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

时间:2016-06-29 10:50:31

标签: php cakephp

我正在使用CakePHP的2.6.1版本。我创建了一个名为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;
}
}
?>

因此,它会出现类似

的错误
  

错误:未在控制器中定义操作admin_survey_question   AndroidController

     

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

     

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

那我怎么解决这个问题?

1 个答案:

答案 0 :(得分:2)

您已为该操作启用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; } } ?> 之前 然后您的行动如下所示:

admin

如果您不希望为该操作启用url路由,请从http://navyon.com/dev/mt/android/survey_question?survey_id=2 删除管理员,然后按以下方式访问:

reduce