【问题标题】:codeigniter route with method and edit带有方法和编辑的codeigniter路由
【发布时间】:2015-12-15 12:02:10
【问题描述】:

我在使用 codeigniter 路由时遇到了麻烦,

我需要这样做:

method/:any = method/index_function
method/edit/:any = method/edit_function

我在路由配置文件中写了这个:

$route['method/:any'] = 'method/index';
$route['method/edit/:any'] = 'method/edit';

但不想要作品。

有什么建议吗?


解决!

我在路由文件中改变了行的顺序:

 $route['method/edit/:any'] = 'method/edit';
 $route['method/:any'] = 'method/index';

感谢巴舍尔·艾哈迈德

【问题讨论】:

  • method/:any = method/index_function method/edit/:any = method/edit_function
  • 试试我的更新答案

标签: php codeigniter routes


【解决方案1】:

路由将按照它们定义的顺序运行。较高的路线总是优先于较低的路线。 Codeigniter Routes

$route['method/edit/(:any)'] = 'controller/edit';
$route['method/(:any)'] = 'controller/index'; 

【讨论】:

  • 我在我的配置文件中写道: $route['dog/:any'] = 'dog/index'; $route['dog/edit/any'] = 'dog/edit';但不起作用
  • 尝试在any周围使用圆括号,然后尝试
  • 尝试dog/1时会发生什么
  • 如果我的用户 dog/1 可以工作,但如果我尝试使用 dog/edit/1,则会出现 404 错误
  • 谢谢!其作品!问题是行的顺序!
【解决方案2】:

如果我没记错的话,你的路由键不能与现有控制器同名,因为 CodeIgniter 会首先检查控制器,如果找到,它会尝试调用该控制器中的方法。请尝试:

$route['m/:any'] = 'method/index';
$route['m/edit/:any'] = 'method/edit';

【讨论】:

  • 我在我的配置文件中写道: $route['dog/:any'] = 'dog/index'; $route['dog/edit/any'] = 'dog/edit';但不起作用
  • 你能用你的意思定义“它不起作用”吗?您收到错误消息吗?如果没有,您是否将 error_reporting 设置为 E_ALL 并打开了 display_errors?我不太确定,但尝试将 :any 包含在(括号)中
  • 我遇到了 404 错误!我尝试添加括号,但没有!
【解决方案3】:

你基本上忘了应用括号。 Codeigniter 路由真的很好用。这是我如何在项目中实现相同目标的示例:

$route['listnote/stepone/(:any)']='listnote/listnote/loanInformation';

【讨论】:

  • 这些() 不是括号,而是括号.. :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-16
  • 2013-04-06
  • 1970-01-01
  • 1970-01-01
  • 2016-01-03
  • 1970-01-01
相关资源
最近更新 更多