Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP: Action runs twice, for no good reason
    primarykey
    data
    text
    <p>I have a strange problem with my cake (cake_1.2.0.7296-rc2). My start()-action runs twice, under certain circumstances, even though only one request is made.</p> <p>The triggers seem to be : - loading an object like: <code>$this-&gt;Questionnaire-&gt;read(null, $questionnaire_id);</code> - accessing $this-data </p> <p>If I disable the call to <code>loadAvertisement()</code> from the <code>start()</code>-action, this does not happen. If I disable the two calls inside <code>loadAdvertisement():</code></p> <pre><code>$questionnaire = $this-&gt;Questionnaire-&gt;read(null, $questionnaire_id); $question = $this-&gt;Questionnaire-&gt;Question-&gt;read(null, $question_id); </code></pre> <p>... then it doesn't happen either.</p> <p>Why?</p> <p>See my code below, the Controller is "questionnaires_controller".</p> <pre><code>function checkValidQuestionnaire($id) { $this-&gt;layout = 'questionnaire_frontend_layout'; if (!$id) { $id = $this-&gt;Session-&gt;read('Questionnaire.id'); } if ($id) { $this-&gt;data = $this-&gt;Questionnaire-&gt;read(null, $id); //echo "from ".$questionnaire['Questionnaire']['validFrom']." ".date("y.m.d"); //echo " - to ".$questionnaire['Questionnaire']['validTo']." ".date("y.m.d"); if ($this-&gt;data['Questionnaire']['isPublished'] != 1 //|| $this-&gt;data['Questionnaire']['validTo'] &lt; date("y.m.d") //|| $this-&gt;data['Questionnaire']['validTo'] &lt; date("y.m.d") ) { $id = 0; $this-&gt;flash(__('Ungültiges Quiz. Weiter zum Archiv...', true), array('action'=&gt;'archive')); } } else { $this-&gt;flash(__('Invalid Questionnaire', true), array('action'=&gt;'intro')); } return $id; } function start($id = null) { $this-&gt;log("start"); $id = $this-&gt;checkValidQuestionnaire($id); //$questionnaire = $this-&gt;Questionnaire-&gt;read(null, $id); $this-&gt;set('questionnaire', $this-&gt;data); // reset flow-controlling session vars $this-&gt;Session-&gt;write('Questionnaire',array('id' =&gt; $id)); $this-&gt;Session-&gt;write('Questionnaire'.$id.'currQuestion', null); $this-&gt;Session-&gt;write('Questionnaire'.$id.'lastAnsweredQuestion', null); $this-&gt;Session-&gt;write('Questionnaire'.$id.'correctAnswersNum', null); $this-&gt;loadAdvertisement($id, 0); $this-&gt;Session-&gt;write('Questionnaire'.$id.'previewMode', $this-&gt;params['named']['preview_mode']); if (!$this-&gt;Session-&gt;read('Questionnaire'.$id.'previewMode')) { $questionnaire['Questionnaire']['participiantStartCount']++; $this-&gt;Questionnaire-&gt;save($questionnaire); } } function loadAdvertisement($questionnaire_id, $question_id) { //$questionnaire = array(); $questionnaire = $this-&gt;Questionnaire-&gt;read(null, $questionnaire_id); //$question = array(); $question = $this-&gt;Questionnaire-&gt;Question-&gt;read(null, $question_id); if (isset($question['Question']['advertisement_id']) &amp;&amp; $question['Question']['advertisement_id'] &gt; 0) { $this-&gt;set('advertisement', $this-&gt;Questionnaire-&gt;Question-&gt;Advertisement-&gt;read(null, $question['Question']['advertisement_id'])); } else if (isset($questionnaire['Questionnaire']['advertisement_id']) &amp;&amp; $questionnaire['Questionnaire']['advertisement_id'] &gt; 0) { $this-&gt;set('advertisement', $this-&gt;Questionnaire-&gt;Question-&gt;Advertisement-&gt;read(null, $questionnaire['Questionnaire']['advertisement_id'])); } } </code></pre> <p>I really don't understand this... it don't think it's meant to be this way. Any help would be greatly appreciated! :)</p> <p>Regards, Stu</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload