Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter中基于模块的登录_Php_Codeigniter - Fatal编程技术网

Php CodeIgniter中基于模块的登录

Php CodeIgniter中基于模块的登录,php,codeigniter,Php,Codeigniter,我想创建一个基于模块的登录。我的应用程序有不同的用户、管理员、作者、编辑器等等 为此,在CodeIgniter中开发登录机制的最佳方法是什么?权限。有几个预先制作的选项可用,或者您可以从头开始构建一个。您可以创建自己的控制器,检查访问特定区域的不同权限。 例如,您可以创建Admin\u Controller和Author\u Controller,并在其中创建所有控制人员。 要扩展主CI\u控制器,您需要在名为“MY\u Controller”的“application/core”文件夹中创建一

我想创建一个基于模块的登录。我的应用程序有不同的用户、管理员、作者、编辑器等等


为此,在CodeIgniter中开发登录机制的最佳方法是什么?

权限。有几个预先制作的选项可用,或者您可以从头开始构建一个。

您可以创建自己的控制器,检查访问特定区域的不同权限。
例如,您可以创建
Admin\u Controller
Author\u Controller
,并在其中创建所有控制人员。
要扩展主
CI\u控制器
,您需要在名为“
MY\u Controller
”的“
application/core
”文件夹中创建一个新文件,其中包含您的员工

例如:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin_login extends CI_Controller{
     function __construct(){
          parent::__construct();
         //Your check staff
     }
}
class Author_login extends CI_Controller{
     function __construct(){
              parent::__construct();
             //Your check staff
         }

}
-

基本上,它检查会话登录并将用户分配给
$this->user
然后,一旦分配了用户,它就会分配他们的组和权限。 现在,您可以轻松地检查这些变量是否匹配字符串/数组

如果需要在视图中运行检查,可以执行以下操作

<?php if(Modules::run('class/has_permissions_to_run_this')): ?>
<p>Good to load a view or print a form</p>
<?php else: ?>
<p>You need the correct credentials to view/edit this</p>
<?php endif;?>
-

您的表结构可能会如下所示

--向要搜索的行(如id、电子邮件、别名)添加索引

ALTER TABLE `users` ADD INDEX( `id` );
ALTER TABLE `users` ADD INDEX( `email` );
ALTER TABLE `users` ADD INDEX( `alias` );

嗯,就像用户可以做的与他相关的某些动作一样。管理员可以创建用户。作者可以提交文章等,你不觉得有点简洁吗?需要更多的细节。@davidethell:虽然我同意你的观点,但它肯定符合问题的模糊性和质量。@david我也可以给他“Codeigniter权限”的谷歌搜索链接,你也会投反对票吗?
class some_module extends MY_Controller{

    public function __construct(){
           parent::__construct();
    }

    public function module_method(){
        if($this->group === 'AUTHOR' AND $this->can_edit())
        {
            // you have access to edit this modules's content
        }
    }
}
<?php if(Modules::run('class/has_permissions_to_run_this')): ?>
<p>Good to load a view or print a form</p>
<?php else: ?>
<p>You need the correct credentials to view/edit this</p>
<?php endif;?>
class Admin extends MY_Controller{

    public function __construct() {
        parent::__construct();

        if( ! $this->_check_admin_credentials())
        {
            redirect('login');
        }

    }

    public function _check_admin_credentials(){
        return (bool)( 
            $this->_can_read()
            AND $this->_can_edit()
            AND $this->_can_delete()
            AND $this->group === 'admin'
        );
    }
public function for_super_user_only(){

        // if you need to block specific sections such as 
        // global settings or accounting from other admins
        // run the check inside the method itself
        if($this->group == 'super')
        {
            //continue;
        }
        else
        {
            show_404();
            //or display error view
        }
    }
create table `users`(
`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
`group` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`firstname` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`lastname` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`alias` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`last_ip` varchar(16) COLLATE utf8_unicode_ci NOT NULL,
`permissions` varchar(250) NOT NULL DEFAULT '["read", "update", "delete"]',
`active` boolean NOT NULL DEFAULT 0,
`activation_code` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL,
`password_token` text COLLATE utf8_unicode_ci DEFAULT NULL,
`last_login` datetime NOT NULL,
`created_at` datetime NOT NULL,
UNIQUE( `email` ),
UNIQUE( `alias` )
) ENGINE=InnoDB CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registered Users';
ALTER TABLE `users` ADD INDEX( `id` );
ALTER TABLE `users` ADD INDEX( `email` );
ALTER TABLE `users` ADD INDEX( `alias` );