當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Inflector::variablize方法代碼示例

本文整理匯總了PHP中yii\helpers\Inflector::variablize方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::variablize方法的具體用法?PHP Inflector::variablize怎麽用?PHP Inflector::variablize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\helpers\Inflector的用法示例。


在下文中一共展示了Inflector::variablize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * Constructor.
  * The default implementation does two things:
  *
  * - Initializes the object with the given configuration `$config`.
  * - Call [[init()]].
  *
  * If this method is overridden in a child class, it is recommended that
  *
  * - the last parameter of the constructor is a configuration array, like `$config` here.
  * - call the parent implementation at the end of the constructor.
  *
  * @param array $config name-value pairs that will be used to initialize the object properties
  */
 public function __construct($config = [])
 {
     if (!empty($config)) {
         foreach ($config as $name => $value) {
             $name = Inflector::variablize($name);
             $this->{$name} = $value;
         }
     }
 }
開發者ID:2amigos,項目名稱:yii2-packagist-component,代碼行數:23,代碼來源:Object.php

示例2: __construct

 /**
  * Constructor override. Required to transform the parameter names to variable names.
  *
  * From [[yii\base\Object]]:
  * The default implementation does two things:
  *
  * - Initializes the object with the given configuration `$config`.
  * - Call [[init()]].
  *
  * If this method is overridden in a child class, it is recommended that
  *
  * - the last parameter of the constructor is a configuration array, like `$config` here.
  * - call the parent implementation at the end of the constructor.
  * @param array $config
  */
 public function __construct($config = [])
 {
     if (!empty($config)) {
         $parsedConfig = [];
         foreach ($config as $k => $value) {
             $parsedConfig[Inflector::variablize($k)] = $value;
         }
         Yii::configure($this, $parsedConfig);
     }
     $this->init();
 }
開發者ID:2amigos,項目名稱:yii2-nexmo-library,代碼行數:26,代碼來源:Object.php

示例3: getName

 /**
  * Returns the name of the object that is going to be used as a js variable of the renderer service.
  *
  * @param bool $autoGenerate whether to auto-generate the name or not
  *
  * @return string
  */
 public function getName($autoGenerate = true)
 {
     if (!empty($this->_name)) {
         return $this->_name;
     }
     if ($autoGenerate) {
         $reflection = new \ReflectionClass($this);
         $this->_name = self::$autoNamePrefix . Inflector::variablize($reflection->getShortName()) . self::$counter++;
     }
     return $this->_name;
 }
開發者ID:denisiodb,項目名稱:yii2-google-maps-library,代碼行數:18,代碼來源:ObjectAbstract.php

示例4: reformatKeys

 /**
  * @param $data
  * @return mixed
  */
 private static function reformatKeys($data)
 {
     foreach ($data as $key => $value) {
         ArrayHelper::remove($data, $key);
         if (is_array($value)) {
             $data[Inflector::variablize($key)] = self::reformatKeys($value);
         } else {
             $data[Inflector::variablize($key)] = $value;
         }
     }
     return $data;
 }
開發者ID:voodoo-mobile,項目名稱:yii2-api,代碼行數:16,代碼來源:Json.php

示例5: setAttributes

 /**
  * Sets the attribute values in a massive way.
  * @param array $values attribute values (name => value) to be assigned to the model.
  * @param boolean $safeOnly whether the assignments should only be done to the safe attributes.
  * A safe attribute is one that is associated with a validation rule in the current [[scenario]].
  * @see safeAttributes()
  * @see attributes()
  */
 public function setAttributes($values, $safeOnly = true)
 {
     if (is_array($values)) {
         $attributes = array_flip($safeOnly ? $this->safeAttributes() : $this->attributes());
         foreach ($values as $name => $value) {
             $name = Inflector::variablize($name);
             if (isset($attributes[$name])) {
                 $this->{$name} = $value;
             } elseif ($safeOnly) {
                 $this->onUnsafeAttribute($name, $value);
             }
         }
     }
 }
開發者ID:NageshVeeravalli,項目名稱:yii2-packaii,代碼行數:22,代碼來源:Base.php

示例6: setKeys

 /**
  * @param $keys
  */
 public function setKeys($keys)
 {
     $variablized = $values = [];
     foreach ($keys as $key => $data) {
         $variablizedKey = Inflector::variablize($key);
         $this->map[$variablizedKey] = $key;
         $values[$variablizedKey] = $this->getKeyStorage()->get($key, null, false);
         $variablized[$variablizedKey] = $data;
     }
     $this->keys = $variablized;
     foreach ($values as $k => $v) {
         $this->setAttribute($k, $v);
     }
     parent::init();
 }
開發者ID:rocketyang,項目名稱:yii2-starter-kit,代碼行數:18,代碼來源:FormModel.php

示例7: run

 /**
  * @inheritdoc
  */
 public function run()
 {
     $id = $this->getId();
     $hiddenId = $id . '-hidden';
     echo Html::hiddenInput($this->name, null, ['id' => $hiddenId]);
     echo Html::tag('div', null, ['id' => $id]);
     $var = Inflector::variablize($id);
     $view = $this->getView();
     RangeFilterAsset::register($view);
     $options = Json::encode($this->pluginOptions);
     $view->registerJs("var {$var} = jQuery('#{$id}');");
     $view->registerJs("{$var}.rangeFilter({$options});");
     $view->registerJs("jQuery('#{$hiddenId}').val(JSON.stringify({$var}.rangeFilter('getFilter')));");
     $view->registerJs("{$var}.on('rangefilter.change', function(){ jQuery('#{$hiddenId}').val(JSON.stringify({$var}.rangeFilter('getFilter'))); });");
 }
開發者ID:diogobd,項目名稱:yii2-rangefilter,代碼行數:18,代碼來源:RangeFilter.php

示例8: init

 public function init()
 {
     parent::init();
     if (!isset($this->siteKey)) {
         $this->siteKey = \Yii::$app->params['reCaptcha']['siteKey'];
         if (empty($this->siteKey)) {
             throw new InvalidConfigException("Required `siteKey` is not found.");
         }
     }
     Html::addCssClass($this->captchaOptions, 'g-recaptcha');
     $this->captchaOptions['data']['sitekey'] = $this->siteKey;
     $this->captchaOptions['id'] = $this->options['id'] . '_captcha';
     $this->_callback = Inflector::variablize($this->options['id'] . '_callback');
     $this->captchaOptions['data']['callback'] = $this->_callback;
 }
開發者ID:petrabarus,項目名稱:yii2-recaptcha,代碼行數:15,代碼來源:ReCaptcha.php

示例9: run

 /**
  * @inheritdoc
  */
 public function run()
 {
     $hiddenId = ArrayHelper::remove($this->options, 'id');
     if ($this->hasModel()) {
         $value = Html::getAttributeValue($this->model, $this->attribute);
         echo Html::activeHiddenInput($this->model, $this->attribute, ['id' => $hiddenId]);
     } else {
         $value = $value = $this->value;
         echo Html::hiddenInput($this->name, $value, ['id' => $hiddenId]);
     }
     $id = $this->getId() . '-editor';
     $this->options['id'] = $id;
     $var = Inflector::variablize($id);
     echo Html::tag('textarea', Html::encode($value), $this->options);
     $view = $this->getView();
     CodeMirrorAsset::register($view);
     $options = Json::encode($this->pluginOptions);
     $view->registerJs("var {$var} = CodeMirror.fromTextArea(document.getElementById('{$id}'), {$options});");
     $view->registerJs("{$var}.on('change', function(editor){jQuery('#{$hiddenId}').val(editor.getValue());});");
 }
開發者ID:leandrogehlen,項目名稱:yii2-codemirror,代碼行數:23,代碼來源:CodeMirror.php

示例10: registerClientOptions

 /**
  * 
  */
 public function registerClientOptions()
 {
     $options = empty($this->clientOptions) ? '{}' : Json::htmlEncode($this->clientOptions);
     if (empty($this->options['id'])) {
         $this->options['id'] = $this->getId();
     }
     if ($this->varName === null) {
         $this->varName = Inflector::variablize($this->options['id']);
     }
     $view = $this->getView();
     $var = empty($this->varName) ? '' : "var {$this->varName} = ";
     $id = json_encode($this->options['id']);
     if ($this->position !== null && $this->position <= View::POS_BEGIN) {
         $view->registerAssetBundle(HandsontableAsset::className(), View::POS_HEAD);
     } else {
         $view->registerAssetBundle(HandsontableAsset::className());
     }
     $position = $this->position ?: View::POS_READY;
     $view->registerJs("{$var}new Handsontable(document.getElementById({$id}),{$options});", $position);
 }
開發者ID:deesoft,項目名稱:yii2-handsontable,代碼行數:23,代碼來源:Handsontable.php

示例11: jsVar

 /**
  * Creates a JavaScript variable name for the object
  *
  * @param string Prefix for JavaScript variable name
  * @return string JavaScript variable name for the object
  */
 public function jsVar($prefix = '')
 {
     return Inflector::variablize($prefix . ' ' . basename(get_class()) . self::$_counter++);
 }
開發者ID:beastbytes,項目名稱:yii2-leaflet,代碼行數:10,代碼來源:Layer.php

示例12: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     static::$instance = $this;
     $this->_varName = Inflector::variablize($this->name);
     $this->requires[] = 'ui.router';
     $this->requires = array_unique($this->requires);
     $view = $this->getView();
     // Asset Dependency
     $am = Yii::$app->getAssetManager();
     $key = md5(serialize([__CLASS__, Yii::$app->controller->route, $this->name]));
     $bundle = ['basePath' => '', 'depends' => [AngularAsset::className()], 'js' => []];
     foreach ($this->requires as $module) {
         if (isset(AngularAsset::$assetMap[$module])) {
             $bundle['depends'][] = AngularAsset::$assetMap[$module];
         }
     }
     $js = $this->generate();
     if ($this->remote) {
         $path = sprintf('%x', crc32($key));
         $jsName = Inflector::camel2id($this->name) . '.js';
         $bundle['js'][] = $jsName;
         $bundle['basePath'] = $am->basePath . '/' . $path;
         $bundle['baseUrl'] = $am->baseUrl . '/' . $path;
         FileHelper::createDirectory(Yii::getAlias($bundle['basePath']));
         file_put_contents(Yii::getAlias($bundle['basePath'] . '/' . $jsName), $js);
     } else {
         $view->registerJs($js, WebView::POS_END);
     }
     $am->bundles[$key] = new AssetBundle($bundle);
     $view->registerAssetBundle($key);
     $options = $this->options;
     if ($this->tag !== 'ui-view' && !isset($options['ui-view'])) {
         $options['ui-view'] = true;
     }
     if ($this->ngApp && !isset($options['ng-app'])) {
         $options['ng-app'] = $this->name;
     }
     echo Html::beginTag($this->tag, $options);
 }
開發者ID:deesoft,項目名稱:yii2-dev,代碼行數:42,代碼來源:UiView.php

示例13: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     static::$instance = $this;
     $this->_varName = Inflector::variablize($this->name);
 }
開發者ID:WiconWang,項目名稱:CS-Iris,代碼行數:8,代碼來源:NgView.php

示例14: generateRelationTo

 public function generateRelationTo($relation)
 {
     $class = new \ReflectionClass($relation->modelClass);
     $route = Inflector::variablize($class->getShortName());
     return $route;
 }
開發者ID:Gnome007,項目名稱:yii2-giiant,代碼行數:6,代碼來源:Generator.php

示例15:

<?php

use yii\helpers\StringHelper;
use yii\helpers\Inflector;
$modelClassName = StringHelper::basename($generator->modelClass);
$idModelClassName = Inflector::camel2id($modelClassName);
$varModelClassName = Inflector::variablize($modelClassName);
echo "<?php\n";
?>
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace app\assets;

use yii\web\AssetBundle;

/**
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class <?php 
echo $modelClassName;
?>
NewAsset extends AssetBundle
{
    public $sourcePath = '@app/views/<?php 
echo $idModelClassName;
?>
開發者ID:tqsq2005,項目名稱:yii2-jeasyui,代碼行數:31,代碼來源:NewAsset.php


注:本文中的yii\helpers\Inflector::variablize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。