Re: Trouble fetching database information

2009-02-25 Thread dr. Hannibal Lecter

Obviously, User model is not used in SupplierController, i.e. you're
missing the following

var $uses = array('User');

In your controller. That's why Undefined property error occurs when
you do $this-User.

Hope that helps!

On Feb 25, 3:27 pm, Matt mmanai...@gmail.com wrote:
 Hi all,

 I'm new to CakePHP (but not PHP) and I have followed the 5 part series
 by IBM to get me going on Cake PHP. I'm building a mini CMS for a
 client, and I am stuck... here's how the system should work:

 the client logs in and adds a supplier. The supplier is added to the
 database and has a field user_id which needs to automatically populate
 with the logged in user's id.

 My problem is that when I try to get the userid, I get the following
 error:
 Notice (8): Undefined property: SuppliersController::$User [APP/
 controllers/suppliers_controller.php, line 27]
 Fatal error: Call to a member function findByUsername() on a non-
 object in /var/www/online_contractors/app/controllers/
 suppliers_controller.php on line 27

 In the supplier controller I attempt to fetch the userid as so:

 $results=$this-User-findByUsername($username);
 $this-set('user', $results['User']);

 The username is what gets written to session when logged in.

 Any help would be greatly appreciated!
 Thanks!
 -Mathieu
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Trouble fetching database information

2009-02-25 Thread brian

On Wed, Feb 25, 2009 at 9:27 AM, Matt mmanai...@gmail.com wrote:

 Hi all,

 I'm new to CakePHP (but not PHP) and I have followed the 5 part series
 by IBM to get me going on Cake PHP. I'm building a mini CMS for a
 client, and I am stuck... here's how the system should work:

 the client logs in and adds a supplier. The supplier is added to the
 database and has a field user_id which needs to automatically populate
 with the logged in user's id.

 My problem is that when I try to get the userid, I get the following
 error:
 Notice (8): Undefined property: SuppliersController::$User [APP/
 controllers/suppliers_controller.php, line 27]
 Fatal error: Call to a member function findByUsername() on a non-
 object in /var/www/online_contractors/app/controllers/
 suppliers_controller.php on line 27

 In the supplier controller I attempt to fetch the userid as so:

 $results=$this-User-findByUsername($username);
 $this-set('user', $results['User']);


Are the User and Supplier models associated? If so, the proper way to
call methods of User would be

$this-Supplier-User-findByUserName($username);

 The username is what gets written to session when logged in.

You could also store the ID, name, etc. of the user in the session and
avoid having to look it up later.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Trouble fetching database information

2009-02-25 Thread Matt

Hello and thank you so much for your help!!

Brian,

I took your advice and added the userid to the session, however, I'm
clearly doing something wrong because in the Supplier controller I
call the session with:
$userid = $this-Session-read('userid');

However in the view, I enter echo $userid;

and I receive the following error:
Notice (8): Undefined variable: userid [APP/views/suppliers/add.ctp,
line 6]

I realise this is most definately a newbie error, and I appreciate all
your patience!

Thanks again,
Mathieu



On Feb 25, 11:49 am, brian bally.z...@gmail.com wrote:
 On Wed, Feb 25, 2009 at 9:27 AM, Matt mmanai...@gmail.com wrote:

  Hi all,

  I'm new to CakePHP (but not PHP) and I have followed the 5 part series
  by IBM to get me going on Cake PHP. I'm building a mini CMS for a
  client, and I am stuck... here's how the system should work:

  the client logs in and adds a supplier. The supplier is added to the
  database and has a field user_id which needs to automatically populate
  with the logged in user's id.

  My problem is that when I try to get the userid, I get the following
  error:
  Notice (8): Undefined property: SuppliersController::$User [APP/
  controllers/suppliers_controller.php, line 27]
  Fatal error: Call to a member function findByUsername() on a non-
  object in /var/www/online_contractors/app/controllers/
  suppliers_controller.php on line 27

  In the supplier controller I attempt to fetch the userid as so:

  $results=$this-User-findByUsername($username);
  $this-set('user', $results['User']);

 Are the User and Supplier models associated? If so, the proper way to
 call methods of User would be

 $this-Supplier-User-findByUserName($username);

  The username is what gets written to session when logged in.

 You could also store the ID, name, etc. of the user in the session and
 avoid having to look it up later.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Trouble fetching database information

2009-02-25 Thread Matt

Hello and thank you so much for your help!!

Brian,

I took your advice and added the userid to the session, however, I'm
clearly doing something wrong because in the Supplier controller I
call the session with:
$userid = $this-Session-read('userid');

However in the view, I enter echo $userid;

and I receive the following error:
Notice (8): Undefined variable: userid [APP/views/suppliers/add.ctp,
line 6]

I realise this is most definately a newbie error, and I appreciate all
your patience!

Thanks again,
Mathieu



On Feb 25, 11:49 am, brian bally.z...@gmail.com wrote:
 On Wed, Feb 25, 2009 at 9:27 AM, Matt mmanai...@gmail.com wrote:

  Hi all,

  I'm new to CakePHP (but not PHP) and I have followed the 5 part series
  by IBM to get me going on Cake PHP. I'm building a mini CMS for a
  client, and I am stuck... here's how the system should work:

  the client logs in and adds a supplier. The supplier is added to the
  database and has a field user_id which needs to automatically populate
  with the logged in user's id.

  My problem is that when I try to get the userid, I get the following
  error:
  Notice (8): Undefined property: SuppliersController::$User [APP/
  controllers/suppliers_controller.php, line 27]
  Fatal error: Call to a member function findByUsername() on a non-
  object in /var/www/online_contractors/app/controllers/
  suppliers_controller.php on line 27

  In the supplier controller I attempt to fetch the userid as so:

  $results=$this-User-findByUsername($username);
  $this-set('user', $results['User']);

 Are the User and Supplier models associated? If so, the proper way to
 call methods of User would be

 $this-Supplier-User-findByUserName($username);

  The username is what gets written to session when logged in.

 You could also store the ID, name, etc. of the user in the session and
 avoid having to look it up later.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Trouble fetching database information

2009-02-25 Thread Matt

Hello and thank you so much for your help!!

Brian,

I took your advice and added the userid to the session, however, I'm
clearly doing something wrong because in the Supplier controller I
call the session with:
$userid = $this-Session-read('userid');

However in the view, I enter echo $userid;

and I receive the following error:
Notice (8): Undefined variable: userid [APP/views/suppliers/add.ctp,
line 6]

I realise this is most definately a newbie error, and I appreciate all
your patience!

Thanks again,
Mathieu



On Feb 25, 11:49 am, brian bally.z...@gmail.com wrote:
 On Wed, Feb 25, 2009 at 9:27 AM, Matt mmanai...@gmail.com wrote:

  Hi all,

  I'm new to CakePHP (but not PHP) and I have followed the 5 part series
  by IBM to get me going on Cake PHP. I'm building a mini CMS for a
  client, and I am stuck... here's how the system should work:

  the client logs in and adds a supplier. The supplier is added to the
  database and has a field user_id which needs to automatically populate
  with the logged in user's id.

  My problem is that when I try to get the userid, I get the following
  error:
  Notice (8): Undefined property: SuppliersController::$User [APP/
  controllers/suppliers_controller.php, line 27]
  Fatal error: Call to a member function findByUsername() on a non-
  object in /var/www/online_contractors/app/controllers/
  suppliers_controller.php on line 27

  In the supplier controller I attempt to fetch the userid as so:

  $results=$this-User-findByUsername($username);
  $this-set('user', $results['User']);

 Are the User and Supplier models associated? If so, the proper way to
 call methods of User would be

 $this-Supplier-User-findByUserName($username);

  The username is what gets written to session when logged in.

 You could also store the ID, name, etc. of the user in the session and
 avoid having to look it up later.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Trouble fetching database information

2009-02-25 Thread brian

On Wed, Feb 25, 2009 at 2:54 PM, Matt mmanai...@gmail.com wrote:

 Hello and thank you so much for your help!!

 Brian,

 I took your advice and added the userid to the session, however, I'm
 clearly doing something wrong because in the Supplier controller I
 call the session with:
 $userid = $this-Session-read('userid');

 However in the view, I enter echo $userid;

 and I receive the following error:
 Notice (8): Undefined variable: userid [APP/views/suppliers/add.ctp,
 line 6]

When you want to pass variables from the controller to the view, use
$this-set(). Otherwise, you're creating a variable that's outside the
view scope.

$this-set('user_id', $this-Session-read('userid'));

This will add the key  value to the $viewVars array. It'll be
available in the view because there's an extract() call in there
somewhere. In any case, it's all transparent. Use set() and then your
echo will work fine.

... unless there's no user_id in the session, of course ;-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Trouble fetching database information

2009-02-25 Thread Matt

Thank you so much! You can't imagine how much I appreciate your help -
I'm sure you remember how hard it was to wrap your head around MVC
when you're used to straight PHP!!

Thanks again!
-Mathieu

On Feb 25, 2:13 pm, brian bally.z...@gmail.com wrote:
 On Wed, Feb 25, 2009 at 2:54 PM, Matt mmanai...@gmail.com wrote:

  Hello and thank you so much for your help!!

  Brian,

  I took your advice and added the userid to the session, however, I'm
  clearly doing something wrong because in the Supplier controller I
  call the session with:
  $userid = $this-Session-read('userid');

  However in the view, I enter echo $userid;

  and I receive the following error:
  Notice (8): Undefined variable: userid [APP/views/suppliers/add.ctp,
  line 6]

 When you want to pass variables from the controller to the view, use
 $this-set(). Otherwise, you're creating a variable that's outside the
 view scope.

 $this-set('user_id', $this-Session-read('userid'));

 This will add the key  value to the $viewVars array. It'll be
 available in the view because there's an extract() call in there
 somewhere. In any case, it's all transparent. Use set() and then your
 echo will work fine.

 ... unless there's no user_id in the session, of course ;-)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---