本文整理汇总了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;
}
}
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
示例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();
}
示例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'))); });");
}
示例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;
}
示例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());});");
}
示例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);
}
示例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++);
}
示例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);
}
示例13: init
/**
* @inheritdoc
*/
public function init()
{
static::$instance = $this;
$this->_varName = Inflector::variablize($this->name);
}
示例14: generateRelationTo
public function generateRelationTo($relation)
{
$class = new \ReflectionClass($relation->modelClass);
$route = Inflector::variablize($class->getShortName());
return $route;
}
示例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;
?>