if($session->power == 'admin'){
$adminMenu= $user->admin_menu;
foreach($adminMenu as $key => $value):{
echo $value; echo $key;
} endforeach;
}
我试图将其转换为OO方法,到目前为止这是我的方法:
用户类
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;
}
然后在显示文件中
while($user->get_menu()){
echo $user->get_menu();
}
我知道这是完全错误的 - 因为它不起作用。所以,请你帮我把它作为面向对象。
答案 0 :(得分:0)
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;
}
}
}
然后在显示文件中
$user->get_menu();