也许有人可以告诉我如何在symfony2中使用类似嵌入式控制器的东西来调用Laravel4,5中的\ render controller动作?
答案 0 :(得分:0)
找到最适合我的方式,对于L5:
<强> CartServerProvider 强>
use Illuminate\Support\ServiceProvider;
class CartServiceProvider extends ServiceProvider {
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->make('view')->composer('layouts.master', 'Vendor\Cart\Http\ViewComposers\CartComposer');
}
}
CartComposer 类如下所示:
use Illuminate\Contracts\View\View;
class CartComposer {
/**
* Cart manager instance.
*
* @var \Vendor\Cart\StoreInterface
*/
protected $cart;
/**
* Create a new CartComposer instance.
*/
public function __construct()
{
$this->cart = app()->make('cart.store');
}
/**
* Compose the view.
*
* @return void
*/
public function compose(View $view)
{
$view->with('cart', $this->cart);
}
}
cart.store 是我注入容器的自定义购物车实现,但上面应该足以向您展示如何注册一个简单的视图编辑器。