如何在Codeigniter中获取发出请求的类 [英] How to get the class from which a request originates in codeigniter
问题描述
我的模块全部扩展了Backend控制器,该控制器检查是否已登录并适当地重定向,现在我有了Class FrontEnd [负责登录,注册等页面],它扩展了My_Controller。
我该如何为FrontEnd创建豁免以使其能够访问模块,因为它需要它们的方法来执行任务。
My modules all extend Backend controller which checks if loggedin and redirects appropriately, now I have Class FrontEnd [responsible for pages like login, signup etc] which extends My_Controller. how can I create an exemption for FrontEnd to be able to access the modules since it needs their methods to perform tasks.
这是我目前拥有的。 ...
this is what I have currently ....
class Backend_Controller extends MY_Controller {
// --------------------------------------------------------------------------
public function __construct() {
parent::__construct();
$this->checkLoggedIn();
}
// --------------------------------------------------------------------------
public function checkLoggedIn() {
//check if loggedin
if (!$this->auth->loggedIn()) {
//implement exclusion for FrontEnd class to allow access to methods though not logged in
if (!the class trying to access == 'FrontEnd') { //how to get refferal page
return;
} else {
redirect('login');
}
}
}
// --------------------------------------------------------------------------
}
我如何获得尝试访问的类=='FrontEnd
附加信息:
FrontEnd类生成一个表单,该表单的
此处输入代码
action = router-> fetch_class()将导致someMoudleName,
,但我想要的是它能够检测到该操作来自FrontEnd类
how can I get "the class trying to access == 'FrontEnd"
Edditional Info:
the FrontEnd class generates a form which has an
enter code here
action= router->fetch_class() will result in someMoudleName ,
but what i want is for it to be able to detect that the action is coming from FrontEnd Class
推荐答案
这取决于您的网址,但您可以执行以下操作。.
This will depend on your url but u can do something like this..
function getNameOfOriginatingClass{
$this->load->library('user_agent');
$previous_url = $this->agent->referrer();
$url_segments = explode('/',$previous_url);
echo '<pre>';print_r($url_segments);
}
打印此结果后,您可以看到您的链接分成数组。通常,$ url_segments [3]或$ url_segments [4]将包含您先前的函数名称,而先前的将包含先前的类名称(取决于您的URL)。
after printing this result u can see your link broken into parts in an array.. Normally the $url_segments[3] or $url_segments[4] will contain your previous function name and previous one will contain previous class name depending upon your url.
这篇关于如何在Codeigniter中获取发出请求的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!