目前此代码有效。
class Home extends MY_Controller {
public function index($renderData=""){
$this->title = "Needzilla";
$this->keywords = "Needzilla";
$this->_render('pages/register',$renderData);
}
我在它下面添加这个的那一刻......
public function home($renderData=""){
$this->title = "Needzilla";
$this->keywords = "Needzilla";
$this->_render('pages/home',$renderData);
}
有时候是这样的。
指向这行代码。
//data
$toBody["content_body"] = $this->load->view($view,array_merge($this->data,$toTpl),true);
我试图弄清楚如何向控制器添加一个函数,以便当我调用该函数时它会打开另一个页面......例如......
从此页面获取(单击登录后)...
到这个页面...
完整的 My_Controller 代码在这里。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller{
//Page info
protected $data = Array();
protected $pageName = FALSE;
protected $template = "main";
protected $hasNav = TRUE;
//Page contents
protected $javascript = array();
protected $css = array();
protected $fonts = array();
//Page Meta
protected $title = FALSE;
protected $description = FALSE;
protected $keywords = FALSE;
protected $author = FALSE;
function __construct()
{
parent::__construct();
$this->data["uri_segment_1"] = $this->uri->segment(1);
$this->data["uri_segment_2"] = $this->uri->segment(2);
$this->title = $this->config->item('site_title');
$this->description = $this->config->item('site_description');
$this->keywords = $this->config->item('site_keywords');
$this->author = $this->config->item('site_author');
$this->pageName = strToLower(get_class($this));
}
protected function _render($view,$renderData="FULLPAGE") {
switch ($renderData) {
case "AJAX" :
$this->load->view($view,$this->data);
break;
case "JSON" :
echo json_encode($this->data);
break;
case "FULLPAGE" :
default :
//static
$toTpl["javascript"] = $this->javascript;
$toTpl["css"] = $this->css;
$toTpl["fonts"] = $this->fonts;
//meta
$toTpl["title"] = $this->title;
$toTpl["description"] = $this->description;
$toTpl["keywords"] = $this->keywords;
$toTpl["author"] = $this->author;
//data
$toBody["content_body"] = $this->load->view($view,array_merge($this->data,$toTpl),true);
//nav menu
if($this->hasNav){
$this->load->helper("nav");
$toMenu["pageName"] = $this->pageName;
$toHeader["nav"] = $this->load->view("template/nav",$toMenu,true);
}
$toHeader["basejs"] = $this->load->view("template/basejs",$this->data,true);
$toBody["header"] = $this->load->view("template/header",$toHeader,true);
$toBody["footer"] = $this->load->view("template/footer",'',true);
$toTpl["body"] = $this->load->view("template/".$this->template,$toBody,true);
//render view
$this->load->view("template/skeleton",$toTpl);
break;
}
}
}
完整的家庭课程
class Home extends MY_Controller {
public function index($renderData=""){
$this->title = "Needzilla";
$this->keywords = "Needzilla";
$this->_render('pages/home',$renderData);
}
}