简体   繁体   English

将模块控制器重定向到HMVC代码点火器中的一个特定控制器

[英]Redirecting modules controller to one specific controller in HMVC codeigniter

Making an offline app with codeigniter . 使用codeigniter制作离线应用程序。 The app is used for storing client data . 该应用程序用于存储客户端数据。 I have used codeigniter hmvc approach . 我已经使用了codeigniter hmvc方法。 and now i have about eight modules in my app like templates , search, client , user etc ..user module checks for admin authentication . 现在我的应用程序中大约有八个模块,例如模板,搜索,客户端,用户等。.user模块检查管理员身份。 The number of modules will increase in the future . 将来模块的数量将增加。

Now to check if a user is logged in as admin i have used this piece of code in every module in __construct() function without templates and user modules because when i try to put this code in templates or users controller then firefox says Page could not be redirected properly 现在要检查用户是否以admin身份登录,因此我在__construct()函数的每个模块中都使用了这段代码,而没有模板和用户模块,因为当我尝试将此代码放入模板或用户控制器时,firefox说Page could not be redirected properly

if(!$this->session->userdata('user_type')){
    redirect(base_url().'users/login');
} 

Pasting this piece of code to templates and users module creates the problem . 将这段代码粘贴到模板和用户模块中会产生问题。 when i remove this code then everything works fine . 当我删除此代码,然后一切正常。 as so user can still acess templates and user modules without login . 这样,用户仍然可以无需登录即可访问模板和用户模块。

I just want to know that if there is any better way of doing it without pasting this piece of code in every controllers or making guest not to access any modules or method without login . 我只是想知道,是否有更好的方法可以做到,而不必在每个控制器中粘贴这段代码,也可以使来宾在没有登录的情况下不访问任何模块或方法。

If you have specified the complete site url, into redirect there is already the path without using base_url() 如果您指定了完整的站点URL,则在不使用base_url()情况下,进入重定向的路径已经存在
try this: 尝试这个:

if(!$this->session->userdata('user_type')){
    redirect('/users/login');
} 

If you user HMVC than you can do it like this: 如果您使用的是HMVC,则可以这样操作:

if(!$this->session->userdata('user_type')){
    redirect('module_name/users/login'); // change module_name with your module name
}

UPDATE: Maybe, You redirect on one page that redirect also... and put on loop 更新:也许,您在一个页面上重定向,该页面也重定向...并循环播放

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM