mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-16 06:17:56 +08:00
Merge branch 'master' of github.com:yiisoft/yii2
* 'master' of github.com:yiisoft/yii2: (43 commits) `BaseActiveRecord::findAll()` comment fix Fixes #2913: RBAC `DbManager` is now initialized via migration [NL] Removed app.php [NL] brought translations up to date Fix for comparing numeric attributes in JavaScript Better Gii caption english Fix for comparing numeric attributes in JavaScript HHVM compatibility Fixes for Yii 2 Console Application Rough creation of a doc style guide typo Finished Edits Edited up to Active Record renamed chapter to section [skip ci] Catalan translation Edited up through "I18N" Cleaned Up updated guide toc [skip ci] Update concept-behaviors.md Fixed wrong links [skip ci] Fixed document for multisort in BaseArrayHelper ...
This commit is contained in:
@@ -11,13 +11,13 @@ use yii\helpers\Html;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* A Bootstrap 3 enhanced version of [[yii\widgets\ActiveField]].
|
||||
* A Bootstrap 3 enhanced version of [[\yii\widgets\ActiveField]].
|
||||
*
|
||||
* This class adds some useful features to [[yii\widgets\ActiveField|ActiveField]] to render all
|
||||
* This class adds some useful features to [[\yii\widgets\ActiveField|ActiveField]] to render all
|
||||
* sorts of Bootstrap 3 form fields in different form layouts:
|
||||
*
|
||||
* - [[inputTemplate]] is an optional template to render complex inputs, for example input groups
|
||||
* - [[horizontalClass]] defines the CSS grid classes to add to label, wrapper, error and hint
|
||||
* - [[horizontalCssClasses]] defines the CSS grid classes to add to label, wrapper, error and hint
|
||||
* in horizontal forms
|
||||
* - [[inline]]/[[inline()]] is used to render inline [[checkboxList()]] and [[radioList()]]
|
||||
* - [[enableError]] can be set to `false` to disable to the error
|
||||
|
||||
@@ -12,7 +12,7 @@ use yii\helpers\Html;
|
||||
use yii\base\InvalidConfigException;
|
||||
|
||||
/**
|
||||
* A Bootstrap 3 enhanced version of [[yii\widgets\ActiveForm]].
|
||||
* A Bootstrap 3 enhanced version of [[\yii\widgets\ActiveForm]].
|
||||
*
|
||||
* This class mainly adds the [[layout]] property to choose a Bootstrap 3 form layout.
|
||||
* So for example to render a horizontal form you would:
|
||||
|
||||
@@ -6,6 +6,7 @@ Yii Framework 2 gii extension Change Log
|
||||
|
||||
- Bug #1263: Fixed the issue that Gii and Debug modules might be affected by incompatible asset manager configuration (qiangxue)
|
||||
- Bug #3265: Fixed incorrect controller class name validation (suralc)
|
||||
- Enh #2018: Search model is not required anymore in CRUD generator (johonunu)
|
||||
- Enh #3088: The gii module will manage their own URL rules now (qiangxue)
|
||||
- Enh #3222: Added `useTablePrefix` option to the model generator for Gii (horizons2)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class Generator extends \yii\gii\Generator
|
||||
public $controllerClass;
|
||||
public $baseControllerClass = 'yii\web\Controller';
|
||||
public $indexWidgetType = 'grid';
|
||||
public $searchModelClass;
|
||||
public $searchModelClass = '';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -61,7 +61,7 @@ class Generator extends \yii\gii\Generator
|
||||
{
|
||||
return array_merge(parent::rules(), [
|
||||
[['moduleID', 'controllerClass', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'],
|
||||
[['modelClass', 'searchModelClass', 'controllerClass', 'baseControllerClass', 'indexWidgetType'], 'required'],
|
||||
[['modelClass', 'controllerClass', 'baseControllerClass', 'indexWidgetType'], 'required'],
|
||||
[['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class must not be equal to Model Class.'],
|
||||
[['modelClass', 'controllerClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'],
|
||||
[['modelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]],
|
||||
@@ -162,15 +162,22 @@ class Generator extends \yii\gii\Generator
|
||||
public function generate()
|
||||
{
|
||||
$controllerFile = Yii::getAlias('@' . str_replace('\\', '/', ltrim($this->controllerClass, '\\')) . '.php');
|
||||
$searchModel = Yii::getAlias('@' . str_replace('\\', '/', ltrim($this->searchModelClass, '\\') . '.php'));
|
||||
|
||||
$files = [
|
||||
new CodeFile($controllerFile, $this->render('controller.php')),
|
||||
new CodeFile($searchModel, $this->render('search.php')),
|
||||
];
|
||||
|
||||
if (!empty($this->searchModelClass)) {
|
||||
$searchModel = Yii::getAlias('@' . str_replace('\\', '/', ltrim($this->searchModelClass, '\\') . '.php'));
|
||||
$files[] = new CodeFile($searchModel, $this->render('search.php'));
|
||||
}
|
||||
|
||||
$viewPath = $this->getViewPath();
|
||||
$templatePath = $this->getTemplatePath() . '/views';
|
||||
foreach (scandir($templatePath) as $file) {
|
||||
if (empty($this->searchModelClass) && $file === '_search.php') {
|
||||
continue;
|
||||
}
|
||||
if (is_file($templatePath . '/' . $file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
|
||||
$files[] = new CodeFile("$viewPath/$file", $this->render("views/$file"));
|
||||
}
|
||||
@@ -438,7 +445,7 @@ class Generator extends \yii\gii\Generator
|
||||
if (is_subclass_of($class, 'yii\mongodb\ActiveRecord')) {
|
||||
return "'id' => (string)\$model->{$pks[0]}";
|
||||
} else {
|
||||
return "'id' => \$model->{$pks[0]}";
|
||||
return "'id' => \$model->{$pks[0]}";
|
||||
}
|
||||
} else {
|
||||
$params = [];
|
||||
@@ -446,7 +453,7 @@ class Generator extends \yii\gii\Generator
|
||||
if (is_subclass_of($class, 'yii\mongodb\ActiveRecord')) {
|
||||
$params[] = "'$pk' => (string)\$model->$pk";
|
||||
} else {
|
||||
$params[] = "'$pk' => \$model->$pk";
|
||||
$params[] = "'$pk' => \$model->$pk";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,11 @@ namespace <?= StringHelper::dirname(ltrim($generator->controllerClass, '\\')) ?>
|
||||
|
||||
use Yii;
|
||||
use <?= ltrim($generator->modelClass, '\\') ?>;
|
||||
<?php if (!empty($generator->searchModelClass)): ?>
|
||||
use <?= ltrim($generator->searchModelClass, '\\') . (isset($searchModelAlias) ? " as $searchModelAlias" : "") ?>;
|
||||
<?php else: ?>
|
||||
use yii\data\ActiveDataProvider;
|
||||
<?php endif; ?>
|
||||
use <?= ltrim($generator->baseControllerClass, '\\') ?>;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
@@ -59,6 +63,7 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
<?php if (!empty($generator->searchModelClass)): ?>
|
||||
$searchModel = new <?= isset($searchModelAlias) ? $searchModelAlias : $searchModelClass ?>;
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->getQueryParams());
|
||||
|
||||
@@ -66,6 +71,15 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas
|
||||
'dataProvider' => $dataProvider,
|
||||
'searchModel' => $searchModel,
|
||||
]);
|
||||
<?php else: ?>
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => <?= $modelClass ?>::find(),
|
||||
]);
|
||||
|
||||
return $this->render('index', [
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
<?php endif; ?>
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,7 @@ use <?= $generator->indexWidgetType === 'grid' ? "yii\\grid\\GridView" : "yii\\w
|
||||
/**
|
||||
* @var yii\web\View $this
|
||||
* @var yii\data\ActiveDataProvider $dataProvider
|
||||
* @var <?= ltrim($generator->searchModelClass, '\\') ?> $searchModel
|
||||
<?= !empty($generator->searchModelClass) ? " * @var " . ltrim($generator->searchModelClass, '\\') . " \$searchModel\n" : '' ?>
|
||||
*/
|
||||
|
||||
$this->title = <?= $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>;
|
||||
@@ -29,8 +29,9 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-index">
|
||||
|
||||
<h1><?= "<?= " ?>Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= "<?php " . ($generator->indexWidgetType === 'grid' ? "// " : "") ?>echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
<?php if(!empty($generator->searchModelClass)): ?>
|
||||
<?= " <?php " . ($generator->indexWidgetType === 'grid' ? "// " : "") ?>echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<p>
|
||||
<?= "<?= " ?>Html::a(<?= $generator->generateString('Create {modelClass}', ['modelClass' => Inflector::camel2words(StringHelper::basename($generator->modelClass))]) ?>, ['create'], ['class' => 'btn btn-success']) ?>
|
||||
@@ -39,8 +40,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
<?php if ($generator->indexWidgetType === 'grid'): ?>
|
||||
<?= "<?= " ?>GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
<?= !empty($generator->searchModelClass) ? "'filterModel' => \$searchModel,\n 'columns' => [\n" : "'columns' => [\n"; ?>
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
<?php
|
||||
|
||||
@@ -112,7 +112,7 @@ class Generator extends \yii\gii\Generator
|
||||
return [
|
||||
'vendorName' => 'This refers to the name of the publisher, your GitHub user name is usually a good choice, eg. <code>myself</code>.',
|
||||
'packageName' => 'This is the name of the extension on packagist, eg. <code>yii2-foobar</code>.',
|
||||
'namespace' => 'PSR-4, eg. <code>myself\foobar\</code> This will be added to your autoloading by composer. Do not use yii or yii2 in the namespace.',
|
||||
'namespace' => 'PSR-4, eg. <code>myself\foobar\</code> This will be added to your autoloading by composer. Do not use yii, yii2 or yiisoft in the namespace.',
|
||||
'keywords' => 'Comma separated keywords for this extension.',
|
||||
'outputPath' => 'The temporary location of the generated files.',
|
||||
'title' => 'A more descriptive name of your application for the README file.',
|
||||
|
||||
@@ -11,7 +11,7 @@ $this->title = 'Welcome to Gii';
|
||||
?>
|
||||
<div class="default-index">
|
||||
<div class="page-header">
|
||||
<h1>Welcome to Gii <small>a magic tool that can write code for you</small></h1>
|
||||
<h1>Welcome to Gii <small>a magical tool that can write code for you</small></h1>
|
||||
</div>
|
||||
|
||||
<p class="lead">Start the fun with the following code generators:</p>
|
||||
|
||||
@@ -39,7 +39,7 @@ use yii\helpers\Html;
|
||||
* 'label' => 'Ajax tab',
|
||||
* 'url' => ['ajax/content'],
|
||||
* ],
|
||||
* ),
|
||||
* ],
|
||||
* 'options' => ['tag' => 'div'],
|
||||
* 'itemOptions' => ['tag' => 'div'],
|
||||
* 'headerOptions' => ['class' => 'my-class'],
|
||||
|
||||
@@ -5,6 +5,7 @@ Yii Framework 2 twig extension Change Log
|
||||
--------------------------
|
||||
|
||||
- Bug #2925: Fixed throwing exception when accessing AR property with null value (samdark)
|
||||
- Enh #1799: Added `form_begin`, `form_end` to twig extension (samdark)
|
||||
|
||||
|
||||
2.0.0-beta April 13, 2014
|
||||
|
||||
@@ -7,19 +7,20 @@ To use this extension, simply add the following code in your application configu
|
||||
|
||||
```php
|
||||
return [
|
||||
//....
|
||||
'components' => [
|
||||
'view' => [
|
||||
'renderers' => [
|
||||
'twig' => [
|
||||
'class' => 'yii\twig\ViewRenderer',
|
||||
//'cachePath' => '@runtime/Twig/cache',
|
||||
//'options' => [], /* Array of twig options */
|
||||
// ... see ViewRenderer for more options
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
//....
|
||||
'components' => [
|
||||
'view' => [
|
||||
'renderers' => [
|
||||
'twig' => [
|
||||
'class' => 'yii\twig\ViewRenderer',
|
||||
// set cachePath to false in order to disable template caching
|
||||
//'cachePath' => '@runtime/Twig/cache',
|
||||
//'options' => [], /* Array of twig options */
|
||||
// ... see ViewRenderer for more options
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
```
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use Yii;
|
||||
use yii\base\View;
|
||||
use yii\base\ViewRenderer as BaseViewRenderer;
|
||||
use yii\helpers\Url;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/**
|
||||
* TwigViewRenderer allows you to use Twig templates in views.
|
||||
@@ -115,11 +116,6 @@ class ViewRenderer extends BaseViewRenderer
|
||||
$this->setLexerOptions($this->lexerOptions);
|
||||
}
|
||||
|
||||
// $this->addFunctions([
|
||||
// 'rot13' => 'str_rot13',
|
||||
// 'jsonEncode' => '\yii\helpers\Json::encode',
|
||||
// ]);
|
||||
|
||||
// Adding global 'void' function (usage: {{void(App.clientScript.registerScriptFile(...))}})
|
||||
$this->twig->addFunction('void', new \Twig_Function_Function(function ($argument) {
|
||||
}));
|
||||
@@ -132,6 +128,14 @@ class ViewRenderer extends BaseViewRenderer
|
||||
return Url::to(array_merge([$path], $args), true);
|
||||
}));
|
||||
|
||||
$this->twig->addFunction('form_begin', new \Twig_Function_Function(function ($args = []) {
|
||||
return ActiveForm::begin($args);
|
||||
}));
|
||||
|
||||
$this->twig->addFunction('form_end', new \Twig_Function_Function(function () {
|
||||
ActiveForm::end();
|
||||
}));
|
||||
|
||||
$this->twig->addGlobal('app', \Yii::$app);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user