【问题标题】:Laravel controller doesn't existLaravel 控制器不存在
【发布时间】:2014-11-11 19:29:31
【问题描述】:

好的,我已经有一段时间没有遇到这个问题了,但我已经尽我所能解决这个问题并阅读了其他人的帖子。我现在很迷茫。

创建控制器后,我执行了“php ./composer.phar dump-autoload”命令,说生成成功,还是说控制器不存在。它所在的文件夹中已经有 3 个其他控制器,并且每个都有效,只是这个控制器有问题。

控制器代码:(/apps/controllers/api/apiBulkController.php)

class apiBulkController extends BaseController {

private $error;

public function __construct()
{
    // Set default values
    $this->error = 'false';
}

public function create()
{
    $bulk = array();

    // Authenticate the user using the api
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
        $this->authenticate();

    } else {

        $auth = User::where('username', $_SERVER['PHP_AUTH_USER'])->first();

        // Check to see if the user is valid
        if(isset($auth->authkey) && $auth->authkey == $_SERVER['PHP_AUTH_PW'])
        {
            $req = Request::get();

            $bulk = new Bulk;
            // Add Columns by example below
            $bulk->save();

            //ex. $Bulk->Name = Request::get('');  $object->column_name = Request;

            // Return JSON data
            return Response::json(array(
                'error' => $this->error
            ));

        }
        else
        {
            echo $_SERVER['PHP_AUTH_USER'].": Your hash seems to be incorrect.";
        }
    }
}

public function authenticate()
{
    header('WWW-Authenticate: Basic realm="User Authentication (Username / Hash)"');
    header('HTTP/1.0 401 Unauthorized');
    echo "You must enter a valid Login ID and Hash to access this resource\n";
    exit;
}

}

【问题讨论】:

    标签: php laravel laravel-4 controller namespaces


    【解决方案1】:

    你应该添加

    namespace api;
    

    在控制器的开头

    并在类名之前使用您的命名空间运行控制器,例如在路由 api\apiBulkController@create 而不是 apiBulkController@create

    如果错误发生变化,您应该更改您的类,将命名空间或用途添加到其他类,例如 extends BaseController 应该是 extends \BaseController 等等

    【讨论】:

    • 谢谢,成功了。我不会抓住那个。
    猜你喜欢
    • 2015-04-20
    • 2019-03-26
    • 2018-07-15
    • 1970-01-01
    • 2019-02-05
    • 2015-05-23
    • 2020-07-07
    • 2017-09-20
    • 2015-04-21
    相关资源
    最近更新 更多