简体   繁体   English

无法从CakePHP的数据库中检索多个记录

[英]Can not retrieve multiple records from the database in CakePHP

I am working with 2.6.1 version of CakePHP. 我正在使用2.6.1版本的CakePHP。 I have created one controller named as AndroidController.php and that looks like 我创建了一个名为AndroidController.php的控制器,看起来像

<?php
class AndroidController extends AppController {

public function survey_question()
{
    Configure::write('debug', '2');
    $survey_id = $_REQUEST['survey_id'];
    $this->layout = "";
    //$condition = "Question.survey_id = '".$survey_id."'";
    $info = $this->Question->find('all', array(
        'conditions' => array(
                    "Question.survey_id" => $survey_id  /*dont use array() */
            )
        ));
    echo json_encode($info);
    exit;
}
}
?>

So, it gives an error like 因此,它给出了类似的错误

Error: The action admin_survey_question is not defined in controller AndroidController 错误:未在控制器AndroidController中定义操作admin_survey_question

Error:Create AndroidController::admin_survey_question() in file: app/Controller/AndroidController.php. 错误:在文件app / Controller / AndroidController.php中创建AndroidController :: admin_survey_question()。

Note :My website url is http://navyon.com/dev/mt/admin/android/survey_question?survey_id=2 注意:我的网站网址是http://navyon.com/dev/mt/admin/android/survey_question?survey_id=2

So how can I resolve this? 那么我该如何解决呢?

You have enable admin routing for that action so your action should preceded admin_ Then your action look like below: 您已为该操作启用了admin路由,因此您的操作应在admin_之前,然后您的操作如下所示:

<?php
class AndroidController extends AppController {

public function admin_survey_question() 
{
Configure::write('debug', '2');
$survey_id = $_REQUEST['survey_id'];
$this->layout = "";
//$condition = "Question.survey_id = '".$survey_id."'";
$info = $this->Question->find('all', array(
    'conditions' => array(
                "Question.survey_id" => $survey_id  /*dont use array()      */
        )
    ));
echo json_encode($info);
exit;
 }
}
?>

If you don't want enable admin routing for that action then remove admin from url and access like this : 如果您不想为该操作启用admin路由,则从url删除admin并按以下方式进行访问:

http://navyon.com/dev/mt/android/survey_question?survey_id=2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM