Hello,
I’m trying to create a plugin called ‘Partners’ the idea is I have several type of Partners and depending on the type of Partner they are I wish to display certain information based on Partner Type on the following url: sitename/partners/view/partner-name (Guest View)
following url: sitename/partners/dashboard/partner-name (Partner Logged in)
I’ve manage to create the following structure using cake bake
- plugins>Partners
- plugins>Partners>src>Model
- plugins>Partners>src>View
- plugins>Partners>src>Controller
- plugins>Partners>src>View>Cell
- plugins>Partners>src>View>Cell>GuestViewCell.php
- plugins>Partners>src>View>Cell>DashboardCell.php
- plugins>Partners>templates>cell>GuestView
- plugins>Partners>templates>cell>GuestView>
PHP files for each cell on the view page for sitename/partners/view/partner-name - plugins>Partners>templates>cell>Dashboard
- plugins>Partners>templates>cell>Dashboard>
PHP files for all the dashboard cells on the dashboard/index
I currently have all the data displaying as it should on templates>Partners>view.php
all the code is on this page and what to split it out to the cells so easier to mange I can load the plugin cell using the following code
<?= $cell = $this->cell('Partners.Guestview::header'); ?>
but can only seem to load static text
header loaded
I have tried moving the following code from templates>Partners>view.php to templates>cell>GuestView>header.php
<div class="container-fluid partnerView" style="background: url('/img/<?= h($partner->background) ?>') no-repeat;
background-size: 100%;">
<div class="row" >
<div class="col-lg-1 justify-text-center"></div>
<div class="col-lg-3 justify-text-center parterHead"><h1><?= h($partner->partner_name) ?></h1>
<?= $this->Html->image(h($partner->logo), array('class' => 'img-fluid rounded', 'alt' => h($partner->partner_name) ));?>
</div>
<div class="col-lg-8"></div>
</div>
<div class="row" >
<div class="col-lg-4"></div>
<div class="col-lg-8"><i class="fas fa-map-marker-alt"></i> <?= h($partner->address) ?> <?= h($partner->street) ?> <?= h($partner->city) ?> <?= h($partner->region) ?> <?= h($partner->country) ?> <?= h($partner->postcode) ?> <i class="fas fa-phone"></i> <?= h($partner->contact_number) ?></div>
</div>
</div>
Then go to the browser it isn’t displaying the the cell but is showing the the following type of error’s in the source code where the cell should appear:
[ Notice (8)](javascript:void(0);): Undefined variable: partner [ ROOT\plugins\Partners\templates\cell\GuestView\header.php , line 6 ]
I have tried adding the code from public function view() in scr>Controller>PartnersController.php
to public function header() in scr>View>GuestViewCell.php
with the following code:
public function header($slug = null)
{
$this->loadModel('Partners');
$partner = $this->Partners->findBySlug($slug)
->where(['Partners.status' => '1'])
->firstOrFail();
$this->set('partners', $partners);
}
but then get the follow error:
Warning (512): Could not render cell - Expression is missing operator (IS, IS NOT) withnull
value. [C:\apps\vanilla\vendor\cakephp\cakephp\src\Database\Expression\QueryExpression.php, line 782] [CORE\src\View\Cell.php, line 271]Code Context$e->getLine()
), E_USER_WARNING);
$e = object(InvalidArgumentException) {
[protected] message => ‘Expression is missing operator (IS, IS NOT) withnull
value.’
[protected] code => (int) 0
[protected] file => ‘C:\apps\vanilla\vendor\cakephp\cakephp\src\Database\Expression\QueryExpression.php’
[protected] line => (int) 782
}Cake\View\Cell::__toString() - CORE\src\View\Cell.php, line 271
include - ROOT\plugins\Partners\templates\Partners\view.php, line 7
Cake\View\View::_evaluate() - CORE\src\View\View.php, line 1164
Cake\View\View::_render() - CORE\src\View\View.php, line 1125
Cake\View\View::render() - CORE\src\View\View.php, line 751
Cake\Controller\Controller::render() - CORE\src\Controller\Controller.php, line 691
Cake\Controller\Controller::invokeAction() - CORE\src\Controller\Controller.php, line 533
Cake\Controller\ControllerFactory::invoke() - CORE\src\Controller\ControllerFactory.php, line 79
Cake\Http\BaseApplication::handle() - CORE\src\Http\BaseApplication.php, line 229
Cake\Http\Runner::handle() - CORE\src\Http\Runner.php, line 77
Authentication\Middleware\AuthenticationMiddleware::process() - ROOT\vendor\cakephp\authentication\src\Middleware\AuthenticationMiddleware.php, line 122
Cake\Http\Runner::handle() - CORE\src\Http\Runner.php, line 73
Cake\Routing\Middleware\RoutingMiddleware::process() - CORE\src\Routing\Middleware\RoutingMiddleware.php, line 156
Cake\Http\Runner::handle() - CORE\src\Http\Runner.php, line 73
Cake\Routing\Middleware\AssetMiddleware::process() - CORE\src\Routing\Middleware\AssetMiddleware.php, line 68
What is the correct way to get the cell to display correctly without erroring so I can then do the same for around 20 functions
Thanks in advance
Mal