« Return to Thread: Dumb Question

RE: Dumb Question

by rcastley :: Rate this Message:

Reply to Author | View in Thread

RE: [fw-general] Dumb Question

 
The way I have done it (rightly or wrongly) and it works is:

Index.php
---------

$db = Zend_Db::factory('PDO_SQLITE', array('dbname' => 'myDb.db3'));
Zend_Db_Table_Abstract::setDefaultAdapter($db);

Then in my models directory I have

Users.php
---------

<?php
/**
 * Manage users table
 *
 */
class Users extends Zend_Db_Table_Abstract
{
    /**
     * Table name
     *
     * @var string
     */
    protected $_name = 'users';

    /**
     * Load current user data
     *
     * @param string $user
     */
    public function getUser($user)
    {
        $where = $this->getAdapter()->quoteInto('username = ?', $user);

        return $this->fetchRow($where);
    }
}

Then in my controller I have

IndexController.php
-------------------

$userTable = new Users();

$getUser = $user->getUser($currentUsername);

$this->view->name = $getUser->name;
$this->view->age = $getUser->age;
Etc......


Hope this helps.

- Robert

-----Original Message-----
From: Joseph Crawford [codebowl@...]
Sent: 15 May 2008 14:17
To: fw-general@...
Subject: [fw-general] Dumb Question

In my index.php bootstrap file I setup the database connection into a variable $db.  Now I need to access this in other controllers.  This seems like a dumb question to me but do I need to global $db; before I can access it in the indexAction method of the controller or is it in the global scope by default?

Thanks,
Joseph Crawford

________________________________________________________________________
This email has been scanned for all known viruses by the MessageLabs Email Security Service and the Macro 4 plc internal virus protection system.

________________________________________________________________________


________________________________________________________________________
This email has been scanned for all known viruses by the MessageLabs Email Security Service and the Macro 4 plc internal virus protection system.
________________________________________________________________________

 « Return to Thread: Dumb Question

LightInTheBox - Buy quality products at wholesale price