Codeigniter Setting Homepage ( Default Controller )

后端 未结 3 838
有刺的猬
有刺的猬 2020-12-18 01:35

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 homepa

3条回答
  •  攒了一身酷
    2020-12-18 02:00

    Your code

    // 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());
    

    the uri segment code

    $this->uri->segment(1)
    

    is looking first url segment, when you browse your site like www.yousite.come/blog it will work find but when you do www.yoursite.com 1st uri segment is missing so it will return false , so i will show 404 page.

    Solution : You can just add the second parameter to the function like

    $this->uri->segment(1,'blog');
    

    now if the first url segment is missing it will not return false,it will return the default vlaue 'blog'

    For more information about this you can see codeingitor documentation

提交回复
热议问题