【发布时间】:2013-09-13 00:27:49
【问题描述】:
从昨天开始,我一直在尝试查看在 4.0.6 中工作的 Laravel 作曲家,但都撞到了头,我不知道该怎么想。
我学习了 Laravel Brazil 的教程:Controllers with clean View Composer (http://www.laravel.com.br/controllers-mais-limpos-com-view-composers/)
你能帮帮我吗? 遵循以下所有代码(或部分代码):
composer.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"
]
},
app/composers.php
<?php
View::composer('layouts.default', 'CategoryComposer');
app/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);
}
}
app/controllers/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);
}
app/models/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();
}
}
app/views/products/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
错误
【问题讨论】:
-
什么?我在您的评论中没有看到任何内容
-
这是一个链接,是文本本身。
-
我昨天看到了这个链接。对不起,对我没有帮助:(
-
你应该使用命名空间......它会让你免于以后的头痛。