开发者

Convert a function to an OO method

开发者 https://www.devze.com 2023-02-24 01:46 出处:网络
ok, so i have this function. Ive stripped it down to and removed all the html. if($session->开发者_Go百科power == \'admin\'){

ok, so i have this function. Ive stripped it down to and removed all the html.

if($session->开发者_Go百科power == 'admin'){
    $adminMenu= $user->admin_menu;
     foreach($adminMenu as $key => $value):{ 
        echo $value; echo $key; 
     } endforeach; 
}

I am trying to covert this into an OO method, this is my method so far:

user class

public function get_menu(){
global $session;
$user_status = $session->power;
$adminMenus = $this->admin_menu; // associate array ($key => value)
$menu = array();
if($user_status == 'admin'){
     foreach($adminMenus as $adminMenu):{ 
       $menu = array($adminMenu);
       return array_shift($menu);
     } endforeach;
}

then in the display file

while($user->get_menu()){
echo $user->get_menu();
}

I know this is completely wrong - because it doesn't work. So can you please help me make it object orientated.


    public function get_menu(){
    global $session;
    $user_status =  $session->power; 
    $adminMenus =$this->admin_menu; // associate array($key => value)
    if($user_status == 'admin')
    { 
      foreach($adminMenus as $key => $value):
      { 
       echo $key . $value;  
      } 
    }
}

then in the display file

$user->get_menu();
0

精彩评论

暂无评论...
验证码 换一张
取 消