Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I find really weird that you have to create a variable in a construct of a model for a dropdown. Specially if you're only going to use it once.</p> <p>But first things first. You're getting that error because you haven't set the variable to the view. In your controller, there needs to be something like this:</p> <pre><code>public function add() { $this-&gt;set('titles', $your_titles_array); if ($this-&gt;request-&gt;is('post')) { //etc </code></pre> <p>Now, please please get the dropdown array away from there. There are two possible nicer places to put that. I'm not going to get picky and say you <em>need</em> to have this values as a table in you database. If you say it's just for one place and you want to have it hardcode, so be it.</p> <p>One option is to put it in one model, like</p> <pre><code>class YourModel extends AppModel { //all your other definitions public function getTitles() { return array( 0 =&gt; __('Mr', true), 1 =&gt; __('Mrs', true), 2 =&gt; __('Miss', true)); } } </code></pre> <p>And in the controller do </p> <pre><code> public function add() { $this-&gt;set('titles', $this-&gt;YourModel-&gt;getTitles()); if ($this-&gt;request-&gt;is('post')) { //etc </code></pre> <p><em>But</em>, I don't think you have an appropriate model to add that function. Where did you plan to add it? User model maybe? It can't be like Post model, for example, that wouldn't make any sense... So, give it a thought, if there's a logical place in a model you can put that function, then go ahead.</p> <p>Otherwise, and if <em>it's just for one form in one place just that one time</em>, why not hardcode it to the view or the controller?</p> <p>For larger lists, my recommendation is to do it in a model like I showed (but I insist, put it in the model where is logical to have it). Well, I rather have a table and reference the values, but it's not mandatory (though give it a thought, is really not that much work, is it? for larger lists, I mean).</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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