【问题标题】:URI routing CodeigniterURI 路由 Codeigniter
【发布时间】:2013-03-18 12:44:33
【问题描述】:

在 CodeIgniter 中遇到路由问题。

这是我的 routes.php

$route['default_controller'] = "site/site/index/$1";
$route['404_override'] = '';
$route['admin'] = 'admin/index';

我使用的是模块化系统,我的文件夹格式是:

在模块>站点>控制器>site.php中,我有以下内容可以获取输入到cms中的每个路径,但问题是当我导航到localhost/my_site/时,它会显示页面但带有错误,所以如果我将以下路线放入: $route['site/(:any)'] = 'site/site/index/$1';然后它可以工作并显示所有页面,但显然我不想要这个,我希望它知道主页已设置。或者这可以通过 htaccess DirectoryIndex 来完成吗??

如果这没有意义,或者你无法理解我的意思,请大声告诉我,我会尝试解释更多细节,但这就是问题所在。

【问题讨论】:

标签: codeigniter url-rewriting


【解决方案1】:

我认为这是因为您的默认控制器需要一个参数,但您没有传递它一个

$route['default_controller'] = "site/site/index/$1";

我觉得应该是的

$route['default_controller'] = "site/site/index";

【讨论】:

  • 是的,我现在有了,但我想在第一次导航到 localhost/my_site 时显示主页,而不是我必须转到 localhost/my_site/site/home,这显然是我不想要的,怎么能得到圆这个?
  • 试试 $route['default_controller'] = "site/home";或 $route['default_controller'] = "site/site/home";
  • 但我没有函数/方法主页,它只是一种获取 $path 的索引方法,如 so.public function index($path = ''){ $page = $this->wc_main- >getPagePath($path); $this->front->set('page', $page); $this->front->set('title', ucfirst($page['title'])); $this->front->buffer('content', 'site/index'); $this->front->render(); }
  • 那么wc_main模型getPagePath为:function getPagePath($path){ $data = array(); $this->db->where('path', $path); $this->db->where('status', '1'); $this->db->order_by('pid', 'asc'); $this->db->limit(1); $Q = $this->db->get('wc_pages'); if ($Q->num_rows() > 0){ $data = $Q->row_array(); } $Q->free_result();返回$数据; }
  • 从那以后我设法做到了: $route['default_controller'] = "site/site/index/home";所以现在导航到 localhost/my_site 会显示主页。
猜你喜欢
  • 2014-12-20
  • 1970-01-01
  • 2014-12-06
  • 2013-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-26
相关资源
最近更新 更多