繁体   English   中英

一个可用于Codeigniter中某些模型和视图的控制器

[英]one controller for some models and views in codeigniter

我有三个模型:add_customer_model,add_post_model和add_project_model。 我也有三个视图:add_customer.tpl,add_post.tpl和add_project.tpl。 我想为他们做一个控制器。 这里是:

  <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ADD extends MX_Controller {

public $mname, $tag, $tpl;

function __construct()
{
    $this->mname=strtolower(get_class());// imya modulya               
    $this->tag=strtoupper($this->mname); // TAG v shablone   
} 


//add_customer
public function index()
{   
    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=$this->mname.'_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');
}


//add_post
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=$this->mname.'_model';
    $this->$model->add_post($this->mname);
    $a['IsEnabled']=$LANGUAGE['IsEnabled']; 
    $a['Submit']=$LANGUAGE['Submit'];
    $a['Cancel']=$LANGUAGE['Cancel'];
    $a['Reset']=$LANGUAGE['Reset'];
    $a['Activity Name']=$LANGUAGE['Activity Name'];

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

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

    $this->load->model($this->mname.'/add_project_model');
   // $model=$this->mname.'_model';
   // $this->$model->add_project($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');
}

}

But in my browser I can see only add_customer page. But when I want to see add_post and add_project pages, it also shows me add_customer page. Where is a mistake?
$this->load->model($this->mname.'/'.$this->mname.'add_post_model');

转换为:

$this->load->model('add/addadd_post_model');

异常设置。 我想如果将其更改为以下内容,则可能会起作用:

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

暂无
暂无

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

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