0

我是 laravel 的新手,几天前用它开始了一个项目。我让作曲家在没有 git 的情况下运行,它工作“没问题”。昨天我尝试安装包felixkiss/uniquewith-validator,安装过程没有问题,但新选项没有实现。完全更新作曲家后,整个应用程序不再工作,我收到一个错误,指出该方法redirectIfTrailingSlash()未定义。但这只是“前传”,不知道对后面是否重要。

再次阅读一些指南后,我突然意识到我使用了错误的 laravel 包!我用laravel/framework的不是正确的包laravel/laravel。此时我备份了我损坏的应用程序,并决定用 composer 安装正确的包,不使用 git 总是很头疼我也决定安装 git。所以我laravel/framework从依赖项中删除了包并添加了laravel/laravel.

令人惊讶的是,一切运行良好,我的文件也很好,唯一的问题是我所有的控制器都坏了。我收到错误消息:

找不到控制器方法。

我试过了:

  • composer dump-autoload
  • composer update
  • php artisan dump-autoload(Artisan 刚刚安装了新包)

更新:

经过进一步调查:问题不直接出在旧控制器上,而是调用了引发错误的父方法。这是我的日历控制器:

class CalendarController extends BaseController {

    protected $layout = 'layouts.master';

    public function __construct()
    {
        //this is a method of BaseController, if I comment out the line, it works fine
        $this->getDays();
    }

    public function init()
    {
        $this->layout->title = 'Start';
        $this->layout->key = 'calendar';
        usort($this->viewData['days'],array($this,'sortDays'));
        $this->getCalendarView();
    }

    private function sortDays($a,$b)
    {
        return $a->teaser_index > $b->teaser_index;
    }

    private function getCalendarView()
    {
        $this->layout->content = View::make('layouts.calendar', $this->viewData);
    }
} 

但是,即使我将方法内的所有内容都getDays()注释掉,错误仍然会抛出,所以由于某种原因我不能再调用父方法了。

另一个更新

我用getDays()方法替换了方法hello()。这是基本控制器(getDays()暂时被删除):

class BaseController extends Controller {

    var $viewData = array();


    /**
     * Setup the layout used by the controller.
     *
     * @return void
     */


    protected function setupLayout()
    {
        if ( ! is_null($this->layout))
        {
            $this->layout = View::make($this->layout);
        }
    }

    public function hello()
    {
        return 'hello';
    }

}   

这是现在的控制器(hello()现在在init()通过路由调用的方法中):

class CalendarController extends BaseController {

    protected $layout = 'layouts.master';

    public function __construct()
    {
        //this is a method of BaseController, if I comment out the line, it works fine
        //$this->getDays();
    }

    public function init()
    {

        $this->layout->title = 'Start';
        $this->layout->key = 'calendar';
        //usort($this->viewData['days'],array($this,'sortDays'));
        //$this->getCalendarView();
        echo $this->hello();
    }

    private function sortDays($a,$b)
    {
        return $a->teaser_index > $b->teaser_index;
    }

    private function getCalendarView()
    {
        $this->layout->content = View::make('layouts.calendar', $this->viewData);
    }
}
4

0 回答 0