how to fetch data from the database in kohana 3.3 framework. I have created dropdown list in the view but i don't know how to connect it with the controller so that i could fetch data from the database and show it in the drop down list
Asked
Active
Viewed 172 times
1 Answers
0
You need to get the data you want out of the database using ORM or a DB::select query, then formulate it into an array where the key is the value of the option, and the value is the text you wish to be displayed for each option.
For example, you'd need to end up with something like:
$options = array(
1 => 'First Option',
2 => 'Second Option',
3 => 'Third Option'
);
Then pass this array to Kohana's Form helper (Form::select) and it will output the options for you. Reference: http://kohanaframework.org/3.3/guide-api/Form#select
The above example would output something like:
<select name="whatever">
<option value="1">First Option</option>
<option value="2">Second Option</option>
<option value="3">Third Option</option>
</select>
If your question is really how to get the data out of the database, then you need to read all of the examples here: http://kohanaframework.org/3.3/guide/orm
Good luck!

SigmaSteve
- 664
- 6
- 25