Here is the solution (posting it because it may help some people)
public function view($id = null) {
$this->loadModel('Item');
$items = $this->set('items', $this->Item->find('all',
array('conditions' => array('Item.ownerid' => $id))));
$this->User->id = $id;
if (!$this->User->exists()) {
throw new NotFoundException(__('Invalid user'));
}
$this->set('user', $this->User->read(null, $id));
}
On 26 déc, 12:38, Tilen Majerle <tilen.maje...@gmail.com> wrote:
> http://book.cakephp.org/2.0/en/models/retrieving-your-data.htmllook at
> this post :)
> --
> Lep pozdrav, Tilen Majerlehttp://majerle.eu
>
> 2011/12/26 J. <contact.mysparet...@gmail.com>
>
>
>
>
>
>
>
> > Thanks ! This worked :
>
> > $this->loadModel('Post');
> > $posts= $this->set('posts', $this->Post->find('all'));
>
> > If I may ask a last question :
>
> > This returns ALL posts. I want to display only owned posts. How should
> > I replace "all" by my $ownerid variable ?
>
> > On 25 déc, 22:36, euromark <dereurom...@googlemail.com> wrote:
> > > classic design failure
> > > you shouldn't (ever) use a controller in another controller
>
> > > design your actions the way that they use the model to get the data
> > > this way you can call these model methods from other controllers, as
> > > well
>
> > > so it boils down to
> > > $this->Model->ownPosts($uid)
>
> > > etc
>
> > > On 25 Dez., 19:13, "J." <contact.mysparet...@gmail.com> wrote:
>
> > > > 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 sitehttp://ask.cakephp.organd 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
> > athttp://groups.google.com/group/cake-php
--
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
No comments:
Post a Comment