You have to find the Post first, so:
$post = $this->Post->find('first', array('conditions' =>
array('Post.id' => $id)));
if ($post != null && $post['Post']['user_id'] == $this->Auth-
>user('id') ){
//delete
}
or you can use conditions =>array('Post.user_id' =>$this->Auth-
>user('id'), 'Post.id' => $id ))));
if ($post != null)
{
//delete
}
else invalid post
On dec. 7, 15:08, Steve Mallett <[email protected]> wrote:
> Got no love from that... tried changing up to
>
> function delete($id = null) {
> if (!$id) {
> $this->Session->setFlash(__('Invalid id for post',
> true));
> $this->redirect(array('action'=>'index'));
> }
> if($this->Session->read('Auth.User.id') ==
> $this->Post->user_id ) { // HERE
> if ($this->Post->delete($id)) {
> $this->Session->setFlash(__('Post deleted', true));
> $this->redirect(array('action'=>'index'));
> }
> }
> $this->Session->setFlash(__('Post was not deleted', true));
> $this->redirect(array('action' => 'index'));
> }
>
> Now only get error: Undefined property: Post::$user_id
> [APP/controllers/posts_controller.php, line 74]
>
> What is the delete function needing to get Post info?
>
>
>
>
>
>
>
>
>
> On Tue, Dec 7, 2010 at 9:31 AM, euromark <[email protected]> wrote:
> > *LOL*
> > well, sometimes even PHP is case sensitive
>
> > try User and PostUser
>
> > On 7 Dez., 14:26, Steve Mallett <[email protected]> wrote:
> >> I'm working from the 1.3 blog & Acl tutorial.
>
> >> in posts_controlllers.php I'm trying to add
>
> >> if($this->user->id == $this->postUser->id ) { to the delete function
> >> so anyone can't type in /posts/delete/postNumber to delete other's
> >> posts like so:
>
> >> function delete($id = null) {
> >> if (!$id) {
> >> $this->Session->setFlash(__('Invalid id for post',
> >> true));
> >> $this->redirect(array('action'=>'index'));
> >> }
>
> >> if($this->user->id == $this->postUser->id ) { //// HERE
> >> if ($this->Post->delete($id)) {
> >> $this->Session->setFlash(__('Post deleted', true));
> >> $this->redirect(array('action'=>'index'));
>
> >> }
> >> }
>
> >> then I get:
>
> >> Notice (8): Undefined property: PostsController::$user
> >> [APP/controllers/posts_controller.php, line 81]
>
> >> Thanks in advance,
>
> >> --
> >> Steve
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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
> > athttp://groups.google.com/group/cake-php?hl=en
>
> --
> Steve Mallett
> inevitable.cc (the) Inevitable Corp.
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