camel2id() public static method

Words in the ID may be concatenated using the specified character (defaults to '-'). For example, 'PostTag' will be converted to 'post-tag'.
public static camel2id ( string $name, string $separator = '-', boolean | string $strict = false ) : string
$name string the string to be converted
$separator string the character used to concatenate the words in the ID
$strict boolean | string whether to insert a separator between two consecutive uppercase chars, defaults to false
return string the resulting ID
Beispiel #1
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, '/');
 }
 /**
  * 添加操作
  * @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]);
 }
<?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 
}