I typically give my fetchAll() method a single, optional parameter called
$constraint. My constraints implement this interface:
interface Galahad_Model_DataMapper_ConstraintInterface
{
public function where($cond, $value = null, $type = null);
public function orWhere($cond, $value = null, $type = null);
public function order($spec);
public function limit($count = null, $offset = null);
public function limitPage($page, $rowCount);
}
Which you can see mirrors a portion of Zend_Db_Select. That way I can use
subclassed Zend_Db_Select objects with my Data Mappers, but if I ever move
away from Zend_Db, I just have to implement the same interface and I won't
have to change any consuming code.
Here's my constraint class:
class Galahad_Model_DataMapper_DbTable_Constraint
extends Zend_Db_Table_Select
implements Galahad_Model_DataMapper_ConstraintInterface
{
}
And here's my fetchAll code in a Zend_Db-based Data Mapper:
if (null !== $constraint && !$constraint instanceof
Galahad_Model_DataMapper_DbTable_Constraint)
{
throw new InvalidArgumentException(__CLASS__ . '::' . __METHOD__ . "
expects its constraint to be of type
'Galahad_Model_DataMapper_DbTable_Constraint'");
}
$result = $this->getDbTable()->fetchAll($constraint);
return $result->toArray();
You can see a working implementation of my modeling system at
http://github.com/inxilpro/Galahad-FE
Cheers,
<http://cmorrell.com/> *Chris Morrell* Web: http://cmorrell.com Twitter:
@inxilpro <http://twitter.com/inxilpro>
On Thu, Jul 15, 2010 at 1:47 PM, Sergio Rinaudo <[email protected]>wrote:
> I am still stuck with these issues,
> hoping to receive some advices :)
>
> -----------
>
>
> Hello,
> I need some explanation of this documentation page:
>
> http://framework.zend.com/manual/en/learning.quickstart.create-model.html
>
> I've created some models following this documentation page,
> I need to get some content with fetchAll using some filter ( where this =
> 'that' ecc ) but the fetchAll
> method doesn't accept any arguments: it is because it is just an example (
> and I have to edit fetchAll by myself providing arguments ) or
> is there any reason?
>
> And also, find method requires second parameter do be a Model instance,
> why?
> Cannot it be instanciated within the method ( like it happens in fetchAll
> )?
>
> Maybe they are just dumb questions, sorry about that!
>
> Any help is very appreciated!
>
> Thanks
>
> Sergio
> ------------------------------
> Non sei a casa? Accedi a Messenger dal
> Web.<http://www.messenger.it/web/default.aspx>
>