Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更正查找(“id=$view”);用cakephp?_Cakephp_Find - Fatal编程技术网

如何更正查找(“id=$view”);用cakephp?

如何更正查找(“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

我从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/)
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))));