Welcome Guest, Not a member yet? Register   Sign In
What is the best approach to create this drop down?
#1

[eluser]behnampmdg3[/eluser]
I am trying hard to keep my views php free.

I have a few solutions in mind that all work fine. But I want to see some others opinion. How do you deal with this code? Do u leave it as it is? Move it to controller? How do you deal with selected option?
Code:
<?php
$name = 'shirts';
$options = array('small'=> 'Small Shirt', 'large'=> 'Large');
$selected = array('small');
echo form_dropdown($name, $options, $selected);
?>
Thanks
#2

[eluser]Otemu[/eluser]
Hi,

You could put it in the controller, this will also handle the selected option, something like this:

//controller
Code:
public function index()
{
$dropMenu= $this->_getDropDown();
$this->load->view('dropdowntest.php', $dropMenu);
}

function _getDropDown(){  
$options = array('small'=> 'Small Shirt', 'large'=> 'Large');
$selected = array('small');
$myDropDown= form_dropdown($name, $options, $selected);
return $myDropDown;
}

//view
Code:
echo $createNavTree;




Theme © iAndrew 2016 - Forum software by © MyBB