我来自codeigniter,并试图将我的头脑围绕在路由上。我正在关注 http://codehappy.daylerees.com/using-controllers教程
如果您向下滚动到 RESTful 控制器,Dayle 谈到 Home_Controller 扩展了 base_controller 并添加了公共函数 get_index() 和 post_index()。我已经复制了代码,但是当我去
http://localhost/m1/public/account/superwelcome/Dayle/Wales
我得到:
我们走错了方向。服务器错误:404(未找到)。
有什么明显的我做错了吗?我应该把代码放在别的地方吗?这是我的代码
class Base_Controller extends Controller {
/**
* Catch-all method for requests that can't be matched.
*
* @param string $method
* @param array $parameters
* @return Response
*/
public function __call($method, $parameters)
{
return Response::error('404');
}
public $restful = true;
public function get_index()
{
//
}
public function post_index()
{
//
}
}
在 routes.php 文件中,我有:
// application/routes.php
Route::get('superwelcome/(:any)/(:any)', 'account@welcome');
我的帐户控制器(来自教程)是:
// application/controllers/account.php
class Account_Controller extends Base_Controller
{
public function action_index()
{
echo "This is the profile page.";
}
public function action_login()
{
echo "This is the login form.";
}
public function action_logout()
{
echo "This is the logout action.";
}
public function action_welcome($name, $place)
{
$data = array(
'name' => $name,
'place' => $place
);
return View::make('welcome', $data);
}
}