Yii2 dev digest #6 Mar'14

Mar 4, 2014, 9:13:15 PM

After the long break here (unfortunately recent situation in my country do not lead to a good productivity), I am glad to announce the next digest.
In 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) !

Want a fast bootstart to play with Yii2 ?

Try it out !
Yii2 Advanced app in Vagrant with Puppet provisioning

Yii2 extensions

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 for getRelationName. override Behavior::__call() to implement getRelationName.

  • 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; } } ~~~

comments powered by Disqus
Ievgen
Kuzminov "iJackUA"
Web Team Lead
at MobiDev (Kharkiv, Ukraine)
Code in Ruby and Elixir, but still love PHP. Explore ES6 and Vue.js. Explore databases, use Ubuntu and MacOS, think about IT people and management

Notes


Skaffold tool that facilitates continuous development for Kubernetes-native applications. Continuously deploys to your local or remote Kubernetes cluster.



DoItLive is a tool for live presentations in the terminal. It reads a file of shell commands and replays the commands in a fake terminal session as you type random characters.