1

i am newbie in cakephp ..actually i have two problems .. first one is I am setting variables in AppController in order to use them in default.ctp.

public function beforeRender(){

    $id = $this->Auth->user('idUser');

    $this->loadModel('Userinfo');
    $data= $this->Userinfo->find('all',array(
        'conditions' => array('Userinfo.User_id' => $id)
    ));

    foreach($data as $d){
        $product_purchase = $d['Userinfo']['product_purchase'];
    }

    $this->set('userinfo',$product_purchase);
}

so it is working fine when i use the variable into my default.ctp layout .. but the problem is when i logout from the the app then it displays this error on my login page

Undefined variable: product_purchase

What am I doing wrong? by the way i want to mention here is that in my login page i am not using default.ctp well which i think it has nothing to do with dat

the second problem is i want to show specific menu items for the specific user ... so i am doing this in my view page

<?php if ($userinfo == 1){ ?> 
  <li><a href="explorer.html" class="shortcut-medias" title="Media">Media</a> </li>
<?php }else{ //nothing }?>

value in userinfo is 2 .. but if else isnt working .. it is still displaying the menu

AD7six
  • 63,116
  • 12
  • 91
  • 123
hellosheikh
  • 2,929
  • 8
  • 49
  • 115
  • Hey... Is the code in your application laid out as it is here in this question? If it is, you are breaking your if statement as `//nothing` is commenting out `}` – AKKAweb Jun 19 '13 at 18:32
  • @A_Santiago and then tell me what would i do then ?what it should be in the else part ... as i just want to hide the Media Menu if there is $userinfo value other then 1 – hellosheikh Jun 20 '13 at 03:52
  • thankyou i got my problem .. actually i dont have to write the else part ...it works fine without the else part like this
  • Media
  • and it works .. thankyou – hellosheikh Jun 20 '13 at 04:01