Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8213071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:59:18+00:00 2026-06-07T10:59:18+00:00

I have this problem with my view-controller relation. This is the controller: <?php class

  • 0

I have this problem with my view-controller relation. This is the controller:

<?php
class AnswersController extends AppController {
    public $helpers = array('Html', 'Form', 'Session');
    public $components = array('Session');

    public function add() {

        $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'])));
        }

        $this->Session->setFlash($question['Question']['content']);
    }
}

It is getting the proper question and possible_answers (I can see the query output) but the view is always showing the same question (no matter what question_set_id and order_value I will pass to the action) and all the possible_answers (not only these that are actually related with the question, even this question that always shows itself). As the query output is correct, it needs to be some problem with passing data to the view, I guess. Anyway, the view looks like this:

<!-- File: /app/View/Answers/add.ctp -->

<?php
if ($question['Question']['kind'] == 'o') {
    echo $this->Form->create('PossibleAnswer');
    echo $this->Form->input('content', array(
    'rows' => '3', 'label' => 'Miejsce na twoją odpowiedź:'));
    echo $this->Form->input('PossibleAnswer', array(
    'question_id' => $question['Question']['id']));
    echo $this->Form->end('Dalej');
}
else {
    echo $this->Form->create('Answer');
    foreach ($possible_answers as $possible_answer) {
        echo '<input name="'
        .'possible_answers'
        .'" id="'
        .$possible_answer['PossibleAnswer']['id']
        .'" value="'
        .$possible_answer['PossibleAnswer']['id']
        .'" type="radio">';
        echo '<label for="'
        .$possible_answer['PossibleAnswer']['id']
        .'">'
        .$possible_answer['PossibleAnswer']['content']
        .'</label><br />';
    }
    echo $this->Form->end('Dalej');
}
?>

and the query output is like this:

1 SELECT Order.id, Order.question_id, Order.question_set_id, Order.value, Question.id, Question.content, Question.company_id, Question.kind, QuestionSet.id, QuestionSet.name, QuestionSet.company_id FROM mentor11.orders AS Order LEFT JOIN mentor11.questions AS Question ON (Order.question_id = Question.id) LEFT JOIN mentor11.question_sets AS QuestionSet ON (Order.question_set_id = QuestionSet.id) WHERE 1 = 1 LIMIT 1

(affected 1, num. rows 1, took 25)

2 SELECT Question.id, Question.content, Question.company_id, Question.kind, Company.id, Company.trader_id, Company.name FROM mentor11.questions AS Question LEFT JOIN mentor11.companies AS Company ON (Question.company_id = Company.id) WHERE 1 = 1 LIMIT 1

(affected 1, num. rows 1, took 49)

3 SELECT Order.id, Order.question_id, Order.question_set_id, Order.value FROM mentor11.orders AS Order WHERE Order.question_id = (1)

(affected 1, num. rows 1, took 28)

4 SELECT PossibleAnswer.id, PossibleAnswer.content, PossibleAnswer.question_id FROM mentor11.possible_answers AS PossibleAnswer WHERE PossibleAnswer.question_id = (1)

(affected 2, num. rows 2, took 35)

5 SELECT PossibleAnswer.id, PossibleAnswer.content, PossibleAnswer.question_id FROM mentor11.possible_answers AS PossibleAnswer WHERE 1 = 1

(affected 5, num. rows 5, took 23)

As you can see, the 4th query returns two possible answers but the view is containing five of them (for now it’s all of them):
view

At first I suspected that the 5th query (returning all the possible_answers) is somehow “deleting” the 4th query; I still don’t know how this 5th query was called (I don’t need it and I can see no piece of code that would call for such a query) but I changed “my” $possible_answers to $possible_answerz just to make it different – it didn’t work but even if it did: it wouldn’t explain why the $question is always the same…

Any tips?

Edit: when I flash the values – they are correct…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:59:20+00:00Added an answer on June 7, 2026 at 10:59 am

    try this:

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

    and then add ‘conditions’ key to other arrays

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem when i try to synchronize a observable list with listbox/view
Im create this code to store page view in database, but i have problem
I have this managedContextObject I want to pass from a view controller to another.
I have run into this problem in my Codeigniter app: A PHP Error was
Good day, I have this problem with Html.DropDownListFor which I can't seem to work
I have this problem in my view area wherein I have this <g:select> tag
I have this problem: I want to generate a new source code file from
I have this problem: $id is id for each user $img = 'http://www.somesite.com/pictures/'; $no_img
I have this problem since I'm beginning in OOP programming I want to close
I have this problem when I run SAS 9.2 on the command line on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.