Note that there are some explanatory texts on larger screens.

plurals
  1. PODo I use a helper, library or place my datepicker code in a model in codeigniter?
    primarykey
    data
    text
    <p>Heres my code:</p> <pre><code>//Setup days $data['days']['FALSE'] = 'Day'; //Setup months $data['months'] = array('FALSE' =&gt; 'Month', '1' =&gt; 'Jan', '2' =&gt; 'Feb', '3' =&gt; 'Mar', '4' =&gt; 'Apr', '5' =&gt; 'May', '6' =&gt; 'Jun', '7' =&gt; 'Jul', '8' =&gt; 'Aug', '9' =&gt; 'Sep', '10' =&gt; 'Oct', '11' =&gt; 'Nov', '12' =&gt; 'Dec' ); for($i=1;$i&lt;=31;$i++){ $data['days'][$i] = $i; } //Setup years $start_year = date("Y",mktime(0,0,0,date("m"),date("d"),date("Y")-100)); //Adjust 100 to however many year back you want $data['years']['FALSE'] = 'Year'; for ($i=$start_year;$i&lt;=date("Y");++$i) { $data['years'][$i] = $i; } </code></pre> <p>and here's my if statement:</p> <pre><code>if($this-&gt;form_validation-&gt;run()){ $month = $this-&gt;input-&gt;post('months'); $day = $this-&gt;input-&gt;post('days'); $year = $this-&gt;input-&gt;post('years'); $birthday = date("m-d-Y H:i:s",mktime(0,0,0,$month,$day,$year)); } </code></pre> <p>here's my corresponding code in my form in the view:</p> <pre><code> &lt;p&gt; &lt;label for="birthday"&gt;Birthday: &lt;/label&gt; &lt;?php echo form_dropdown('days',$days). " " . form_dropdown('months',$months). " " . form_dropdown('years',$years); ?&gt; &lt;/p&gt; </code></pre> <p>When I put the datepicker code directly in my controller the drop down on my form shows correctly. I wanted to be neat with my coding so decided to create a model and attempted to make calls from my controller but I get the undefined variable error a few times when my view tries to display the form.</p> <p>I've done some research and wondering whether it's better to make my datepicker a helper "datepicker_helper.php" put the code in there and load it in my controller.</p> <p>Is this the best way to do this?</p> <p>If so can somebody give me a example of how I can do this? If there is another way can somebody show me please?</p> <p>Thanks in advance.. I'm here to learn..</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.
 

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