在CodeIgniter中找不到控制器?
首页链接:在CodeIgniter中找不到控制器?
<a href="view_pre_read/?tid=22">Click here to go</a>
路由代码:
$route['view_pre_read/(:any)'] = 'view_pre_read/$1';
$route['view_pre_read'] = 'view_pre_read';
和我的控制器:
class View_pre_read extends CI_Controller {
function index(){
$tid=$_REQUEST['tid'];
$this->load->view('pages/notopic',$data);
}
}
但它总是要叫404错误页面;
请任何人帮我如何克服这一点 在此先感谢。
只要确保您的控制器文件名是否正确。
这看起来更像一条评论! – goseo 2014-09-24 07:32:41
@AfghanWiz:我无法评论bcoz,我的荣誉少于50。 – 2014-09-24 07:34:14
你现在有+50的代表。我认为这应该是一个评论。 – 2014-09-26 02:40:50
首先从文档的:
(:num) will match a segment containing only numbers.
(:any) will match a segment containing any character.
那么,为什么不是在你的情况下使用(:num)
?
在您的控制器中,您必须通过在您的方法参数中添加值来检索tid
的值。我猜想缺少的参数会导致缺失的路线。此外,我不认为使用$_REQUEST
是个好主意。我猜CI实现了一些函数来获取$_REQUEST
的参数。
class View_pre_read extends CI_Controller {
function index($tid) { // Add the $tid here
echo $tid; //print 22
//$tid=$_REQUEST['tid'];
$this->load->view('pages/notopic',$data);
}
}
编辑:
我没听长时间看你的路线......也许你应该添加你调用哪个方法。
$route['view_pre_read/(:num)'] = "view_pre_read/index/$1";
将导致http://yourwebsite.com/view_pre_read/index/22
。
链接是:click here to go – 2014-09-25 05:39:36
class View_pre_read extends CI_Controller { function index($ tid){//在这里添加$ tid echo $ tid; // print 22 // $ tid = $ _ REQUEST ['tid']; $ this-> load-> view('pages/notopic',$ data); } } – 2014-09-25 05:42:27
在链接中使用base_url() – 2014-09-25 06:04:57