Yii2 dev digest #4 Dec'13
Dec 27, 2013, 1:28:31 PM- Added consumer classes for OpenID, OAuth 1 & 2
Build in clients for Facebook, GitHub, GoogleOAuth, GoogleOpenId, LinkedIn, Twitter, YandexOAuth, YandexOpenId. (Discussion here) - Participate in discussion - Determine the list of predefined auth clients
- Added
ActiveQuery::joinWith()
to support joining with relations + Discussion over another "join with" approach And the documentation for joining with relations - Added
BaseActiveRecord::markAttributeDirty() to force updating a record when calling
update()` - Added
BaseActiveRecord::updateAttributes()
- a shortcut toupdate()
when data validation is not needed and only a list of attributes need to be updated. - Throw exception when the given AR relation name does not match in a case sensitive manner
- Added
ActionColumn::controller
property to support custom controller for handling GridView actions - Added support for validating multiple columns by
UniqueValidator
andExistValidator
- Yii PHAR package support should be reviewed after GA
- Added
yii\web\Controller::createAbsoluteUrl()
- Added support for tagName and encodeLabel parameters in ButtonDropdown
- GII generates rules for unique indexes
- More Codeception integration and usage docs
Html::activeCheckboxList()
andHtml::activeRadioList()
will submit an empty string if no checkbox/radio is selected- Use masked CSRF tokens to prevent BREACH exploits
- Discussion - Enhance Inflector helper with ascii function
- Advanced template and MongoDB AR don't work smooth together yet
Tips & Tricks
@cebe :
class RedactorI18NAsset extends AssetBundle
{
public $sourcePath = '@app/assets/redactor';
public $js = [
];
public function init()
{
$this->js[] = 'jquery.ui.datepicker-' . Yii::$app->language . '.js';
parent::init();
}
}
A way to make Sortable Column for non-DataColumn
@cebe : to allow sorting and filtering your value has to be calculated in the database. if your model calculates it in afterFind() or similar way you are not able to filter or sort by that field anymore. You can add values to the select query like this:
$query->select[] = 'SUM(price) AS subtotal';
You also need to declare a property in your AR class to hold the value after find.Don't make Autoincrement ID with Mongo
@iJackUA : Really - don't do it, whatever good idea it seems to you, I have tried once and will no do it again :)
How to create url from backend to frontend app?
@qiangxue : You should configure a url manager like you do for the frontend app. The same set of URL rules should be used.
How can I handle an event from annother class
@qiangxue : You can use class-level events
ActiveRecord not adding quotation to the field name (for plain SQL)
@klimov-paul This is expected: you are responsible for any plain SQL on your own. Query class still provides you several shortcut syntaxes. In this particular case you should use:
MyArClass::find()->where(["show" => 1])->all();
How to reuse main layout file, like the column1 & column2 in Yii1 ?
@ philippfrenzel : ok, use case - in your view/layouts folder you make a new column2.php this should look like this:
<php $this->beginContent('@app/views/layouts/main.php'); ?>
<div class="row">
<div class="col-md-3">
<div class="pg-sidebar">
<?= $this->blocks['sidebar']; ?>
<?= $this->blocks['toolbar']; ?>
</div>
</div>
<div class="col-md-9">
<?= $content; ?>
</div>
</div>
<php $this->endContent(); ?>
And in your controller, you set a new public variable:
public $layout = "/main";
In your ControllerAction you can set layout by:$this->layout = "/column2";