查看作曲家不发送var来查看

时间:2013-09-13 00:27:49

标签: php laravel

我从昨天开始尝试查看在4.0.6中工作的Laravel作曲家,但两人都打得很头,我不知道该怎么想。

我遵循了Laravel Brazil的教程:带有更清晰的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"
  ]
},

应用/ composers.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

ERRO Error generated when I try to access a variable sent by the view composer. - CategoryComposer

1 个答案:

答案 0 :(得分:0)

Brayan Rastelli(brayanrastelli),为我解决问题:

我更改部分的视图编辑器第一个参数(视图)(适用于任何视图,布局除外 - 我不知道为什么)。

View::composer('partials.category_navigation', 'CategoryComposer');

他们,我在composers.php(最后一行)中加入了filters.php

/* ----------------------------------------------------------------------------
| Extra files
| -----------------------------------------------------------------------------
|
| View Composers, etc
|
*/
require_once app_path() . '/composers.php';

而且,在我看来,我@include

@include('partials.category_navigation')

谢谢你们。