本文整理汇总了PHP中yii\helpers\Inflector::camel2id方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::camel2id方法的具体用法?PHP Inflector::camel2id怎么用?PHP Inflector::camel2id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Inflector
的用法示例。
在下文中一共展示了Inflector::camel2id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getViewPath
/**
* Find view paths in application folder.
*
* {@inheritDoc}
*
* @see \yii\base\Widget::getViewPath()
* @return string
*/
public function getViewPath()
{
// get reflection
$class = new ReflectionClass($this);
// get path with alias
return '@app/views/widgets/' . Inflector::camel2id($class->getShortName());
}
示例2: renderDataCellContent
protected function renderDataCellContent($model, $key, $index)
{
if ($this->count) {
$count = call_user_func($this->count, $model, $key, $index, $this);
// Deprecated: use `self::$count`
} elseif ($this->countField) {
$count = $model->{$this->countField};
} elseif ($this->modelClass) {
$childModelClass = $this->modelClass;
$count = $childModelClass::find()->where([$this->modelField => $key])->permission()->count();
} else {
throw new Exception("Count is empty");
}
if (empty($count) && !$this->showEmpty) {
return '';
}
$content = Html::tag('span', $count, ['class' => 'badge']);
// Deprecated: Use `DataColumn::$link`
if ($this->needUrl && $this->modelClass && $this->modelField) {
// need url
$childModel = new $childModelClass();
if (empty($this->urlPath)) {
$this->urlPath = Inflector::camel2id($childModel->formName()) . '/index';
}
if (empty($this->searchFieldName)) {
$this->searchFieldName = $this->modelField;
if ($this->dirtyUrl) {
$this->searchFieldName = $childModel->formName() . 'Search[' . $this->modelField . ']';
}
}
$url = Url::to([$this->urlPath, $this->searchFieldName => $key]);
return Html::a($content, $url);
}
return $this->dataCellContentWrapper($content, $model);
}
示例3: bOrderAttr
public static function bOrderAttr()
{
if (is_null(static::$b_order_attr)) {
static::$b_order_attr = Inflector::camel2id(StringHelper::basename(static::bClass()), '_') . '_ord';
}
return static::$b_order_attr;
}
示例4: tableName
/**
* @inheritdoc
*/
public static function tableName()
{
$name = Inflector::camel2id(StringHelper::basename(get_called_class()), '_');
$length = mb_strlen($name, \Yii::$app->charset) - 7;
// - mb_strlen('_record', Yii::$app->charset);
return '{{%' . trim(mb_substr($name, 0, $length, \Yii::$app->charset)) . '}}';
}
示例5: getLink
/**
* @param $class
* @param $id
* @param array $options
* @return string
*/
public static function getLink($class, $id, $options = [])
{
list($app, $module, $moduleName, $model, $modelName) = explode('\\', $class);
list($modulePath, $modelPath) = [Inflector::camel2id($moduleName), Inflector::camel2id($modelName)];
$modelName = $modulePath == $modelPath || $modelPath == 'item' ? $moduleName : "{$moduleName} {$modelName}";
return $id ? Html::a("{$modelName}#{$id}", ["/{$modulePath}/{$modelPath}/view", 'id' => $id], $options) : Html::a("{$modelName}", ["/{$modulePath}/{$modelPath}/index"], $options);
}
示例6: getRoute
/**
* @return string
*/
protected function getRoute()
{
if (Yii::$app->requestedAction) {
return \yii\helpers\Inflector::camel2id(Yii::$app->requestedAction->getUniqueId());
}
return Yii::$app->requestedRoute;
}
示例7: actionIndex
public function actionIndex()
{
$actions = [];
$rc = new \ReflectionClass($this);
$publicMethods = $rc->getMethods(\ReflectionMethod::IS_PUBLIC);
$availableActions = [];
foreach ($publicMethods as $publicMethod) {
$methodName = $publicMethod->name;
if ($methodName == 'actions') {
continue;
}
if (StringHelper::startsWith($methodName, 'action')) {
$availableActions[] = $methodName;
}
}
if (count($this->actions()) > 0) {
$availableActions = $availableActions + array_keys($this->actions());
}
$menus = [];
foreach ($availableActions as $actionName) {
$routeId = Inflector::camel2id(substr($actionName, strlen('action')));
$menus[] = Html::a($actionName, [$routeId]);
}
echo implode('<br/>', $menus);
}
示例8: testCamel2id
public function testCamel2id()
{
$this->assertEquals('post-tag', Inflector::camel2id('PostTag'));
$this->assertEquals('post_tag', Inflector::camel2id('PostTag', '_'));
$this->assertEquals('post-tag', Inflector::camel2id('postTag'));
$this->assertEquals('post_tag', Inflector::camel2id('postTag', '_'));
}
示例9: actionRoute
public function actionRoute()
{
Yii::$app->response->format = 'json';
$controllerlist = [];
$name = Yii::getAlias('@app');
$pos = strrpos($_GET['title'], '\\');
$class = substr(substr($_GET['title'], $pos + 0), 0, -10);
$nameController = Inflector::camel2id($class);
if ($views = opendir($name . '/views/' . $nameController)) {
while (false !== ($file = readdir($views))) {
$viewlist[] = $file;
}
closedir($views);
}
$fulllist = [];
$handle = fopen($name . '/controllers/' . $_GET['title'] . ".php", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
if (preg_match('/public function action(.*?)\\(/', $line, $display)) {
if (strlen($display[1]) > 2) {
$actionname = Inflector::camel2id($display[1]);
$nameController = Inflector::camel2id($class);
$fulllist['url'][strtolower($nameController . '/' . $actionname)][] = strtolower($nameController . '/' . $actionname);
}
}
}
}
fclose($handle);
return $fulllist;
}
示例10: run
public function run()
{
$controllerId = Inflector::camel2id($this->itemClass);
$translatedWordItems = $this->itemClass == 'Page' ? \Yii::t('back', 'pages') : \Yii::t('back', 'articles');
$translatedWordItems2 = $this->itemClass == 'Page' ? \Yii::t('back', 'of pages') : \Yii::t('back', 'of articles');
$contentType = $this->itemClass == 'Page' ? ContentRecord::TYPE_PAGE : ContentRecord::TYPE_ARTICLE;
return $this->render('recentContent', ['items' => $this->_items, 'controllerId' => $controllerId, 'translatedWordItems' => $translatedWordItems, 'translatedWordItems2' => $translatedWordItems2, 'contentType' => $contentType]);
}
示例11: idAttr
protected function idAttr()
{
if (is_null($this->pivotIdAttr)) {
$owner = $this->owner;
$this->pivotIdAttr = Inflector::camel2id(StringHelper::basename($owner->className()), '_') . '_id';
}
return $this->pivotIdAttr;
}
示例12: getFilenameFor
/**
* @param ActiveRecord $activeRecord
* @param $attribute
* @param null $extension
*
* @return string
*/
public function getFilenameFor($activeRecord, $attribute, $extension = null)
{
$path = Inflector::camel2id((new \ReflectionClass($activeRecord))->getShortName());
$basename = implode('-', $activeRecord->getPrimaryKey(true)) . '-' . $attribute;
if ($extension) {
$basename .= '.' . $extension;
}
return $path . DIRECTORY_SEPARATOR . $basename;
}
示例13: getControllers
/**
* @param Module $module
*
* @return array
*/
public function getControllers($module)
{
$files = FileHelper::findFiles($module->controllerPath, ['only' => ['*Controller.php']]);
return ArrayHelper::getColumn($files, function ($file) use($module) {
$class = pathinfo($file, PATHINFO_FILENAME);
$route = Inflector::camel2id($class = substr($class, 0, strlen($class) - strlen('Controller')));
return new ControllerModel(['route' => $module->uniqueId . '/' . $route, 'label' => Inflector::camel2words($class)]);
});
}
示例14: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!isset($this->counterOwner) || !is_array($this->counterOwner) && !is_object($this->counterOwner)) {
throw new InvalidConfigException('counterOwner must be configured as array or object');
}
if (!isset($this->counterParam)) {
$this->counterParam = Inflector::camel2id(StringHelper::basename(get_class($this->counterOwner))) . '_count';
}
}
示例15: init
/**
* Initialize attributes
*
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
if (!$this->model) {
throw new InvalidConfigException('Model is missing');
}
$this->_modelName = $this->model instanceof ActiveRecord ? Inflector::camel2id(StringHelper::basename(get_class($this->model))) : $this->model;
if (!$this->storageId) {
$this->storageId = $this->_modelName;
}
}