Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is a little bit of logic that can be moved to the controller or even model layer:</p> <pre><code>$options = array(); $options[''] = 'Country'; foreach($country_options AS $cnt) { $options[$cnt-&gt;id] = $cnt-&gt;country; } echo form_dropdown('country',$options,'',$country); </code></pre> <p>Could probably look like:</p> <pre><code>echo form_dropdown('country', $countries, '', $country); </code></pre> <p>...if you move the options to the controller or view.</p> <p>This is a problem I run into all the time trying to keep things <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow">DRY</a> as possible, where to define the form data? I think sometimes we forget the power of the "V" in "MVC". You <em>could</em> define all the view logic in the view instead.</p> <p>Things like <code>id</code>, <code>tabindex</code> and <code>placeholder</code> are only necessary and useful in the view. Things like form validation rules and data checking/prepping belong in the Controller/Model layer.</p> <p>The form helper functions are useful, but sometimes raw HTML is better. For example:</p> <pre><code>// Controller $this-&gt;data['address1'] = array( 'name' =&gt; 'address1', 'id' =&gt; 'address1', 'type' =&gt; 'text', 'class' =&gt; 'field text addr', 'tabindex' =&gt; '10', 'value' =&gt; $this-&gt;form_validation-&gt;set_value('address1'), 'placeholder' =&gt; 'Street Address' ); // View echo form_input($address1); </code></pre> <p>Or simply:</p> <pre><code>&lt;input name="address1" id="address1" tabindex="10" type="text" placeholder="Street Address" value="&lt;?php echo set_value('address1'); ?&gt;" class="field text addr"&gt; </code></pre> <p>I wrote a bunch of applications last year where I defined all this stuff in the Model, and now I'm regretting it as I've been going back to do maintenance on them and all the view logic is obscured away in the Model or Controller. Editing a Controller or Model to change a <code>class</code> attribute is just silly.</p>
 

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