PagesController.php顯示分類清單在主頁的蛋糕PHP
$this->loadModel('Category');
$categories = $this->Category->find('all',
array(
'limit' => 5,
'order' => 'Category.id ASC',
'fields' => array('Category.id','Category.category'),
'contain' => false,
'conditions' => array('Category.super_id' => 1),
'recursive' => 0
)
);
//pr($categories); Here showing all category listing
$this->set(compact('categories'));
//$this->set('categories',$categories); that code also used
通過PagesController顯示分類清單在主頁的蛋糕PHP
但鑑於文件即時得到以下錯誤(鑑於/頁/ home.ctp)
<?php pr($categories); ?>
Notice (8): Undefined variable: categories [APP/View/Pages/home.ctp, line 142]
pagesController.php
public function display() {
$path = func_get_args();
$count = count($path);
if (!$count) {
return $this->redirect('/');
}
$page = $subpage = $title_for_layout = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$title_for_layout = Inflector::humanize($path[$count - 1]);
}
$this->set(compact('page', 'subpage', 'title_for_layout'));
try {
$this->render(implode('/', $path));
} catch (MissingViewException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new NotFoundException();
}
$this->loadModel('Category');
$categories = $this->Category->find('all',
array(
'order' => 'Category.id ASC',
'fields' => array('Category.id','Category.category'),
'contain' => false,
'conditions' => array('Category.super_id' => 1),
'recursive' => 0
)
);
$this->set('categories',$categories);
//$this->set(compact('categories'));
//pr($categories);
}
routes.php文件
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
@Wooble我沒有得到你的觀點,你能解釋一點點更多 –
@Wooble使用CakePHP 2.3版本 –
其中pagesController的行動是你嗎? – arilia