I suggest that you look into the Containable behavior, at:
http://book.cakephp.org/view/474/Containable
This will save you a lot of time in the future.
Until you choose to use Containable, your code should be changed to:
[code]
$conditions = array("month(Duty.duty_date)" => $monthNo);
$this->set('duties', $this->Duty->findByuser_id($user), array
('conditions' => $conditions, 'recursive' => 2));
[/code]
Observe that I added the array element 'recursive' to your
findByUser_id method call!
Enjoy,
John
On Dec 14, 1:47 pm, Bailey <[email protected]> wrote:
> Hi all,
>
> I am new to cake within the last couple of months but I am a
> experienced PHP programmer. I've made a few basic applications in
> practice to building my own time and event management system.
>
> I have a question regarding how to pull data from multiple tables...
>
> I have a user profile table and a 'duties' table, a user can have many
> duties and each record in duties counts as one duty.
>
> In the duties_controller i create a function that requires input from
> the user: (first name, last name, month and year). I take the first
> name and last name and pass it to the user_profile model to find a
> valid user id.
>
> I then use this user id to display all duties for that user within the
> last month, but the duties tables relys on relations as well as
> specific values.
>
> In my displayDuty() in the duties_controller i set a variable which is
> then used in the display_duty.ctp view to loop over all the user
> duties and echo them to a table.
>
> duties_controller display method:
>
> $conditions = array("month(Duty.duty_date)" => $monthNo);
> $this->set('duties', $this->Duty->findByuser_id($user), array
> ('conditions' => $conditions));
>
> My question... (and sorry for the long build up :p):
>
> Is there an easy way to pull out data from relationship tables from
> duties using the value given in the view, so I do a foreach loop in
> the view and could do:
>
> $duty['Duty']['station_id'];
>
> But what i really want is the station name from the Station table,
> similary how would I pull out data not in the duty table but related
> to the user id, such as user_role from Usr_roles table..
>
> I might be making this too complicated but would appreciate any
> advice :-) could i just do a simple sql lookup? i wasnt sure if its
> right to do this within a view and not the controller.
>
> Many thanks for any info,
> Bailey
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en