[nycphp-talk] Zend Framework confusion
willie klein
willie at pdfsystems.com
Fri Dec 14 10:21:18 EST 2007
Hi All;
I've just started using Zend Framework and having a hard time getting
used to this new way of doing things.
I'm a bit confused about how to register databases with the registry and
putting things all together.
I can query tables fine and put the results into my view if I use the
table model, that is make the table a class and refer to it as a object
through Zend_Table_class. This is fine for querys with one table but I
think for joins its better to use their SQL builder interface. So if I
put in my bootstrap file:
// load configuration
$config = new Zend_Config_Ini('./application/config.ini', 'general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);
// setup database
$db = Zend_Db::factory($config->db->adapter,
$config->db->config->toArray());
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('db', $db);
/////
Can I just use in my controller :
$db = Zend_Registry::get('db');
$select = $db->select();
$select->distinct()
->from( 'course')
->join(array( 'user'), 'course.teacherID =
user.id') ;
$data = $db->fetchAll($select);
$this->view->data = $data;//
This doesn't work and I'm not sure why.
This works with the model:
$dbuser = new User();
$this->view->dbuser = $dbuser->fetchAll();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20071214/a22a97f0/attachment.html>
More information about the talk
mailing list