Yii2 dev digest #6 Mar'14
Mar 4, 2014, 9:13:15 PMIn any case it seems that Yii2 developments is going close to the Beta and only a few big breaking changes were made in the last month ;)
And yes - Russian version of this digest is available (see the link above) !
- Yii2 added to Scrutinizer-CI. Feel a power in your arms to make code smells better? Come on, investigate reports and contribute.
- First draf of REST api implementation from Qiang. See the code, read docs, make your suggestions ! It is not in master yet, but it has a lot of features implemented - quick prototyping, routing by HTTP verbs, authorization, HATEOAS etc.
- New look for a framework documentation. Combined with Class References. Now it's easier to read.
- Help needed to enhance api doc generator
- Help needed to fix issues in Yii2 to work with HHVM
- Support for fetching Query results in Batches. Very usefull when working with big data sets. Here is the docs for this
- Support for Nested Transactions
- Big change in Custom Scopes handling for ActiveRelation. Now additional Query class should be made per AR model if you want to have custom scopes.
- Fixed syntax consistency in Html::a, createUrl, redirect etc. At last ! :)
- Pjax widget. Allows to add Ajax update to other widgets or any form/link inside it and changes url in browser via pushState.
- GridView supports update via pjax
- Added getIsPjax method and HTTP_X_PJAX header
Special method
renderAjax
> This method is similar torenderPartial()
except that it will inject into the rendering result with JS/CSS scripts and files which are registered with the view. For this reason, you should use this method instead ofrenderPartial()
to render a view to respond to an AJAX requestAdded support to parse JSON request data to Request::getRestParams()
"DB attributes" or "virtual properties" discussion. In the end there will not be any kind of that > You are currently able to add public properties which are not stored in db but you can validate them. This is done in advanced app with password field. Attributes are fields that are stored in db, public properties are not, but both can be validated.
- Yii2 extension generator in Gii module
- Bundled behaviors refactoring. AttributeStampBehavior, BlameableBehavior, TimestampBehavior. Also a proposal for a set of other behaviors like "SoftDelete", "Translatable" tec.
- Workflow for embedded documents usage in MongoDB ActiveRecord. I have had an experience workign with Mongo and embedded docs in Yii1 and I must say it's a pain in any case and require manual work
- New Fixtures handling - as classes, with dependencies, initialiser etc.
- Added ability to downgrade migrations by their absolute apply time
- Update for debug toolbar UI
Markdown extension from @cebe is now added as official one. I must say that's awesome work, and already really looks like introduced : > All existing implementations are either slow or not extensible so I decided to combine these two factors in a new implementation.
- DynamicModel - model class primarily used to support ad-hoc data validation
$model = DynamicModel::validateData(compact('name', 'email'), [ [['name', 'email'], 'string', 'max' => 128]], ['email', 'email'], ]);
Want a fast bootstart to play with Yii2 ?
Try it out !
Yii2 Advanced app in Vagrant with Puppet provisioning
Yii2 extensions
- @kartik-v made a great collection of useful helpers and extensions for Yii2
- jQuery Flot Charts extension for Yii 2
- yii2-resource-manager-component
- yii2-syntaxhighlighter
- yii2-bootstrap-daterangepicker
- yii2-fullcalendar
Yii2 Tips and Tricks
[Ok, I have an error `"unexpected '[', expecting ')' in ../vendor/yiisoft/yii2/yii/Yii.php on line 25"`](https://github.com/yiisoft/yii2/issues/2582) > Hey man just use PHP 5.4 :)
Url Rule To Catch All >
'<action:\w+><data:(.*)?>' => 'site/<action>'
Confused with
"use Yii;"
in view file > cebe :use Yii;
is to import Yii class into the current namespace. As the view file is already in the root namespace where also the Yii class lives there is not sense of importing it. Thus the error.How can I add relationships on fly in Yii2 ? > qiang : I see. So your relation name is dynamic based on the configuration, right? You need to do some trick with your behavior to support such "dynamic method". override
Behavior::hasMethod()
to return true forgetRelationName
. overrideBehavior::__call()
to implementgetRelationName
.Adding default scope to AR > Yes in Yii2 is dropped, because this method make many problems. You can simple add default scope, e.q ~~~{.php} class Post extends ActiveRecord { public static function createQuery($config = []) { $config['modelClass'] = get_called_class(); return (new PostQuery($config))->active(); } }
class PostQuery extends ActiveQuery { public function active() { $this->andWhere(['status' => Post::STATUS_PUBLISHED]); return $this; } } ~~~
How to keep hidden data in gridview > qiang : Configure
GridView::rowOptions
How to update assets as always while develop > vova07 : 1) With asset bundle (you must write it in each needed bundle): ~~~ public $publishOptions = [ 'forceCopy' => true ]; ~~~ > 2) Using symlink (just turn on it in config file): ~~~ 'assetManager' => [ 'linkAssets' => true ] ~~~