1

我已经辞职升级到 Laravel 4.1.x(composer.json为我安装的那种,所以我更新了 Antonio Carlos Ribeiro 提到的控制器别名),但现在有一个不同的问题:

编辑:在克隆了一个新的 Laravel 存储库后,我最终在 Adam Rivers 的帖子中进行了全新安装(在复制了我所拥有的小公共文件之后),现在它可以工作了。

    [2013-10-11 21:25:58] production.ERROR: exception 'ErrorException' with message 'Attempt to assign property of non-object' in /path/to/laravel/app/controllers/HomeController.php:22
Stack trace:
#0 /path/to/laravel/app/controllers/HomeController.php(22): Illuminate\Exception\Handler->handleError(2, 'Attempt to assi...', '/path/to/laravel...', 22, Array)
#1 [internal function]: HomeController->Index()
#2 /path/to/laravel/bootstrap/compiled.php(5574): call_user_func_array(Array, Array)
#3 /path/to/laravel/bootstrap/compiled.php(5562): Illuminate\Routing\ControllerDispatcher->call(Object(HomeController), Object(Illuminate\Routing\Route), 'Index')
#4 /path/to/laravel/bootstrap/compiled.php(4901): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'HomeController', 'Index')
#5 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#6 /path/to/laravel/bootstrap/compiled.php(5155): call_user_func_array(Object(Closure), Array)
#7 /path/to/laravel/bootstrap/compiled.php(4925): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#8 /path/to/laravel/bootstrap/compiled.php(4914): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#9 /path/to/laravel/bootstrap/compiled.php(548): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#10 /path/to/laravel/bootstrap/compiled.php(532): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#11 /path/to/laravel/public/index.php(49): Illuminate\Foundation\Application->run()
#12 {main} [] []

代码在哪里:

<?php

class HomeController extends BaseController {

    /*
    |--------------------------------------------------------------------------
    | Default Home Controller
    |--------------------------------------------------------------------------
    |
    | You may wish to use controllers instead of, or in addition to, Closure
    | based routes. That's great! Here is an example controller method to
    | get you started. To route to this controller, just add the route:
    |
    |   Route::get('/', 'HomeController@showWelcome');
    |
    */

    protected $layout = 'layouts.master';

    public function Index()
    {
        $this->layout->content = View::make('home'); //This is line 22
    }

}

我的BaseController

<?php

class BaseController extends Controller {

        /**
         * Setup the layout used by the controller.
         *
         * @return void
         */
        protected function setupLayout()
        {
                if ( ! is_null($this->layout))
                {
                        $this->layout = View::make($this->layout);
                }
        }

}

我的routes.php

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', 'HomeController@Index');

老问题:

我一直在 WAMP 上开发 Laravel 4.0.x,并将我的站点部署到我的 LEMP 堆栈。但是,我一直遇到这个错误:

[2013-10-09 01:20:00] log.ERROR: exception 'ReflectionException' with message 'Class filter.parser does not exist' in /path/to/laravel/bootstrap/compiled.php:165
Stack trace:
#0 /path/to/laravel/bootstrap/compiled.php(165): ReflectionClass->__construct('filter.parser')
#1 /path/to/laravel/bootstrap/compiled.php(142): Illuminate\Container\Container->build('filter.parser', Array)
#2 /path/to/laravel/bootstrap/compiled.php(442): Illuminate\Container\Container->make('filter.parser', Array)
#3 /path/to/laravel/bootstrap/compiled.php(233): Illuminate\Foundation\Application->make('filter.parser')
#4 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Routing/Controllers/Controller.php(104): Illuminate\Container\Container->offsetGet('filter.parser')
#5 /path/to/laravel/bootstrap/compiled.php(4755): Illuminate\Routing\Controllers\Controller->callAction(Object(Illuminate\Foundation\Application), Object(Illuminate\Routing\Router), 'Index', Array)
#6 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#7 /path/to/laravel/bootstrap/compiled.php(7824): call_user_func_array(Object(Closure), Array)
#8 /path/to/laravel/bootstrap/compiled.php(7811): Illuminate\Routing\Route->callCallable()
#9 /path/to/laravel/bootstrap/compiled.php(4766): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#10 /path/to/laravel/bootstrap/compiled.php(481): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#11 /path/to/laravel/bootstrap/compiled.php(470): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#12 /path/to/laravel/public/index.php(49): Illuminate\Foundation\Application->run()
#13 {main} [] []

当我删除我的路线时,基本上是

Route::get('/', 'HomeController@Index');

错误消息改为未找到。不确定这是否意味着什么,但我认为错误消息与路由有关。

我能想到的唯一区别是作曲家包(我什至尝试vendor直接复制文件夹)或 PHP 版本(5.4.12在 WAMP 上,5.4.19在 LEMP 上)。

我尝试用谷歌搜索类名,但我只找到了一个封闭的 github 问题的结果。谁能帮我找出问题所在?

作为参考,我使用的 Laravel 版本与 github 上的 master 分支相同 - https://github.com/laravel/laravel

删除后我更新的错误/path/to/laravel/bootstrap/compiled.php

 [2013-10-11 20:12:38] log.ERROR: exception 'ReflectionException' with message 'Class filter.parser does not exist' in /path/to/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:296
 Stack trace:
 #0 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(296): ReflectionClass->__construct('filter.parser')
 #1 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(238): Illuminate\Container\Container->build('filter.parser', Array)
 #2 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(425): Illuminate\Container\Container->make('filter.parser', Array)
 #3 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(468): Illuminate\Foundation\Application->make('filter.parser')
 #4 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Routing/Controllers/Controller.php(104): Illuminate\Container\Container->offsetGet('filter.parser')
 #5 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(985): Illuminate\Routing\Controllers\Controller->callAction(Object(Illuminate\Foundation\Application), Object(Illuminate\Routing\Router), 'Index', Array)
 #6 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
 #7 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(80): call_user_func_array(Object(Closure), Array)
 #8 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Routing/Route.php(47): Illuminate\Routing\Route->callCallable()
 #9 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1016): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
 #10 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(522): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
 #11 /path/to/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(497): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
 #12 /path/to/laravel/public/index.php(49): Illuminate\Foundation\Application->run()
 #13 {main} [] []

我对 Laravel 安装所做的明显更改:

在......的最后app/start/global.php

-require app_path().'/filters.php';
+require app_path().'/filters.php';
+
+ClassLoader::register(new ClassLoader(array(
+    app_path().'/libraries',
+)));
+
+App::bind('html', function() {
+    return new HTML;
+});
4

3 回答 3

3
  • 删除vendor目录和composer.lock.

  • 运行一个composer install --prefer-source.

  • 然后转到:https ://github.com/laravel/laravel/blob/master/app/config/app.php并将其复制到您的config/app.php.

  • 然后运行以下命令:php artisan key:generate.

  • 然后为了安全起见,运行:composer dump-autoload

你的新问题:

您的基本控制器似乎存在问题。确保您的基本控制器如下所示:

<?php

class BaseController extends Controller
{
    /**
     * Setup the layout used by the controller.
     *
     * @return void
     */
    protected function setupLayout()
    {
        if ( ! is_null($this->layout))
        {
            $this->layout = View::make($this->layout);
        }
    }
}
于 2013-10-11T12:25:51.250 回答
2

您是否从 4.1 移回 4.0?

您可能需要检查您的 app/config/app.php 是否有此服务提供商:

'Illuminate\Routing\ControllerServiceProvider',

正如亚当里弗斯所说,它可能不存在。

还要检查您的别名:

4.0

'Controller'      => 'Illuminate\Routing\Controllers\Controller',

4.1

'Controller'      => 'Illuminate\Routing\Controller',

编辑:

关于您的新问题,请检查您的 BaseController 是否至少如下所示:

<?php

class BaseController extends Controller {

    /**
     * Setup the layout used by the controller.
     *
     * @return void
     */
    protected function setupLayout()
    {
        if ( ! is_null($this->layout))
        {
            $this->layout = View::make($this->layout);
        }
    }

}
于 2013-10-11T12:56:04.127 回答
1

删除 bootstrap/ compiled.php文件。这可能会有所帮助。

于 2013-10-11T08:17:31.883 回答