yidas / yii2-helpers
Yii Framework 2.0 的实用助手集合
1.2.2
2017-08-09 04:00 UTC
README
Yii2 Helpers
Yii Framework 2.0 的实用助手集合
助手
安装
通过 composer 命令安装
$ php composer.phar require yidas/yii2-helpers
或者,在 yii2 的 composer.json
中,手动添加 yidas/yii2-helpers 作为依赖。
"require": {
...
"yidas/yii2-helpers": "*"
},
文档
路由
使用方法:(假设当前控制器路由为 'site/index')
Route::in('site'); // True for site/* Route::is('site/index'); // True for site/index Route::get(); // Get such as 'site/index' Route::getByLevel(1); // Get 'site' from 'site/index' // Root Level usage for filtering prefix from route Route::setRootLevel(1); // Set the rootLevel to 1 Route::get(); // Get 'index' from 'site/index' Route::setRootLevel(); // Get the rootLevel back to 0 Route::get(); // Get 'site/index' from 'site/index'
视图中的示例
<ul class="sidebar-menu"> <li class="<?php if(Route::in('site')):?>active<?php endif ?> treeview"> <a href="#">SITE MENU</a> <ul class="treeview-menu"> <li class="<?php if(Route::is('site/index')):?>active<?php endif ?>"><a href="<?=Url::to(['site/index'])?>">Menu List</a></li> <li class="<?php if(Route::is('site/create')):?>active<?php endif ?>"><a href="<?=Url::to(['site/create'])?>">Add One</a></li> </ul> </li> </ul>
RouteJS
使用 JavaScript 弹出窗口重定向到控制器中的路由
public function actionStore() { // Code... return RouteJS::redirect(['index', 'status'=>'1'], 'Stroed success!'); }
使用 JavaScript 弹出窗口在控制器中返回上一页
public function actionStore() { // Code... return RouteJS::goBack('Stroed failed! Return back.'); }