Hi!
-- Why are you abusing the pages controller for that?
It doesn't support actions out of the box.
Am Donnerstag, 2. April 2015 16:40:17 UTC+2 schrieb Amit G:
It doesn't support actions out of the box.
Make yourself a new FooController and then you can have actions for your views.
But the PagesController itself only supports view files only (no action for it)
The error you get shows this pretty clearly
Mark
Am Donnerstag, 2. April 2015 16:40:17 UTC+2 schrieb Amit G:
Hi,
I am using CakePHP3.0 gettingNotice (8): Undefined variable: color [APP/Template\Pages\myshow.ctp, line 2]
how can fix this error?
Here is my full code:
<?php
namespace App\Controller;
use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;
class PagesController extends AppController
{
/**
* Displays a view
*
* @return void|\Cake\Network\Response
* @throws \Cake\Network\Exception\NotFoundException When the view file could not
* be found or \Cake\View\Exception\MissingTemplateException in debug mode.
*/
public function display()
{
$path = func_get_args();
$count = count($path);
if (!$count) {
return $this->redirect('/');
}
$page = $subpage = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
$this->set(compact('page', 'subpage'));
try {
$this->render(implode('/', $path));
} catch (MissingTemplateException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new NotFoundException();
}
}
public function myshow() {
$this->set('color', 'pink');
$this->render();
}
}
src\Template\Pages\myshow.ctp
<?php
echo $color;
?>
test
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment