一个控制器三页

时间:2017-07-18 09:42:43

标签: codeigniter controller

我有一个控制器ADD。我希望这个控制器操作三个页面:add_customer页面,add_project页面和add_post_page。在这种情况下,add_project页面可以完美地运行。但add_customeradd_post页面有错误:

  

无法加载资源:服务器响应状态为500(内部服务器错误)。

我认为问题在于我的编纂:

public function index(){
    if($this->uri->segment(3)=='add_customer'){
        $this->add_customer(); 
    }
    else if($this->uri->segment(3)=='add_post'){
        $this->add_post(); 
    }
    else{
        $this->add_project(); 
    }
}

这是我的完整控制器:     

class ADD  extends MX_Controller {

public $mname, $tag, $tpl;

function __construct()
{
    $this->mname=strtolower(get_class());             
    $this->tag=strtoupper($this->mname); 
} 


public function index(){

    if($this->uri->segment(3)=='add_customer'){
        $this->add_customer(); 
    }

    else if($this->uri->segment(3)=='add_post'){
        $this->add_post(); 
    }

    else{
        $this->add_project(); 
    }

}

public function add_project()
{ 
    include APPPATH."language/".LANG.".php";

    $this->load->model($this->mname.'/add_project_model');
    $model='add_project_model';
    $this->$model->index($this->mname);

    $a['IsEnabled']=$LANGUAGE['IsEnabled']; 
    $a['Submit']=$LANGUAGE['Submit'];
    $a['Cancel']=$LANGUAGE['Cancel'];
    $a['Reset']=$LANGUAGE['Reset'];
    $a['Name']=$LANGUAGE['Name'];
    $a['SelectCustomer']=$LANGUAGE['SelectCustomer'];
    $a['Project Name']=$LANGUAGE['ProjectName'];
    $a['Manager']=$LANGUAGE['Manager'];
    $a['Customer']=$LANGUAGE['Customer'];

    $userGROUP = $this->session->userdata('_userGROUP');
    if ($userGROUP=='Administrator')
        $a['AddManager']='<button type="button" class="btn btn-warning" onclick="AddNewManager()">+</button>';
    else
        $a['AddManager']='';

    $this->tp->assign($a);
    $this->tp->parse('CONTENT', $this->mname.'/add_project.tpl');
}

public function add_customer()
{   
    include APPPATH."language/".LANG.".php";

    $userGROUP = $this->session->userdata('_userGROUP');

    if($userGROUP!=='Administrator')
    {
        show_404('page');
        exit; 
    }

    $this->load->model($this->mname.'/add_customer_model');
    $model='add_customer_model';
    $this->$model->index($this->mname);


    $a['IsEnabled']=$LANGUAGE['IsEnabled']; 
    $a['Submit']=$LANGUAGE['Submit'];
    $a['Cancel']=$LANGUAGE['Cancel'];
    $a['Reset']=$LANGUAGE['Reset'];
    $a['Name']=$LANGUAGE['Name'];
    $a['Project Name']=$LANGUAGE['CustomerName'];
    $a['Customer Name']=$LANGUAGE['Customer Name'];

    $this->tp->assign($a);
    $this->tp->parse('CONTENT', $this->mname.'/add_customer.tpl');
}


public function add_post()
{ 
    include APPPATH."language/".LANG.".php";

    $userGROUP = $this->session->userdata('_userGROUP');

    if($userGROUP=='Engineer')
    {
        show_404('page');
        exit; 
    }

    $this->load->model($this->mname.'/add_post_model');
    $model='add_post_model';
    $this->$model->index($this->mname);


    $a['IsEnabled']=$LANGUAGE['IsEnabled']; 
    $a['Submit']=$LANGUAGE['Submit'];
    $a['Cancel']=$LANGUAGE['Cancel'];
    $a['Reset']=$LANGUAGE['Reset'];
    $a['Activity Name']=$LANGUAGE['Activity Name'];
    $a['SalaryHour']=$LANGUAGE['SalaryHour'];

    $this->tp->assign($a);
    $this->tp->parse('CONTENT', $this->mname.'/add_post.tpl');
}

}

如何解决此问题?

2 个答案:

答案 0 :(得分:0)

试一试,希望它有效:

public function index(){
    if($this->uri->segment(3)=='add_customer'){
        redirect(base_url().'/Add/add_customer');
        //$this->add_customer(); 
    }
    else if($this->uri->segment(3)=='add_post'){
        redirect(base_url().'/Add/add_post');
        //$this->add_post(); 
    }
    else{
        redirect(base_url().'/Add/add_project');
        //$this->add_project(); 
    }
}

答案 1 :(得分:0)

永远不会达到您的索引功能

这将达到它:http://project.dev/add

默认情况下,以下网址会点击相应的功能。

http://project.dev/add/add_customer点击公共函数add_customer()

http://project.dev/add/add_post点击公共函数add_post()

如果您遇到错误,请查看特定功能中的各种错误,并确保您已启用错误报告