Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Debugging Config

  • I'm still trying to debug the DB class.

    It's not getting the type setting. I've tried defining it in the configs but it's not magically working.

    I looked at the db class and it's calling:
    \Config::load('db', true);

    I looked at Config::load and it's really hard to figure out where it's looking for the data:

            if ( ! $reload and
                 ! is_array($file) and
                 ! is_object($file) and
                array_key_exists($file, static::$loaded_files))
            {
                $group === true and $group = $file;
                if ($group === null or $group === false or ! isset(static::$items[$group]))
                {
                    return false;
                }
                return static::$items[$group];
            }
    etc

    I'm trying to figure out where it's looking and then dump that info just to tell how close
    I am to getting it configured correctly.

    Thanks In Advance


  • I set this in app/config/production/db.php :


    return array(
        'production' => array(
            'type' => 'pdo',
            'connection'  => array(
                'dsn'        => 'pgsql:host=localhost;dbname=mypgname',
                'username'   => 'apache',
                'password'   => '',
                'persistent' => false,
                'compress'   => false,
            ),
            'identifier'     => '"',
            'table_prefix'   => '',
            'charset'        => 'utf8',
            'enable_cache'   => true,
            'profiling'      => false,
            'readonly'       => false, // array(),
        ),
    );



    And in app/config/db.php i set:

    return array(

        'active' => 'production',

    );



    But when my model calls:


            $q = "
    SELECT tip_id, active, base_filename, title, description, animated, ext
     FROM tips
    ";

            return DB::query ( $q, DB::SELECT )->Execute ( );



    I get this:

    Fuel\Core\FuelException [ Error ]:
    Database type not defined in "production" configuration or "production" configuration does not exist


    TIA
  • I just tested a deliberate error in:
    app/config/db.php and it gave a parse error.

    But I put garbage in:
    app/config/production/db.php

    and there was no parse error.

    So app/config/production/db.php is not being included.
    So I need to do something to get production/db.php included or
    put the database setup somewhere else...

    TIA
  • So I searched for "production" and found it in
    app/bootstrap.php

    So I searched for bootstrap.php in documentation
    and found the instruction for setting FUEL_ENV in apache.

    I set the FUEL_ENV and now I get an Unexpected error.

    I looked in the log (which I found this morning) and it said
    Error - could not find driver

    So then I ran as root on fedora:
    dnf install *-Pdo-Pgsql

    I finally got my database parameters correct
    and then the query worked!

    Now I'm trying to pack it into a var that I can access from the view.

    I found a post that said to use ->as_array() on the query data so
    I can use foreach in the view.

    The Models and Views help topics don't have any complete examples of this.

    I'm resisting the urge to go back to youtube and re-watch that tutorial where it
    showed my how to do the foreach thing. I should be able to figure it out from the
    documentation.


    I finally got it. I take the query command and add ->as_array ( );
    then I build it correctly in my return array:

    $data['rows'] = DB::...

    Then I can do the:

    foreach ( $rows as $row )
    {
    echo $row['field name']...
    }


    It might be good to explain that each index in the array returned by the model,
    is available as a variable in the view. That's probably in there somewhere but
    I was looking in the model and view topic and couldn't find it.

    Thanks for your help! I'm now off and running!   :)
  • Since the environment setting has the most effect on the database,
    maybe the Model topic should explain this.

    Also the Model topic has some nice helpful snippets showing how to
    use DB but it could use a complete example as well as some guidance
    about where to configure the database connection.

    I'm just trying to help...
  • If you haven't set anything, by default a Fuel application runs in the "development" environment. You should use this, or any other non-production environment, while developing the app, as production mode doesn't display any error messages. This makes debugging difficult.

    If you want to run your app in a different environment, you need to configure that.

    This shows you how: http://docs.fuelphp.com/general/environments.html#/setting_env
  • OK, thanks for the tip, I'll set it back to development.

Howdy, Stranger!

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

In this Discussion