How To Create CodeIgniter form_dropdown - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: How To Create CodeIgniter form_dropdown (/showthread.php?tid=35235) Pages:
1
2
|
How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]Ahmed Iqbal[/eluser] Hello Friends, I'm using Dropdown old code for categorie's list. Look like Code: <select name="category" id="category"> But i want to be use codeigniter 'form_dropdown function'. By the way, I've already selected form helper in me config/autoload.php. But i need dropdown code structure for codeingiter...! Thanks How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]pickupman[/eluser] Try Code: echo form_dropdown('category', $categories, FALSE, 'id="category"); Note: The label attribute is only supported by IE 7+. How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]Ahmed Iqbal[/eluser] Thanks, but how i can get foreach '$cat' result in this 'form_dropdown' function? How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]pickupman[/eluser] If you would like to use the form dropdown helper, you need to pass a associative array rather than object. You something in your controller like: Code: $data['cat'] = array(); How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]Ahmed Iqbal[/eluser] if i dot this Code: <?php foreach ($categories as $cat): ?> it's generate <select> multi time with <option>. so how i fix I'm confused with this. How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]pickupman[/eluser] Thats not the code I posted. Double check my syntax on the foreach loop. How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]Ahmed Iqbal[/eluser] Controller Code: Quote:$data['cat'] = $this->database->get_cat(); // Try To Catch Categories Result From Model View Code: Quote:<?=form_dropdown('category', $cat, set_value('category'), 'id="category"'); ?> Error in Result: Code: A PHP Error was encountered How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]pickupman[/eluser] You need to return the result object back to $categories from your model. How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]Ahmed Iqbal[/eluser] ohh, sorry...! I've understand your solution. your code work for me. thanks man. Fried, please let me know right solution to access custom build function in controller. we need to 'require_once' custom functions file in controller? or maybe we access my custom function through model? like '$this->load->model('database');' and '$this->database->custom_function(argument) ??? this is right solution??? How To Create CodeIgniter form_dropdown - El Forum - 10-23-2010 [eluser]pickupman[/eluser] Yes that will be fine. Remember codeigniter is still php so you can still do the same stuff. If are going to include a custom class check out the user guide for custom libraries. That you can use CI syntax. If it is a set of function you can put into your own helper. Whatever you feel comfortable with is fine. That's one of the things people like about CI is that it doesn't force you into anything. |