我是laravel的新手,只是尝试了一些例子。这是:
laravel-master\app\controllers\account.php -
class AccountController extends BaseController
{
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.";
}
}
然后我在 - laravel-master\app\routes.php
Route::controller('account');
所以我什么时候会去主页
但显示
Missing argument 2 for Illuminate\Routing\Router::controller(), called in C:\Program Files\Zend\Apache2\htdocs\laravel-master\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 177 and defined
。不知道是什么问题。我错了吗?
答案 0 :(得分:7)
将控制器文件的名称更改为:
laravel-master\app\controllers\AccountController.php
将路线定义更改为:
Route::controller('account', 'AccountController');
将控制器方法更改为:
class AccountController extends BaseController
{
public function getIndex()
{
echo "This is the profile page.";
}
public function getLogin()
{
echo "This is the login form.";
}
public function getLogout()
{
echo "This is the logout action.";
}
}
答案 1 :(得分:1)
不是Laravel专家,但我认为你的Route::controller
缺少路由目的地的参数,你应该使用控制器类的全名。尝试
Route::controller('account', 'AccountController')
我也不确定action_
。如果我正确理解documentation on controllers,它们必须以HTTP动词作为前缀,例如
public function getIndex()
而不是
public function action_index()