简体   繁体   中英

Can not retrieve multiple records from the database in CakePHP

I am working with 2.6.1 version of CakePHP. I have created one controller named as AndroidController.php and that looks like

<?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

Error:Create AndroidController::admin_survey_question() in file: app/Controller/AndroidController.php.

Note :My website url is 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:

<?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 :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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