我正在使用CakePHP 2.0
,我試圖瞭解如何在用戶登錄應用程序時使用echo
動態內容。如果用戶登錄時回顯不同的菜單
在view
我想呼應菜單登錄或註銷用戶,我該怎麼做?
// I'm in the default template view
if (!AuthComponent::loggedIn()) {
$menu = $this->Html->link('Login', array('controller' => 'users', 'action' => 'login'));
$menu .= $this->Html->link('Register', array('controller' => 'users', 'action' => 'register'));
} else {
$menu = $this->Html->link('Home', array('controller' => 'users', 'action' => AuthComponent::user('id'), AuthComponent::user('username')));
$menu .= $this->Html->link('Logout', array('controller' => 'users', 'action' => 'logout'));
}
echo $menu;
我以爲這樣的東西,但我讀過它打破了MVC的規則。
我該如何在CakePHP中做這樣的事情? 在線是否存在一些示例?