Prev | Current Page 167 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

14, the Users class follows exactly the same pattern as that Places class and
only defines the table classes that are directly dependant on. This means that we don??™t explicitly state a manyto-
many relationship in the code and we let the Zend_Db_Table work out that there is one. To create a list of
the places that a given user has reviewed, the following code is used:
$users = new Users();
$robAllen = $users->fetchRow('id = 1');
$places = $robAllen->findManyToManyRowset('Places', 'Reviews');
As you can see, the function that does the work for us is called findManyToManyRowset(). The first
parameter is the destination table and the second is the intersection table class containing the rules that will
link the initial table class to the intersection table class. In both cases, the parameters can either be strings or
instances of Zend_Db_Table, so the snippet above could be written as:
$users = new Users();
$places = new Places();
$reviews = new Reviews();
$robAllen = $users->fetchRow('id = 1');
$places = $robAllen->findManyToManyRowset($places, $reviews);
This would produce exactly the same result. Note that if there is more than one rule in the $_referenceMap
of the intersection table that that would link the tables, then you can specify which rule to use as additional
parameters to findManyToManyRowset().


Pages:
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
taxi kino azjatyckie hotele londyn Romet ceny żywca