public function register() { $this->app->singleton('tee.siteIdentifier', function () { return new SiteIdentifier(); }); // registra os macros e helpers require_once __DIR__ . '/macros/html.php'; require_once __DIR__ . '/macros/form.php'; App::register('YAAP\\Theme\\ThemeServiceProvider'); App::register('Lavary\\Menu\\ServiceProvider'); App::register('Creitive\\Breadcrumbs\\BreadcrumbsServiceProvider'); App::register('Roumen\\Asset\\AssetServiceProvider'); App::register('Pingpong\\Widget\\WidgetServiceProvider'); App::register('Greggilbert\\Recaptcha\\RecaptchaServiceProvider'); class_alias('Pingpong\\Widget\\Facades\\Widget', 'Tee\\System\\Widget'); class_alias('YAAP\\Theme\\Facades\\Theme', 'Tee\\System\\Theme'); class_alias('Lavary\\Menu\\Facade', 'Tee\\System\\Menu'); class_alias('Creitive\\Breadcrumbs\\Facades\\Breadcrumbs', 'Tee\\System\\Breadcrumbs'); class_alias('Roumen\\Asset\\Asset', 'Tee\\System\\Asset'); class_alias('Tee\\System\\Facades\\SiteIdentifier', 'SiteIdentifier'); // registra os widgets Widget::register('errorList', __NAMESPACE__ . '\\Widgets\\ErrorList'); }
<?php /** * 自动引入每个模型的挂件文件 * tangbing <*****@*****.**> * 2015/10/14 16:20 */ if (getModuleInfo()) { $widgets_dir = getModuleInfo()->getPath() . '/Widgets'; if (is_dir($widgets_dir)) { $dir = dir($widgets_dir); while ($file = $dir->read()) { if (in_array($file, ['.', '..']) || substr($file, '-3', '3') != 'php' || !is_file($widgets_dir . '/' . $file)) { continue; } include $widgets_dir . '/' . $file; } } } /* * DEMO 部分 * 文档地址:http://sky.pingpong-labs.com/docs/2.0/widget */ Widget::register('demo', function ($contents) { return "<h1>{$contents}</h1>"; });
<?php /* |-------------------------------------------------------------------------- | Application Widget |-------------------------------------------------------------------------- | | Here you may also register your custom widget. | */ Widget::register('app', 'AppWidget');
}); Widget::register('datalist', function ($model, $view, $filter = [], $skip = 0, $limit = 10, $fields = [], $with = '', $with_filter = []) { $model = new $model(); if ($with) { if (is_array($with_filter) && !empty($with_filter)) { $data = $model->select($fields)->where(function ($query) use($filter) { foreach ($filter as $v) { $query->where($v[0], $v[1], $v[2]); } })->skip($skip)->take($limit)->with(array($with => function ($query) use($with_filter) { foreach ($with_filter as $key => $val) { $query->{$key}($val); } }))->get()->toArray(); } else { $data = $model->select($fields)->where(function ($query) use($filter) { foreach ($filter as $v) { $query->where($v[0], $v[1], $v[2]); } })->skip($skip)->take($limit)->with($with)->get()->toArray(); } } else { $data = $model->select('id')->where(function ($query) use($filter) { foreach ($filter as $v) { $query->where($v[0], $v[1], $v[2]); } })->skip($skip)->take($limit)->get()->toArray(); } //dd($data); return View::make($view, compact('data'))->render(); });
use App\News; use App\Article; use App\Slider; // Виджет слайдера Widget::register('slider', function () { // Получение данных $data['slider'] = Slider::orderBy('order', 'ASC')->get(); // Отображение return view('marketing.widgets.slider', $data); }); // Виджет новостей в футере Widget::register('footer_latest_news', function () { // Получаем новости, которые должны быть на главной $data['news'] = News::whereIsOnMain(TRUE)->orderBy('created_at', 'DESC')->limit(3)->get(); // Отображаем return view('marketing.widgets.footer_latest_news', $data); }); // Виджет "О Компании" в футере Widget::register('footer_about', function () { // Получаем данные $data['text'] = Article::firstOrCreate(['type' => 'footer_about'])->full_text; // Отображаем return view('marketing.widgets.footer_about', $data); }); // Виджет "Зв'яжіться з нами" в футере Widget::register('footer_contacts', function () { // Получаем данные $data['text'] = Article::firstOrCreate(['type' => 'footer_contacts'])->full_text; // Отображаем return view('marketing.widgets.footer_contacts', $data); });
<?php namespace cms\Modules\Users; \Widget::register('count_users', 'cms\\Modules\\Users\\App\\Widgets\\CountUsers'); \Widget::register('export_users', 'cms\\Modules\\Users\\App\\Widgets\\ExportUsers'); \Widget::register('social_buttons', 'cms\\Modules\\Users\\App\\Widgets\\SocialButtons'); \Widget::register('profile_users', 'cms\\Modules\\Users\\App\\Widgets\\ProfileUsers');
<?php Widget::register('header', 'App\\Widgets\\HeaderWidget');