mercredi 9 mai 2018

Checking if Post author is equal to logged in user

A user can post a 'Tutorial', each tutorial is associated with its author via their 'user_id'. My problem is I want to alter the view if the logged in user is viewing their own post (Tutorial).

CONTROLLER:

  public function view($id = null)
{
    $tutorial = $this->Tutorials->get($id, [
        'contain' => ['Users','Courses', 'TutorialComments.Users']
    ]);


    $tutorialComment = $this->Tutorials->TutorialComments->newEntity();

    $this->set(compact('tutorial', 'tutorialComment'));

}

VIEW:

<? if (($tutorial->user->id) === ($this->request->session()->read('Auth.User.id'))): ?> 

<p> hello </p>

 <? endif; ?> 

Aucun commentaire:

Enregistrer un commentaire