AnalyticsAB

Ads Inside Post

Search in This Blog

Notice (8): Undefined variable in cakephp

Problem:

You can get the error message Notice (8): Undefined variable in CakePHP while passing variable value from Controller to View. How to overcome this error?

Solution:

If you mistakenly create a method in predefined Controller "PagesController.php" which is automatically created by default. So don't touch or use "PagesController.php". you need to create own Controller ans create method and pass variable.
In other clear wording "do not use PagesController.php file, create own controller class"

Example:

See below incorrect code:File: src\Controller\PagesController.php

<?php
namespace App\Controller;
use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;