找到你要的答案

Q:Routing to different function based on login

Q:基于登录的不同功能路由

How can i call the different function based on the login. I have a user login it should check whether the user is employee or student stored on the database on user_type.

I have a controller with two functions:

class mainextends CI_Controller {

function index()
{
    echo "main";
}

function student($user_id)
{
    //code
}

function employee($user_id)
{
    //code
}

routes.php:

$route['default_controller']   = "main";
$route['people/(.*)']          = "main/student/$1";
$route['trainer/(.*)']         = "main/employee/$1";
$route['404_override']         = '';

Where can i check the user_type before redirecting it to appropriate url.

如何根据登录名调用不同的功能。我有一个用户登录,则应检查用户是否存储在数据库user_type雇员或学生。

我有一个控制器有两个功能:

class mainextends CI_Controller {

function index()
{
    echo "main";
}

function student($user_id)
{
    //code
}

function employee($user_id)
{
    //code
}

routes.php:

$route['default_controller']   = "main";
$route['people/(.*)']          = "main/student/$1";
$route['trainer/(.*)']         = "main/employee/$1";
$route['404_override']         = '';

我在哪里可以在重定向到适当的URL检查user_type。

answer1: 回答1:

A simple solution is to use the codeigniter _remap function, just place it in your controller with some logic:

    function _remap($methode){
      // do something
}

A better solution is to have a basecontroller, which you include in every controller and expend it. In this basecontroller you put the access-control and the complete basic stuff.

一个简单的解决方案是使用CodeIgniter _remap功能,只是把它放在你的控制器和一些逻辑:

    function _remap($methode){
      // do something
}

一个更好的解决办法是有一个方法,你包括在每个控制器和扩展。这个方法你把访问控制和完成基本的东西。

php  codeigniter