Codeigniter Setting Homepage ( Default Controller )

后端 未结 3 825
有刺的猬
有刺的猬 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

    0 讨论(0)
  • 2020-12-18 02:00

    application/config/routes.php

    $route['default_controller'] = 'namecontroller';
    
    0 讨论(0)
  • 2020-12-18 02:06

    The problem is that there's no URI segment when you visit www.mywebsite.com. You can try setting the default value as:

    $this->uri->segment(1 , 'blog')
    
    0 讨论(0)
提交回复
热议问题