Codeigniter Setting Homepage ( Default Controller )

╄→гoц情女王★ 提交于 2019-11-28 11:16:49

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')

application/config/routes.php

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!