Sunday, December 25, 2011

Use classes from a different controller

Hello.

I'm building an app derivated from the cakephp blog tutorial.

On the User profils, I want to display which posts they own (my posts
have a owner_id field) with a foreach.

But to use the classes from my Posts Controller in my UsersController,
I used this code :

App::import('Controller', 'Posts');

$Posts = new PostsController;

$Posts->constructClasses();,


but when doing this :


<?php foreach ($posts as $post): ?>


I get this on the page :

Undefined variable: posts [APP/View/Users/view.ctp, line 78]

and

Warning (2): Invalid argument supplied for foreach() [APP/View/Users/
view.ctp, line 78]

I'm new to cake and php, so I really don't understand what's the
problem here.

thanks for your time and merry Christmas !


--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate