我正在尝试在我的codeigniter应用程序中实现页面模板,模板工作正常,例如,我有一个博客页面,我试图指定为我的主页,具有不同的视图和分页等等.当我写www.mywebsite.com/blog时,它会在主页模板中打开,或者假设我有一个页面www.mywebsite.com/about,它也会在页面模板中打开.但是当我尝试通过www.mywebsite.com访问我的网站时,我有一个404错误页面.如何将我的博客页面指定为主页?
页面控制器:
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 } }
$route['default_controller'] = "page";
问题是,当您访问www.mywebsite.com时,没有URI段.您可以尝试将默认值设置为:
$this->uri->segment(1,'blog')
原文地址:https://www.jb51.cc/php/137094.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。