在我的頁面中,我有一個側邊欄,我想顯示管理鏈接,只要用戶具有管理權限即可。我在控制器方法工作正常,但是當我用他的觀點我有一個錯誤:ZF2如何調用功能
PHP Fatal error: Call to a member function get() on a non-object in /UNXDEVCKT01/www/firewall/ZendFramework/module/Firewall/src/Firewall/Service/UserRight.php on line 59
我不明白,不工作...
我班UserRight類:
<?php
namespace Firewall\Service;
use Zend\Mvc\Controller\ActionController;
use Zend\Session\Container;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Db\TableGateway\Feature\RowGatewayFeature;
use Zend\Db\TableGateway\TableGateway;
use Zend\Mvc\Controller\Plugin\FlashMessenger;
use Zend\Http\Request;
class UserRight extends AbstractActionController
{
# Boolean
public function hasAdminRight()
{
# Call the User service table
$Rights = $this->getServiceLocator()->get('Firewall\Model\UserTable')->fetchAllList($this->session->user_id);
echo $Rights->right_admin. ' '. $Rights->user_group_admin;
# Check is the user have the admin rights, else he's redirected
return (($Rights->right_admin == 'n' && $Rights->user_group_admin == 'n')) ? false : true;
}
// Code ...
}
?>
我的觀點:
<h3>Template</h3>
<ul class="toggle">
<li class="icn_folder"><a href="#">File manager</a></li>
<li class="icn_photo"><a href="#">Gallery</a></li>
<li class="icn_audio"><a href="#">Audio</a></li>
<li class="icn_video"><a href="#">Video</a></li>
</ul>
<br/>
<?php
$UserRight = new \Firewall\Service\UserRight;
if($UserRight->hasAdminRight()):
?>
<hr/><h3>Administration</h3>
<ul class="toggle">
<li class="icn_add_user"><a href="<?php echo $this->url('user', array('action'=>'add'));?>">New user</a></li>
<li class="icn_categories"><a href="<?php echo $this->url('user', array('action'=>'list'));?>">User list</a></li>
<br/>
<li class="icn_profile"><a href="<?php echo $this->url('profile', array('action'=>'add'));?>">New profile</a></li>
<li class="icn_categories"><a href="<?php echo $this->url('profile', array('action'=>'list'));?>">Profile list</a></li>
<br/>
<li class="icn_view_users"><a href="<?php echo $this->url('group', array('action'=>'add'));?>">New group</a></li>
<li class="icn_categories"><a href="<?php echo $this->url('group', array('action'=>'list'));?>">Group list</a></li>
<!--<br/>
<li class="icn_settings"><a href="#">Options</a></li>
<li class="icn_security"><a href="#">Security</a></li>
<li class="icn_jump_back"><a href="#">Logout</a></li>-->
</ul>
<?php endif; ?>
好!謝謝 ! – Dimitri