本文整理汇总了PHP中yii\helpers\Inflector::pluralize方法的典型用法代码示例。如果您正苦于以下问题:PHP Inflector::pluralize方法的具体用法?PHP Inflector::pluralize怎么用?PHP Inflector::pluralize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\Inflector
的用法示例。
在下文中一共展示了Inflector::pluralize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getModelSubDir
public function getModelSubDir($model)
{
$pk = $model::primaryKey();
$id = array_shift($pk);
$modelName = $this->getShortClass($model);
$modelDir = \yii\helpers\Inflector::pluralize($modelName) . '/' . $modelName . $model->{$id};
return $modelDir;
}
示例2: testPluralize
public function testPluralize()
{
$testData = ['move' => 'moves', 'foot' => 'feet', 'child' => 'children', 'human' => 'humans', 'man' => 'men', 'staff' => 'staff', 'tooth' => 'teeth', 'person' => 'people', 'mouse' => 'mice', 'touch' => 'touches', 'hash' => 'hashes', 'shelf' => 'shelves', 'potato' => 'potatoes', 'bus' => 'buses', 'test' => 'tests', 'car' => 'cars'];
foreach ($testData as $testIn => $testOut) {
$this->assertEquals($testOut, Inflector::pluralize($testIn));
$this->assertEquals(ucfirst($testOut), ucfirst(Inflector::pluralize($testIn)));
}
}
示例3: init
public function init()
{
if (!$this->modelClass) {
$this->modelClass = Inflector::pluralize($this->id);
}
\Yii::$app->request->getRawBody();
\Yii::$app->getResponse()->getHeaders()->add('Access-Control-Allow-Origin', '*');
parent::init();
}
示例4: getModelSubDir
public function getModelSubDir()
{
$modelName = $this->getShortClass($this->owner);
$modelDir = Inflector::pluralize($modelName) . '/' . $modelName . $this->owner->id;
return $modelDir;
}
示例5: getModelSubDir
public function getModelSubDir($model)
{
$modelName = $this->getShortClass($model);
$modelDir = \yii\helpers\Inflector::pluralize($modelName) . '/' . $modelName . $model->id;
return $modelDir;
}
示例6: index
/**
* @return string the name of the index this record is stored in.
*/
public static function index()
{
return Inflector::pluralize(Inflector::camel2id(StringHelper::basename(get_called_class()), '-'));
}
示例7: init
/**
* @inheritdoc
*/
public function init()
{
if (empty($this->controller)) {
throw new InvalidConfigException('"controller" must be set.');
}
$controllers = [];
foreach ((array) $this->controller as $urlName => $controller) {
if (is_integer($urlName)) {
$urlName = $this->pluralize ? Inflector::pluralize($controller) : $controller;
}
$controllers[$urlName] = $controller;
}
$this->controller = $controllers;
$this->prefix = trim($this->prefix, '/');
parent::init();
}
示例8: getPluralName
/**
* @return string
*/
public function getPluralName()
{
return $this->_pluralName ?: Inflector::titleize(Inflector::pluralize($this->_type));
}
示例9: getHeading
/**
* Retrieves heading
* @param boolean $plural
*/
public function getHeading($plural = false)
{
$headingKey = sprintf('heading_%s', $this->getClassid(self::RK_MODEL_CM, false, '_'));
if ($plural) {
return self::$generator->generateString(Inflector::pluralize($headingKey));
}
return self::$generator->generateString($headingKey);
}
示例10: lcfirst
echo lcfirst($column[4][0]);
?>
-><?php
echo $column[4][1];
?>
: '',
<?php
}
}
} elseif ($column[2] != 'main') {
?>
isset($this->model-><?php
echo lcfirst(Inflector::pluralize($column[0]));
?>
[0]) ? $this->model-><?php
echo lcfirst(Inflector::pluralize($column[0]));
?>
[0]-><?php
echo $column[1]->name;
?>
: '',
<?php
} elseif (in_array($column[3], [$generator::TYPE_DATE_AUTO, $generator::TYPE_DATE_INPUT])) {
?>
Yii::$app->formatter->asDatetime($this->model-><?php
echo $column[1]->name;
?>
, I18N::getDateFormat()),
<?php
} elseif ($column[3] == $generator::TYPE_IMAGE_INPUT) {
?>
示例11: loadAll
public function loadAll($POST, $skippedRelations = [])
{
if ($this->load($POST)) {
$shortName = StringHelper::basename(get_class($this));
$relData = $this->getRelationData();
foreach ($POST as $key => $value) {
if ($key != $shortName && strpos($key, '_') === false) {
/* @var $AQ ActiveQuery */
/* @var $this ActiveRecord */
/* @var $relObj ActiveRecord */
$isHasMany = is_array($value) && is_array(current($value));
$relName = $isHasMany ? lcfirst(Inflector::pluralize($key)) : lcfirst($key);
if (in_array($relName, $skippedRelations) || !array_key_exists($relName, $relData)) {
continue;
}
$AQ = $this->getRelation($relName);
$relModelClass = $AQ->modelClass;
$relPKAttr = $relModelClass::primaryKey();
$isManyMany = count($relPKAttr) > 1;
if ($isManyMany) {
$container = [];
foreach ($value as $relPost) {
if (array_filter($relPost)) {
$condition = [];
$condition[$relPKAttr[0]] = $this->primaryKey;
foreach ($relPost as $relAttr => $relAttrVal) {
if (in_array($relAttr, $relPKAttr)) {
$condition[$relAttr] = $relAttrVal;
}
}
$relObj = $relModelClass::findOne($condition);
if (is_null($relObj)) {
$relObj = new $relModelClass();
}
$relObj->load($relPost, '');
$container[] = $relObj;
}
}
$this->populateRelation($relName, $container);
} else {
if ($isHasMany) {
$container = [];
foreach ($value as $relPost) {
if (array_filter($relPost)) {
/* @var $relObj ActiveRecord */
$relObj = empty($relPost[$relPKAttr[0]]) ? new $relModelClass() : $relModelClass::findOne($relPost[$relPKAttr[0]]);
$relObj->load($relPost, '');
$container[] = $relObj;
}
}
$this->populateRelation($relName, $container);
} else {
$relObj = empty($value[$relPKAttr[0]]) ? new $relModelClass() : $relModelClass::findOne($value[$relPKAttr[0]]);
$relObj->load($value, '');
$this->populateRelation($relName, $relObj);
}
}
}
}
return true;
} else {
return false;
}
}
示例12:
?>
/* @var $dataProvider yii\data\ActiveDataProvider */
//$this->title = <?php
echo $generator->generateString(Inflector::pluralize($nameModel));
?>
;
//$this->params['breadcrumbs'][] = $this->title;
?>
<div class="<?php
echo Inflector::camel2id(StringHelper::basename($generator->modelClass));
?>
-index box">
<div class="box-header with-border">
<h1 class='box-title'><?php
echo Inflector::pluralize($nameModel);
?>
</h1>
</div>
<div class="box-body table-responsive">
<?php
if (!empty($generator->searchModelClass)) {
echo " <?php " . ($generator->indexWidgetType === 'grid' ? "// " : "");
?>
echo $this->render('_search', ['model' => $searchModel]); ?>
<?php
}
?>
<p>
示例13: generateRelationName
/**
* Generate a relation name for the specified table and a base name.
* @param string $key a base name that the relation name may be generated from
* @param boolean $multiple whether this is a has-many relation
* @return string the relation name
*/
protected function generateRelationName($key, $multiple)
{
if (!empty($key) && substr_compare($key, 'id', -2, 2, true) === 0 && strcasecmp($key, 'id')) {
$key = rtrim(substr($key, 0, -2), '_');
}
if ($multiple) {
$key = Inflector::pluralize($key);
}
return Inflector::id2camel($key, '_');
}
示例14: ltrim
* @var yii\web\View $this
* @var <?php
echo ltrim($generator->modelClass, '\\');
?>
$model
*/
$this->title = <?php
echo $generator->generateString('Create');
?>
;
$this->params['breadcrumbs'][] = ['label' => Yii::t('<?php
echo $generator->modelMessageCategory;
?>
', '<?php
echo Inflector::pluralize($modelName);
?>
'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="giiant-crud <?php
echo Inflector::camel2id(StringHelper::basename($generator->modelClass), '-', true);
?>
-create">
<h1>
<?php
echo "<?= Yii::t('{$generator->modelMessageCategory}', '{$modelName}') ?>\n";
?>
<small>
<?php
示例15: labels
/**
* Should return an array with single and plural form of model name, e.g.
*
* ```php
* return ['User', 'Users'];
* ```
*
* @return array
*/
public static function labels()
{
$class = new ReflectionClass(static::className());
$class = $class->getShortName();
return [$class, Inflector::pluralize($class)];
}