Data from database in the view
Hello.
I'm trying to create a select field with data from the database in the MY_fuel_layouts.
I do the connection to the database manually like this:
$host="localhost";
$username="root";
$word=" ";
$db_name="database";
$con=mysqli_connect("$host", "$username", "$word","$db_name")or die("cannot connect");
if($con === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
else {
//my code
}
I want to put that information in an select type array:
$options = array('a' => 'option A', 'b' => 'option B', 'c' => 'option C');
$fields['select_example'] = array('type' => 'select', 'options' => $options, 'model' => 'people', 'first_option' => 'Select one...');
How can i do to obtain this data of the select field in the view's block? I really apreciate help. Thanks.
Comments
http://docs.getfuelcms.com/libraries/my_model#func_options_list
If i understand you, i have to use the model of the table and create the key to obtain the information? And that info will be appear in the user's view? I hope i explain correctly my problem.
When i try to obtain the data by this way in MY_fuel_layouts:
$this->load->module_model(FUEL_FOLDER, 'Eventos_model');
I have this error message
An uncaught Exception was encountered
Type: Error
Message: Call to a member function module_model() on null
Filename: /Applications/MAMP/htdocs/FUEL/fuel/application/config/MY_fuel_layouts.php
I really need the information when i create the layout. This because i want to choose an option of this info.
I hope make me understand, thanks admin.