1

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

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Oh, I've found "my way" somewhere in the cookbook so I probably messed sth up - the link is now working but I'm getting "Undefined index" error at $customer_id = $this->params['url']['customer_id'] and the two other $this->params...
It's either or. If you don't pass them as ?customer_id=1 in the URL, they're not available in $this->params.
dont forget to make them = null by default to avoid warnings thrown!
@mark I don't want the page to run without these values so warnings are okay - I even have no index action, it's just one action, managed by my software
thing is, they url could be triggered without arguments from just about anybody - you should catch this in your controller instead. but the warnings thrown are unnecessary either way, and therefore my hint!
|
0
 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.

1 Comment

sorry, now I've edited my question, I showed the link by witch I'm trying to pass these arguments (which are necessary).
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.