Do not use BaseInflector. Use Inflector instead.
Since: 2.0
Author: Antonio Ramirez (amigo.cobos@gmail.com)
Author: Alexander Makarov (sam@rmcreative.ru)
Example #1
0
 public function run()
 {
     $view = $this->getView();
     JsoneditorAsset::register($view);
     $editorName = BaseInflector::camelize($this->id) . 'Editor';
     $view->registerJs("var container = document.getElementById('" . $this->options['id'] . "');\n            var options = " . Json::encode($this->editorOptions) . ";\n            var json = " . $this->value . ";\n            " . $editorName . " = new JSONEditor(container, options, json);\n            jQuery('#" . $this->id . "').parents('form').eq(0).submit(function() {\n                jQuery('#" . $this->id . "').val(" . $editorName . ".getText());\n                return true;\n            });");
     echo Html::hiddenInput($this->name, $this->value, ['id' => $this->id]);
     echo Html::tag('div', '', $this->options);
 }
Example #2
0
 /**
  * On event callback
  */
 public function beforeAction($actionEvent)
 {
     $actionId = BaseInflector::camelize($actionEvent->action->id);
     $controllerId = BaseInflector::camelize($actionEvent->action->controller->id);
     $permissionName = "{$controllerId}.{$actionId}";
     $allowedActions = $actionEvent->action->controller->allowed();
     if (\Yii::$app->getUser()->isGuest && !in_array(strtolower($permissionName), array_map('strtolower', $allowedActions)) && \Yii::$app->getRequest()->url !== Url::to(\Yii::$app->getUser()->loginUrl)) {
         \Yii::$app->getResponse()->redirect(\Yii::$app->getUser()->loginUrl);
     }
     if (!Yii::$app->getUser()->isGuest && !in_array(strtolower($permissionName), array_map('strtolower', $allowedActions))) {
         if (!Yii::$app->user->can($permissionName)) {
             Yii::$app->getResponse()->redirect(Yii::$app->params['accessDeniedUrl']);
         }
     }
 }
Example #3
0
 /**
  * 添加操作
  * @return  [type] [description]
  * @version 1.0    2016-01-22T11:42:10+0800
  * @author zhangxianglong@yolo24.com
  */
 public function actionListAction()
 {
     $auth = Yii::$app->authManager;
     $dir = '../controllers/';
     $dh = opendir($dir);
     //循环读取文件
     while ($file = readdir($dh)) {
         if ($file != '.' && $file != '..' && $file != 'SiteController.php' && $file != 'BaseController.php' && strpos($file, '.php') !== false) {
             $fullpath = $dir . $file;
             //本文件不include
             if (!in_array($file, array('AuthItemController.php'))) {
                 include $fullpath;
             }
             $class_name = str_replace('.php', '', $file);
             $str = "backend\\controllers\\{$class_name}";
             $class_methods = get_class_methods($str);
             $file_content = file_get_contents($fullpath);
             $all_arr = explode("\n", $file_content);
             $model_name = trim(str_replace('//', '', $all_arr[1]));
             $route_name = str_replace('Controller', '', $class_name);
             $parent_item_name = BaseInflector::camel2id(Yii::$app->params['pre_auth_item'] . lcfirst($route_name));
             if (!$auth->getPermission($parent_item_name)) {
                 $operator_obj = $auth->createPermission($parent_item_name);
                 $operator_obj->description = $model_name;
                 $auth->add($operator_obj);
             }
             foreach ($class_methods as $name) {
                 if (strpos($name, 'action') === 0 && strlen($name) > 7) {
                     $route_controller_name = lcfirst(str_replace('action', '', $name));
                     $targetIndex = mb_strpos($file_content, 'public function ' . $name . '(', 0, 'utf-8');
                     #查找目标字符串的坐标
                     $pre_content = mb_substr($file_content, 0, $targetIndex, 'utf-8');
                     $explode = explode("\n", $pre_content);
                     $explode = array_reverse($explode);
                     $zhushi = '';
                     foreach ($explode as $key => $row) {
                         if (trim($row) == '/**') {
                             $zhushi = trim(str_replace('*', '', $explode[$key - 1]));
                             break;
                         }
                     }
                     if (mb_strlen($zhushi, 'utf-8') > 10) {
                         echo $file . $model_name . '_' . $name . '_' . $zhushi . '<br/>';
                     } else {
                         $child_name = BaseInflector::camel2id($parent_item_name . '/' . $route_controller_name);
                         if (!$auth->getPermission($child_name)) {
                             $operator_obj = $auth->createPermission($child_name);
                             $operator_obj->description = $zhushi;
                             $auth->add($operator_obj);
                             $auth->addChild($auth->getPermission($parent_item_name), $operator_obj);
                         }
                     }
                 }
             }
         }
     }
     return json_encode(['status' => 1]);
 }
Example #4
0
 /**
  * Retrieves i18n category for given key
  * ---
  * Finds i18n category based on config rule
  * or default category or model classname category
  * ---
  * @return string namespace
  */
 public function getI18nCategory($key = false)
 {
     if ($key) {
         $rules = ArrayHelper::getValue(self::$generator->messages, $key);
         foreach ($rules as $regex => $ns) {
             $pattern = static::sanitazeNsRegex($regex);
             if (preg_match('%' . $pattern . '%', self::basename($this->getClass(self::RK_MODEL_CM)), $matches)) {
                 return static::sanitazeI18n($ns, $matches);
             }
         }
     }
     if (self::$generator->messageCategory) {
         return self::$generator->messageCategory;
     }
     $basename = self::basename($this->getClass(self::RK_MODEL_CM));
     if (static::$generator->isDbView()) {
         $prefix = ucfirst(str_replace('_', '', static::$generator->dbViewPrefix));
         $basename = str_replace($prefix, '', $basename);
     }
     return \yii\helpers\BaseInflector::camel2id($basename, '/');
 }
<?php

/**
 * Created by PhpStorm.
 * User: karen
 * Date: 1/31/16
 * Time: 12:31 PM
 */
use yii\helpers\BaseInflector;
foreach ($lists as $key => $value) {
    ?>
    <h4><a href="/<?php 
    echo BaseInflector::camel2id($key);
    ?>
/index"><?php 
    echo implode('<br>', $value);
    ?>
</a></h4>
<?php 
}
 /**
  * Gets the source and returns a string. If a relation is defined adjusts the source in order
  * to match that url.
  *
  * Base source name is defined by the table name in the model
  *
  * @return string
  */
 public function getSource()
 {
     /* @var $modelClass ActiveRecord */
     $modelClass = $this->modelClass;
     $source = $modelClass::tableName();
     if (!empty($this->where['id'])) {
         $source = BaseInflector::singularize($source) . '/' . $this->where['id'];
         unset($this->where['id']);
     } else {
         if (!empty($this->link)) {
             $pre = '';
             foreach ($this->link as $key => $link) {
                 $pre .= "{$key}/{$link}";
             }
             $source = $pre . '/' . $source;
         }
     }
     return 'discovery/' . $source;
 }
 /**
  * @param WidgetsCrud $nextModel
  * @return string
  */
 public function generateWidgetActiveField($nextModel)
 {
     $controllerName = explode(' ', BaseInflector::camel2words(str_replace('Controller', '', StringHelper::basename($this->controllerClass))));
     $controller = '';
     $module = $this->moduleID ? "/{$this->moduleID}" : '';
     foreach ($controllerName as $item) {
         $controller .= (strlen($controller) ? '-' : '') . strtolower($item);
     }
     $nextModel->pathName = $nextModel->pathName ?: '_widgets';
     return str_replace(['{controller}', '{module}'], [$controller, $module], $this->render("views/{$nextModel->pathName}/_{$nextModel->widgetType}Input.php"));
 }