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:

    $word=" ";
    $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.
  • You may want to look at a model's options_list method which creates a key value array:
  • 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.
  • 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.
  • I'm not quite clear on what you are trying to do.
  • 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.
  • Are you using your block field type in a page layout form or in a simple module's form?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!