smsware smsware - 2 months ago 24
PHP Question

CakePHP: missing argument error, passing arguments via URL

This is my controller (unfinished obviously but to "do some magic" I first need to make it run):

public function add($customer_id, $question_set_id, $order_value) {

$customer_id = $this->params['url']['customer_id'];
$question_set_id = $this->params['url']['question_set_id'];
$order_value = $this->params['url']['order_value'];

$possible_answer_model = ClassRegistry::init('PossibleAnswer');
$question_model = ClassRegistry::init('Question');
$order_model = ClassRegistry::init('Order');

$order = $order_model -> find('first', array(
'Order.question_set_id' => $question_set_id,
'Order.value' => $order_value));

$question = $question_model -> find('first', array(
'Question.id' => $order['Order']['question_id']));

$this -> set('question', $question);

if ($question['Question']['kind'] != "o") {
$this -> set('possible_answers', $possible_answer_model -> find('all', array(
'PossibleAnswer.question_id' => $question['Question']['id'])));
}
.
.
.


What I get is:


Warning (2): Missing argument 1 for AnswersController::add() [APP\Controller\AnswersController.php, line 10]

Warning (2): Missing argument 2 for AnswersController::add() [APP\Controller\AnswersController.php, line 10]

Warning (2): Missing argument 3 for AnswersController::add() [APP\Controller\AnswersController.php, line 10]


My link is:


/answers/add/?customer_id=1&question_set_id=1&order_value=1

Answer

The link needs to be

/answers/add/1/1/1

in order to map to

AnswersController::add($customer_id, $question_set_id, $order_value)

Regular query parameters have to be accessed through $this->params inside the controller, they are not passed as arguments to the action.

Comments