Data from database in the view

edited February 2018 in Feature Requests
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

  • edited 5:55PM
    You may want to look at a model's options_list method which creates a key value array:
    http://docs.getfuelcms.com/libraries/my_model#func_options_list
  • edited 5:55PM
    Hi admin.

    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.
  • edited 5:55PM
    Admin.

    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.
  • edited 5:55PM
    I'm not quite clear on what you are trying to do.
  • edited 5:55PM
    At the moment that i create the block in MY_fuel_layouts file i want that block contains the information from the database. For that reason i try to use the model but it always return null. Is something like pre charged information in the block.

    I hope make me understand, thanks admin.
  • edited 5:55PM
    Are you using your block field type in a page layout form or in a simple module's form?
Sign In or Register to comment.