ps24love / widget
此软件包最新版本(dev-master)没有可用的许可证信息。
laravel4 小部件系统
dev-master
2014-05-19 07:59 UTC
Requires
- php: >=5.3.0
- illuminate/support: 4.1.*
This package is not auto-updated.
Last update: 2024-09-24 06:21:31 UTC
README
为Laravel 4创建精彩特性的简单小部件系统
安装
打开您的composer.json文件,并添加新的必需软件包。
"Ps24love/widget": "dev-master"
接下来,打开终端并运行。
composer update
在composer更新后,在app/config/app.php中添加新的服务提供者和别名。
'Ps24love\Widget\WidgetServiceProvider'
'Widget' => 'Ps24love\Widget\Facades\Widget'
完成。
示例
注册您的widget
要注册您的widget,只需在您的app文件夹中创建一个名为widgets.php
的文件,并将您的widget代码放入该文件中。如下所示。
laravel/
|-- app/
|-- commands/
...
|-- views/
|-- filters.php
|-- routes.php
|-- widgets.php
|-- bootstrap/
|-- vendor/
简单Widget
Widget::register('awesome', function(){ return View::make('awesome'); });
带有一个或多个参数的Widget
Widget::register('hello', function($name){ return "Hello, $name !"; }); Widget::register('box', function($title, $description){ return View::make('widgets.box', compact('title', 'description')); });
将之前已定义的widget分组。
// First, you must registering one or more widget Widget::register('categories', function(){ return View::make('widgets.categories'); }); Widget::register('latestPost', function(){ return View::make('widgets.latestPost'); }); // Next, you can group some widgets like this: Widget::group('sidebar', array('categories', 'latestPost')); Widget::group('footer', array('hello', 'box'));
调用您的widget
全局调用widget,如下所示
Widget::awesome(); Widget::hello('John'); Widget::box('Latest News', 'This is a description of latest news'); // calling widget group just like below // Widget::$name(); Widget::sidebar(); // calling widget group which parameters just like below // Widget::$name($params1, $params2, $params3, ....); Widget::box(array('name'), array('My Tweets', '.....Latest Tweets'));
在视图中简单调用widget
@awesome @hello('John') //calling group widget @sidebar() @box(array('name'), array('My Tweets', '.....Latest Tweets'))
许可证
此软件包是开源软件,许可协议为MIT许可证