如何更正查找(“id=$view”);用cakephp?
我从cake的旧版本中学习cakephp,因此一些代码需要更新我有一个控制器,它将数据传递到视图或布局这里是控制器: BlogController.php如何更正查找(“id=$view”);用cakephp?,cakephp,find,Cakephp,Find,我从cake的旧版本中学习cakephp,因此一些代码需要更新我有一个控制器,它将数据传递到视图或布局这里是控制器: BlogController.php <?php class BlogController extends AppController { var $name = 'Blog'; var $uses = array('Blog'); // Used when indexing the page (http://yourdomain.com/blog/) fun
<?php
class BlogController extends AppController {
var $name = 'Blog';
var $uses = array('Blog');
// Used when indexing the page (http://yourdomain.com/blog/)
function index($view = null) {
// What to do if a view is set
if (isset($view))
{
//problem is here
$this->set('article', $this->Blog->find("id = $view"));
$this->render('article');
}
else
{
$this->set('articles', $this->Blog->find('all'));
}
}
}
?>
以下是我单击其中一个项目将得到的错误:
Notice (8): Undefined index: id = 2 [CORE\Cake\Model\Model.php, line 2666]
你可能想要这个:
$this->set('article', $this->Blog->find('first', array('conditions' => array('Blog.id' => $view))));
见:
$this->set('article', $this->Blog->find('first', array('conditions' => array('Blog.id' => $view))));