Yii2 dev digest #7 Apr'14 > stdout.in Ievgen Kuzminov IT blog

Yii2 dev digest #7 Apr'14

Apr 16, 2014, 10:07:12 AM

Lucky 7th digest dedicated to Beta release . Not so much really new to say after Beta release notes on Yii site, but I can't stay away :)
Thanks for a big PR campaign by Alexander Makarov (@sam_dark), previous dev digest was seen by more than 5500 people. Quite impressive and gives me more inspiration to make new reviews! As usual - Russian version of this digest is available (see the link above) !
tl;dr;
Yii2 beta Release, PSR-2, DI, new RBAC, consistent Url helper, a lot of new widgets

Yii2 Development Visualization

made by Serg Ilin with Gource

Yii2 Extensions

Come on people! Connect your efforts to other great contributors as 2amigos, create and share your extensions. Let's increase Yii2 ecosystem !

Yii2 Tips & Tricks

        $url = ['site/index'];
        $url['Model'] = $model->attributes;
        echo Url::to($url);
common\models\ArticleData
backend\models\ArticleData (extends from common\models\ArticleData)
frontend\models\ArticleData (extends from common\models\ArticleData)

This way I can re-use this relation both from backend and frontend without re-declaring

$calledClass = static::className();
$nsPosition = strrpos($calledClass, '\\');
$calledNS = substr($calledClass, 0, $nsPosition);
...
return $this->hasMany(forward_static_call([$calledNS . '\ArticlesData', 'className']), ['bla' => 'bla_id']);
'request'=> [
            'class' => '\yii\web\Request',
            'hostInfo' => $params['backendUrl'],
            'baseUrl' => $params['backendUrl'],
        ],

or mock $_SERVER somewhere in app bootstrap

$_SERVER['SERVER_NAME'] = 'mydomain.com';
$_SERVER['HTTP_HOST'] = 'mydomain.com';
 namespace app\models;

 use yii\base\Object;
 use yii\db\Connection;
 use yii\di\Container;

 interface UserFinderInterface
 {
     function findUser();
 }

 class UserFinder extends Object implements UserFinderInterface
 {
     public $db;

     public function __construct(Connection $db, $config = [])
     {
         $this->db = $db;
         parent::__construct($config);
     }

     public function findUser()
     {
     }
 }

 class UserLister extends Object
 {
     public $finder;

     public function __construct(UserFinderInterface $finder, $config = [])
     {
         $this->finder = $finder;
         parent::__construct($config);
     }
 }

 $container = new Container;
 $container->set('yii\db\Connection', [
     'dsn' => '...',
 ]);
 $container->set('app\models\UserFinderInterface', [
     'class' => 'app\models\UserFinder',
 ]);
 $container->set('userLister', 'app\models\UserLister');

 $lister = $container->get('userLister');

 // which is equivalent to:

 $db = new \yii\db\Connection(['dsn' => '...']);
 $finder = new UserFinder($db);
 $lister = new UserLister($finder);

Read previous digests

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


Linkify - jQuery plugin for finding URLs in plain-text and converting them to HTML links. It works with all valid URLs and email addresses



Remodal - flat, responsive, lightweight, fast, easy customizable modal window jquery plugin with declarative state notation and hash tracking



Giving a try to Ubuntu 14.04 - so far it's ok. More stable and refined. But it seem to have problems with Cinnamon 2 installation. Oh fine... will wait for Linux MInt 17 to use on my Work machine



Updated blog. Mostly "under-the-hood" changes according to latest Yii2 state, some CSS and server optimisations. In case of any issues please feel free to comment here