$this对象在已加载的带有angular的模板中



我正试图在我的Codinglighter+AngularJs页面中实现一些ACL内容。我使用ng路线,所以我在主视图页面上有这行:

<div ng-view></div>

我正在使用离子身份验证库来帮助实现ACL。

这是我的控制器:

public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library(['ion_auth', 'form_validation']);
$this->load->helper(['url', 'language']);
$this->lang->load('auth');
}
public function index()
{
if (!$this->ion_auth->logged_in())
{
// redirect them to the login page
redirect('/login', 'refresh');
}
else
$this->load->view('master_view');
}

这是我的ng路线使用:

var app = angular.module("myApp", ["ngRoute","bw.paging"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "/app/templates/cars_list.php",   
controller: "CarsController"
})
});

当我试图在主视图中使用离子身份验证的功能时,它运行良好:

<?php if($this->ion_auth->in_group('admin')):?>
<a class="nav-item nav-link" href="index.php#!/list">Users</a>
<?php endif;?>

但当我在加载的模板(cars_list.php(中尝试这一行时,它什么也没做。请帮帮我。我怎么能在模板中使用$this?TIA!

您不能在模板中使用$this,而是可以这样做。

public function index()
{
if (!$this->ion_auth->logged_in())
{
// redirect them to the login page
redirect('/login', 'refresh');
}
else{
$data = [];
$data["allowed"] = $this->ion_auth->in_group('admin');
$this->load->view('master_view',$data);
}
}

可视

<?php if($allowed):?>
<a class="nav-item nav-link" href="index.php#!/list">Users</a>
<?php endif;?>

最新更新