mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-13 04:38:03 +08:00
Merge commit 'fcac7f64b37c6a8d4ead9816b2580f50580c540d' into feature/gii-extension-generator
This commit is contained in:
@@ -12,6 +12,7 @@ Yii Framework 2 gii extension Change Log
|
||||
- Enh #1818: Do not display checkbox column if all rows are empty (johonunu)
|
||||
- Enh #1897: diff markup is now copy paste friendly (samdark)
|
||||
- Enh #2327: better visual representation of changed files, added header and refresh button to diff modal (thiagotalma)
|
||||
- Enh #2491: Added support for using the same base class name of search model and data model in Gii (qiangxue)
|
||||
|
||||
2.0.0 alpha, December 1, 2013
|
||||
-----------------------------
|
||||
|
||||
@@ -110,8 +110,9 @@ class DefaultController extends Controller
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function createUrl($route, $params = [])
|
||||
public function createUrl($params)
|
||||
{
|
||||
$params = (array)$params;
|
||||
if (!isset($params['id']) && $this->generator !== null) {
|
||||
foreach ($this->module->generators as $id => $generator) {
|
||||
if ($generator === $this->generator) {
|
||||
@@ -120,7 +121,7 @@ class DefaultController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
return parent::createUrl($route, $params);
|
||||
return parent::createUrl($params);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +140,8 @@ class DefaultController extends Controller
|
||||
}
|
||||
}
|
||||
$params['name'] = $name;
|
||||
return parent::createUrl('action', $params);
|
||||
$params[0] = 'action';
|
||||
return parent::createUrl($params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,8 +17,11 @@ use yii\web\Controller;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property array $columnNames Model column names. This property is read-only.
|
||||
* @property string $controllerID The controller ID (without the module ID prefix). This property is
|
||||
* read-only.
|
||||
* @property array $searchAttributes Searchable attributes. This property is read-only.
|
||||
* @property boolean|\yii\db\TableSchema $tableSchema This property is read-only.
|
||||
* @property string $viewPath The action view file path. This property is read-only.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
|
||||
@@ -14,7 +14,7 @@ $controllerClass = StringHelper::basename($generator->controllerClass);
|
||||
$modelClass = StringHelper::basename($generator->modelClass);
|
||||
$searchModelClass = StringHelper::basename($generator->searchModelClass);
|
||||
if ($modelClass === $searchModelClass) {
|
||||
$searchModelAlias = $searchModelClass.'Search';
|
||||
$searchModelAlias = $searchModelClass . 'Search';
|
||||
}
|
||||
|
||||
/** @var ActiveRecordInterface $class */
|
||||
@@ -31,7 +31,7 @@ namespace <?= StringHelper::dirname(ltrim($generator->controllerClass, '\\')) ?>
|
||||
|
||||
use Yii;
|
||||
use <?= ltrim($generator->modelClass, '\\') ?>;
|
||||
use <?= ltrim($generator->searchModelClass, '\\') ?><?php if (isset($searchModelAlias)):?> as <?= $searchModelAlias ?><?php endif ?>;
|
||||
use <?= ltrim($generator->searchModelClass, '\\') . (isset($searchModelAlias) ? " as $searchModelAlias" : "") ?>;
|
||||
use <?= ltrim($generator->baseControllerClass, '\\') ?>;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\VerbFilter;
|
||||
|
||||
@@ -11,6 +11,9 @@ use yii\helpers\StringHelper;
|
||||
|
||||
$modelClass = StringHelper::basename($generator->modelClass);
|
||||
$searchModelClass = StringHelper::basename($generator->searchModelClass);
|
||||
if ($modelClass === $searchModelClass) {
|
||||
$modelAlias = $modelClass . 'Model';
|
||||
}
|
||||
$rules = $generator->generateSearchRules();
|
||||
$labels = $generator->generateSearchLabels();
|
||||
$searchAttributes = $generator->getSearchAttributes();
|
||||
@@ -23,10 +26,10 @@ namespace <?= StringHelper::dirname(ltrim($generator->searchModelClass, '\\')) ?
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use <?= ltrim($generator->modelClass, '\\') ?>;
|
||||
use <?= ltrim($generator->modelClass, '\\') . (isset($modelAlias) ? " as $modelAlias" : "") ?>;
|
||||
|
||||
/**
|
||||
* <?= $searchModelClass ?> represents the model behind the search form about <?= $modelClass ?>.
|
||||
* <?= $searchModelClass ?> represents the model behind the search form about `<?= $generator->modelClass ?>`.
|
||||
*/
|
||||
class <?= $searchModelClass ?> extends Model
|
||||
{
|
||||
@@ -53,7 +56,7 @@ class <?= $searchModelClass ?> extends Model
|
||||
|
||||
public function search($params)
|
||||
{
|
||||
$query = <?= $modelClass ?>::find();
|
||||
$query = <?= isset($modelAlias) ? $modelAlias : $modelClass ?>::find();
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
]);
|
||||
@@ -69,7 +72,13 @@ class <?= $searchModelClass ?> extends Model
|
||||
|
||||
protected function addCondition($query, $attribute, $partialMatch = false)
|
||||
{
|
||||
$value = $this->$attribute;
|
||||
if (($pos = strrpos($attribute, '.')) !== false) {
|
||||
$modelAttribute = substr($attribute, $pos + 1);
|
||||
} else {
|
||||
$modelAttribute = $attribute;
|
||||
}
|
||||
|
||||
$value = $this->$modelAttribute;
|
||||
if (trim($value) === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
<?= "<?= " ?>Html::a('Update', ['update', <?= $urlParams ?>], ['class' => 'btn btn-primary']) ?>
|
||||
<?= "<?php " ?>echo Html::a('Delete', ['delete', <?= $urlParams ?>], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data-confirm' => Yii::t('app', 'Are you sure to delete this item?'),
|
||||
'data-method' => 'post',
|
||||
'data' => [
|
||||
'confirm' => Yii::t('app', 'Are you sure to delete this item?'),
|
||||
'method' => 'post',
|
||||
],
|
||||
]); ?>
|
||||
</p>
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class <?= $className ?> extends <?= '\\' . ltrim($generator->baseClass, '\\') .
|
||||
<?php foreach ($relations as $name => $relation): ?>
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveRelation
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function get<?= $name ?>()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user