Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
397 views
in Technique[技术] by (71.8m points)

php - Codeigniter Setting Homepage ( Default Controller )

I'm trying to implement page templating in my codeigniter application, templating is working fine for instance, i have a blog page, which i'm trying to assign as my homepage, with different view and pagination and so on. When i write www.mywebsite.com/blog, it gets opened in homepage template, or assume that i have a page www.mywebsite.com/about , it gets opened in page template too. But when i try to access my website via www.mywebsite.com, i have a 404 error page. How can i assign my blog page as the homepage ?

Page Controller :

class Page extends Frontend_Controller {

public function __construct(){
    parent::__construct();
    $this->load->model('page_m');
}

public function index() {

// Fetch the page template
$this->data['page'] = $this->page_m->get_by(array('slug' => (string) $this->uri->segment(1)), TRUE);
count($this->data['page']) || show_404(current_url());

add_meta_title($this->data['page']->title);
add_meta_keyword($this->data['page']->keywords);
add_meta_description($this->data['page']->description);

// Fetch the page data
$method = '_' . $this->data['page']->template;
if (method_exists($this, $method)) {
        $this->$method();
}
else {
log_message('error', 'Could not load template ' . $method .' in file ' . __FILE__ . ' at line ' . __LINE__);
}

// Load the view
$this->data['subview'] = $this->data['page']->template;
$this->load->view('_main_layout', $this->data);
}

private function _page(){ // methods }
private function _homepage(){ // methods }
}

in my Routes, i have set my default controller to page controller

$route['default_controller'] = "page";
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

application/config/routes.php

$route['default_controller'] = 'namecontroller';

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...