从昨天开始,我一直在尝试查看在 4.0.6 中工作的 Laravel 作曲家,但都击中了头部,我不知道该怎么想。
我遵循了 Laravel Brazil 的教程:Controllers with clean View Composer ( http://www.laravel.com.br/controllers-mais-limpos-com-view-composers/ )
你能帮助我吗?遵循以下所有代码(或部分代码):
作曲家.json
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/macros",
"app/services",
"app/libraries",
"app/viewComposers",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
应用程序/作曲家.php
<?php
View::composer('layouts.default', 'CategoryComposer');
应用程序/viewComposers/CategoryComposer.php
<?php
class CategoryComposer {
/**
* compose method
* Busca as categorias para a sidebar do front-end
*
* @access public
* @param Array $view
* @return Category
* @since 1.0
* @version 1.0
* @author Patrick Maciel
*/
public static function compose($view)
{
$categories = Category::getActive(false);
$view->with('categories', $categories);
}
}
应用程序/控制器/ProductsController.php
/**
* Display a listing of the resource.
*
* @return Response
*/
public function getIndex()
{
$products = Product::getActive(false, false);
return View::make('products.index')
->with('title', 'Produtos')
->with('products', $products);
}
应用程序/模型/Product.php
/**
* getActive method
* Obtém a lista de grupos ativos
*
* @access public
* @return Array
* @since 1.0
* @version 1.0
* @author Patrick Maciel
*/
public static function getActive($optional = true, $list = true)
{
if ($optional AND $list) {
return array('' => 'Selecione (opcional)') + static::active()->lists('name', 'id');
} else if (!$optional AND $list) {
return static::active()->lists('name', 'id');
} else if (!$optional AND !$list) {
return static::active()->get();
}
}
应用程序/视图/产品/index.blade.php
@foreach ($categories as $category)
<li class='categoria_produto'>
<a href="{{ URL::to('/categoria/' . $category->id . '/' . Str::slug($category->name, '-')) }}" title="{{ $category->name }}">{{ $category->name }}</a>
</li>
@endforeach
错误