webPragmatist wrote:
>
> I can extend Zend_Db_Table but that seems to leave me with only insert,
> update, delete because the select statements are moved to
> Zend_Db_Table_Select (according to the guide).
>
> So, what if I want to be able to load one model and perform both of these
> functions? Am I missing the idea?
>
I currently extend the Zend_Db_Table as you have mentioned and create public
methods for anything that is outside the standard functionality offered by
the parent class.
I'm comfortable with SQL - so for quick apps and without having the time to
learn select object usage (already have my hands full with zend_form), I
code the SQL in a string and return fetchall($SQL) - you can set the return
type also if required.
Something along the lines of:
<?php
/**
* Users TDG
* @author rvdavid
*/
require_once 'Zend/Db/Table/Abstract.php';
class Users extends Zend_Db_Table_Abstract
{
/**
* dbname
*/
protected $_name = 'users';
public function getList()
{
$SQL = "SELECT `a`.`id`, `a`.`company`, `b`.`name` as `user_type`,
CONCAT_WS(' ',`first_name`,`middle_name`,`last_name`) as
`contact`
FROM {$this->_name} `a`
LEFT JOIN `user_types` `b` ON `a`.`user_type_id` =
`b`.`id`";
$this->_db->setFetchMode(Zend_Db::FETCH_OBJ); // FETCH_ASSOC for
associated (I think this is the default anyway).
return $this->_db->fetchAll($SQL);
}
// ... other methods
}
That enough gets me out of trouble.
Reading some documentation on the select object, I suppose you could further
extend it through the use a single api and feed it parameters to construct
where clauses etc which saves you from the "$SQL .= X or $SQL[] = X; $query
= implode(' AND ', $SQL); " way of coding. Well, there's also the data
abstraction point, but I'm of the opinion that that is a moot point.
HTH anyway.
regards,
-----
R. Villar David
Lead Developer, DevProducts Pty Ltd
p: +61 2 9648 3777 f: +61 2 9648 6988
w: http://www.devproducts.com
--
View this message in context: http://www.nabble.com/Another-Model-Design-Thread-tp20909700p20909923.html
Sent from the Zend MVC mailing list archive at Nabble.com.
没有评论:
发表评论