Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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
选择cakephp中的特定记录_Php_Mysql_Cakephp - Fatal编程技术网

选择cakephp中的特定记录

选择cakephp中的特定记录,php,mysql,cakephp,Php,Mysql,Cakephp,我使用的是CakePHP2.3。我的搜索查询有问题: $this->loadModel("names"); $modelMerge = $this->names->bindModel(array ( 'belongsTo' => array ( 'origins' => array ( 'foreignKey' => false,

我使用的是CakePHP2.3。我的搜索查询有问题:

$this->loadModel("names");
    $modelMerge = $this->names->bindModel(array
    (
        'belongsTo' => array
        (
            'origins' => array
            (
                'foreignKey' => false,
                'joins' => 'INNER',
                'conditions' => array
                (                                                                'names.Name LIKE' => '%'. $search . '%',
                )
            )

        )

    ));
    $this->set("names", $this->names->findAllByName('$search'));

结果为空-find('all')工作正常,但此代码存在问题。

请先阅读cake文档

模型不能是复数。您必须设置模型名称的名称,而不是名称

$this->loadModel("Name");
$names = $this->Name->find('all', array( // 'all' or 'first'
          'conditions' => array(
                 'Name.name LIKE' => '%'. $search .'%'
          )
));

$this->set(compact("names"));

对于特定记录,您需要通过主键查找它。所以如果pk是“id”

重复的为什么在这里滥发-和多个帐户?开始阅读文档,这样会更有效。
$names = $this->Name->find('all', array(
      'conditions' => array(
             'table.id' => '".$id."'
      ),
      'limit' => 1
));