On Wed, Mar 11, 2009 at 10:59 PM, Dave Maharaj :: WidePixels.com
<[email protected]> wrote:
> I been at this for hours and still no luck. What I am trying to do is run a
> simple query to find a user_id based on the Auth->id and pass the result to
> the view.
>
> This is being run in the students_controller which is checking the TEACHERS
> table. In the view where I have wantsAccess all that gets displayed is
> "Array".
>
> view: <?php echo $wantsAccess; ?>
<?php debug($wantsAccess); ?>
>
> $this->set('wantsAccess', $this->Teacher->find('all', array( 'conditions' =>
> array('Teacher.user_id' => $this->Auth->user('id')),'fields' =>
> array('Teacher.id')
> )
> ));
If you want just a single row, use find('first', ...). If you really
want just the ID, use the field() method:
$this->set(
'wantsAccess',
$this->Teacher->field(
'id',
array(
'Teacher.user_id' => $this->Auth->user('id')
)
)
);
This will return just the ID (no array). Note that you don't put the
'conditions' key because that 2nd param is *only* for conditions.
Another bit of advice: I've gotten in the habit of naming my vars much
more specifically (ie. $user_id rather than $wantsAccess) in order to
keep things clearer months down the road when I need to make changes
(and curse my lack of comments ;-)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---