Reputation: 479
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
Upvotes: 1
Views: 3283
Reputation: 2300
I'm using custom routes, and this solve for me.
Router::connect('/me/edit/:id', array('controller' => 'users', 'action' => 'edit'),
array('pass' => array('id'), 'id' => '[0-9]+')
);
Thanks for @david-yell in https://stackoverflow.com/a/17989140/1424473.
Upvotes: 0
Reputation: 522597
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.
Upvotes: 3
Reputation: 67968
public function add($customer_id=null, $question_set_id=null, $order_value=null) {
....
}
Probably aren't passing the arguments you need to when it's required, you can just do the above and it won't require it.
Upvotes: 0