Nisarg Nisarg - 5 months ago 8
PHP Question

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?

Answer

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