Laravel 尝试创建第一个包,但获取未定义的方法callAction()异常
我正在尝试开发一个包,所以我一直遵循创建一个Facade部分,因为我不需要Facade 问题是:Laravel 尝试创建第一个包,但获取未定义的方法callAction()异常,laravel,laravel-4,composer-php,Laravel,Laravel 4,Composer Php,我正在尝试开发一个包,所以我一直遵循创建一个Facade部分,因为我不需要Facade 问题是: /app/routes.php Route::get('test', 'Aristona\Installer\Installer@install'); 引发异常:调用未定义的方法Aristona\Installer\Installer::callAction() 我的Installer.php如下所示: workbench/aristona/installer/src/Aristona/Insta
/app/routes.php
Route::get('test', 'Aristona\Installer\Installer@install');
引发异常:调用未定义的方法Aristona\Installer\Installer::callAction()
我的Installer.php
如下所示:
workbench/aristona/installer/src/Aristona/Installer/Installer.php
<?php namespace Aristona\Installer;
class Installer
{
public static function install()
{
return "Hello";
}
}
workbench/aristona/installer/src/aristona/installer/installer.php
您将收到一个错误,因为您正在尝试使用路由到不存在的控制器。更具体地说,Laravel正试图从其核心控制器类执行此方法:
/**
* Execute an action on the controller.
*
* @param string $method
* @param array $parameters
* @return \Symfony\Component\HttpFoundation\Response
*/
public function callAction($method, $parameters)
{
$this->setupLayout();
$response = call_user_func_array(array($this, $method), $parameters);
// If no response is returned from the controller action and a layout is being
// used we will assume we want to just return the layout view as any nested
// views were probably bound on this view during this controller actions.
if (is_null($response) && ! is_null($this->layout))
{
$response = $this->layout;
}
return $response;
}
因此,除非您在Route::get()
中指定的类正在扩展BaseController或Controller,否则将引发此异常。如果您在闭包中测试相同的方法,它将起作用
有关Laravel控制器路由的更多信息,请参见
要解决此问题,您应该向包中添加一个控制器,或者在另一个控制器中使用Installer类