{"id":208182,"date":"2014-01-05T23:01:02","date_gmt":"2014-01-05T19:01:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=208182"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=208182","title":{"rendered":"<span class=\"post_title\">\u041a\u0430\u043a \u0441\u0432\u044f\u0437\u0430\u0442\u044c Yii Framework \u0438 Doctrine 2 ORM?<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/c13\/8ed\/525\/c138ed52553f803328ead2f79d73a9fb.jpg\"\/><\/p>\n<p>  \u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f Yii Framework. \u041e\u043d \u0431\u044b\u0441\u0442\u0440\u044b\u0439, \u0443\u0434\u043e\u0431\u043d\u044b\u0439, \u0433\u0438\u0431\u043a\u0438\u0439. \u041c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0432 \u043d\u0451\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d ActiveRecord. \u041d\u043e \u0431\u044b\u0432\u0430\u044e\u0442 \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430, \u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u044b\u043c, \u0434\u043e\u043c\u0435\u043d\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430, \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0440\u0430\u0441\u0442\u0451\u0442 \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c DataMapper.<\/p>\n<p>  \u0412 \u0442\u043e\u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f Doctrine 2 ORM. \u042d\u0442\u043e \u043f\u043e\u0436\u0430\u043b\u0443\u0439 \u0441\u0430\u043c\u0430\u044f \u043c\u043e\u0449\u043d\u0430\u044f ORM \u0434\u043b\u044f PHP, \u0438\u043c\u0435\u044e\u0449\u0430\u044f \u0448\u0438\u0440\u043e\u0447\u0430\u0439\u0448\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b. \u0414\u0430, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043e\u043d\u0430 \u00ab\u0442\u044f\u0436\u0435\u043b\u043e\u0432\u0430\u0442\u0430\u00bb \u0438 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u043e\u0438\u0442 \u0434\u0443\u043c\u0430\u0442\u044c \u043e\u0431 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a <i>\u00ab\u043f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0440\u0435\u043d\u044c \u0432\u0441\u0435\u0445 \u0431\u0435\u0434\u00bb<\/i><\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u0430 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u043c\u044b\u0441\u043b\u044c \u0441\u0432\u044f\u0437\u0430\u0442\u044c 2 \u044d\u0442\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043c\u043d\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430. \u041a\u0430\u043a \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e, \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0438\u0436\u0435.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/h4>\n<p>  \u0421\u0432\u044f\u0437\u0430\u0442\u044c Doctrine \u0438 Yii \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 DoctrineComponent, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c Doctrine.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c, \u0432 \u043f\u0430\u043f\u043a\u0435 protected \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u043f\u0430\u043f\u043a\u0430 vendor, \u043a\u0443\u0434\u0430 \u0438 \u0431\u044b\u043b \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d \u043a\u043e\u0434 Doctrine 2 ORM. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c Doctrine \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Composer \u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u0430\u0447\u0430\u0432\/\u0441\u043a\u043b\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0438\u0437 <a href=\"https:\/\/github.com\/doctrine\/doctrine2\">GitHub \u043f\u0440\u043e\u0435\u043a\u0442\u0430 Doctrine.<\/a> <br \/>  \u0422\u0430\u043a\u0436\u0435, \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b ORM \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f <a href=\"https:\/\/github.com\/doctrine\/dbal\">Doctrine Database Abstraction Layer<\/a> \u0438 <a href=\"https:\/\/github.com\/doctrine\/common\">Doctrine Common<\/a> (\u043f\u0440\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 Doctrine 2 ORM \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Composer \u0434\u0430\u043d\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438).<\/p>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0441\u043e\u0432\u0435\u0442\u0443\u044e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Doctrine 2 ORM \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0432 \u0442\u0443\u0436\u0435 \u043f\u0430\u043f\u043a\u0443 vendor 2 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 Symfony \u2014 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/symfony\/Console\">Console<\/a> (\u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Doctrine \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u043e\u043b\u044c) \u0438 <a href=\"https:\/\/github.com\/symfony\/Yaml\">Yaml <\/a>(\u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u043d\u0430 Yaml)<\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/d75\/7f8\/688\/d757f8688b111300e6c289d55f749626.png\"\/><\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <b>DoctrineComponent<\/b><\/h4>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 DoctrineComponent. \u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0431\u043b\u0430\u0433\u043e \u043e\u043d \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439. \u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435 protected\/components \u0432 \u0444\u0430\u0439\u043b\u0435 DoctrineComponent.php.<\/p>\n<pre><code class=\"php\">use Doctrine\\ORM\\EntityManager; use Doctrine\\ORM\\Configuration; use Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver; use Doctrine\\Common\\Annotations\\AnnotationReader; use Doctrine\\Common\\Annotations\\AnnotationRegistry;  class DoctrineComponent extends CComponent {     private $em = null;     private $basePath;     private $proxyPath;     private $entityPath;     private $driver;     private $user;     private $password;     private $host;     private $dbname;            public function init()     {         $this-&gt;initDoctrine();     }      public function initDoctrine()     {         Yii::setPathOfAlias('Doctrine', $this-&gt;getBasePath() . '\/vendor\/Doctrine');          $cache = new Doctrine\\Common\\Cache\\FilesystemCache($this-&gt;getBasePath() . '\/cache');         $config = new Configuration();         \/\/  $config-&gt;setMetadataCacheImpl($cache);           $driverImpl = new AnnotationDriver(new AnnotationReader(), $this-&gt;getEntityPath());         AnnotationRegistry::registerAutoloadNamespace('Doctrine\\ORM\\Mapping', $this-&gt;getBasePath() . '\/vendor');          $config-&gt;setMetadataDriverImpl($driverImpl);         $config-&gt;setQueryCacheImpl($cache);         $config-&gt;setProxyDir($this-&gt;getProxyPath());         $config-&gt;setProxyNamespace('Proxies');         $config-&gt;setAutoGenerateProxyClasses(true);         $connectionOptions = array(             'driver' =&gt; $this-&gt;getDriver(),             'user' =&gt; $this-&gt;getUser(),             'password' =&gt; $this-&gt;getPassword(),             'host' =&gt; $this-&gt;getHost(),             'dbname' =&gt; $this-&gt;getDbname()         );          $this-&gt;em = EntityManager::create($connectionOptions, $config);     }        public function setBasePath($basePath)     {         $this-&gt;basePath = $basePath;     }      public function getBasePath()     {         return $this-&gt;basePath;     }      public function setEntityPath($entityPath)     {         $this-&gt;entityPath = $entityPath;     }      public function getEntityPath()     {         return $this-&gt;entityPath;     }      public function setProxyPath($proxyPath)     {         $this-&gt;proxyPath = $proxyPath;     }      public function getProxyPath()     {         return $this-&gt;proxyPath;     }      public function setDbname($dbname)     {         $this-&gt;dbname = $dbname;     }      public function getDbname()     {         return $this-&gt;dbname;     }      public function setDriver($driver)     {         $this-&gt;driver = $driver;     }      public function getDriver()     {         return $this-&gt;driver;     }      public function setHost($host)     {         $this-&gt;host = $host;     }      public function getHost()     {         return $this-&gt;host;     }      public function setPassword($password)     {         $this-&gt;password = $password;     }      public function getPassword()     {         return $this-&gt;password;     }      public function setUser($user)     {         $this-&gt;user = $user;     }      public function getUser()     {         return $this-&gt;user;     }       \/**      * @return EntityManager      *\/     public function getEntityManager()     {         return $this-&gt;em;     } } <\/code><\/pre>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <code>initDoctrine<\/code>. \u0420\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043a\u043e\u0434.<\/p>\n<pre><code class=\"php\">$cache = new Doctrine\\Common\\Cache\\FilesystemCache($this-&gt;getBasePath() . '\/cache'); $config = new Configuration(); $config-&gt;setMetadataCacheImpl($cache); <\/code><\/pre>\n<p>  \u0414\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438\u0437 Doctrine. \u041f\u043e-\u0445\u043e\u0440\u043e\u0448\u0435\u043c\u0443, \u0442\u0438\u043f \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <code>FilesystemCache<\/code>) \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u043e \u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0440\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<pre><code class=\"php\">$driverImpl = new AnnotationDriver(new AnnotationReader(), $this-&gt;getEntityPath()); AnnotationRegistry::registerAutoloadNamespace('Doctrine\\ORM\\Mapping', $this-&gt;getBasePath() . '\/vendor'); $config-&gt;setMetadataDriverImpl($driverImpl); <\/code><\/pre>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0434\u0430 \u0432\u044b\u0448\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0440\u0430\u0439\u0432\u0435\u0440 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439.<\/p>\n<pre><code class=\"php\"> $config-&gt;setQueryCacheImpl($cache);  $config-&gt;setProxyDir($this-&gt;getProxyPath());  $config-&gt;setProxyNamespace('Proxies');  $config-&gt;setAutoGenerateProxyClasses(true); <\/code><\/pre>\n<p>  \u041a\u043e\u0434\u043e\u043c \u0432\u044b\u0448\u0435 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 (\u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430), \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u2014 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 Proxy \u0434\u043b\u044f Doctrine (\u043f\u0443\u0442\u044c, \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0451\u043d, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f Proxy-\u043a\u043b\u0430\u0441\u0441\u043e\u0432)<\/p>\n<pre><code class=\"php\">$connectionOptions = array(     'driver' =&gt; $this-&gt;getDriver(),     'user' =&gt; $this-&gt;getUser(),     'password' =&gt; $this-&gt;getPassword(),     'host' =&gt; $this-&gt;getHost(),     'dbname' =&gt; $this-&gt;getDbname() ); $this-&gt;em = EntityManager::create($connectionOptions, $config); <\/code><\/pre>\n<p>  \u041a\u043e\u0434 \u0432\u044b\u0448\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u043f\u0446\u0438\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441 \u0411\u0414. \u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 (\u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0434\u0430\u043b\u0435\u0435, \u043a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442).<br \/>  \u0418 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f EntityManager \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u043d\u043d\u0435\u0435 <code>$connectionOptions<\/code> \u0438 <code>$config<\/code>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0438 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0430\u0448\u0438\u043c\u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438.<\/p>\n<h4>\u041a\u0430\u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c DoctrineComponent \u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443?<\/h4>\n<p>  \u041f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044e <code> DoctrineComponent <\/code>\u043a \u043f\u0440\u043e\u0435\u043a\u0442\u0443.<br \/>  \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043f\u0440\u043e\u0435\u043a\u0442\u0430 (\u043e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e main.php)  <\/p>\n<pre><code class=\"php\">return array(     'components' =&gt; array(         'doctrine'=&gt;array(             'class' =&gt; 'DoctrineComponent',             'basePath' =&gt; __DIR__ . '\/..\/',             'proxyPath' =&gt; __DIR__ . '\/..\/proxies',             'entityPath' =&gt; array(                 __DIR__ . '\/..\/entities'             ),             'driver' =&gt; 'pdo_mysql',             'user' =&gt; 'dbuser',             'password' =&gt; 'dbpassword',             'host' =&gt; 'localhost',             'dbname' =&gt; 'somedb'         ),         \/\/ ... ); <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0447\u0435\u0440\u0435\u0437 <code>Yii::app()-&gt;doctrine<\/code>, \u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <code>EntityManager<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0447\u0435\u0440\u0435\u0437 <code>Yii::app()-&gt;doctrine-&gt;getEntityManager()<\/code><\/p>\n<p>  \u041d\u043e \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0430\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>EntityManager<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"php\">\u0441lass MainController extends Controller {     private $entityManager = null;      \/**      * @return Doctrine\\ORM\\EntityManager      *\/     public function getEntityManager()     {         if(is_null($this-&gt;entityManager)){             $this-&gt;entityManager = Yii::app()-&gt;doctrine-&gt;getEntityManager();         }         return $this-&gt;entityManager;     }     \/\/ ... } <\/code><\/pre>\n<p>  \u041a\u0430\u0436\u0434\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 <code>MainController<\/code> \u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>$this-&gt;getEntityManager()<\/code> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043f\u0440\u0438\u0447\u0451\u043c \u0432 IDE \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f <code>EntityManager<\/code>, \u0447\u0442\u043e \u043d\u0435\u0441\u043e\u043c\u043d\u0435\u043d\u043d\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043b\u044e\u0441\u043e\u043c.<\/p>\n<h4>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 Doctrine<\/h4>\n<p>  \u0421 Doctrine \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0435\u0451 \u043a\u043e\u043d\u0441\u043e\u043b\u044c. \u041d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0434\u043b\u044f \u0435\u0451 \u0437\u0430\u043f\u0443\u0441\u043a\u0430. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d \u043d\u0438\u0436\u0435. \u042f \u043f\u043e\u043b\u043e\u0436\u0438\u043b \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0432 \u043f\u0430\u043f\u043a\u0443 protected\/commands. \u041e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0442\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u043e \u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>doctrine<\/code> \u0434\u043b\u044f \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438, \u043d\u043e \u043c\u043d\u043e\u0439 \u043f\u043e\u043a\u0430 \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043d\u0435 \u0431\u044b\u043b\u043e.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0444\u0430\u0439\u043b <code>doctrine.php<\/code> \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u043e\u043d\u0441\u043e\u043b\u044c\u044e Doctrine.   <\/p>\n<pre><code class=\"php\">\/\/ change the following paths if necessary $yii = __DIR__ .'path\/to\/yii.php'; $config = __DIR__ . 'path\/to\/config\/console.php';  require_once($yii); Yii::createWebApplication($config); Yii::setPathOfAlias('Symfony', Yii::getPathOfAlias('application.vendor.Symfony'));  $em = Yii::app()-&gt;doctrine-&gt;getEntityManager(); $helperSet = new \\Symfony\\Component\\Console\\Helper\\HelperSet(array(     'db' =&gt; new \\Doctrine\\DBAL\\Tools\\Console\\Helper\\ConnectionHelper($em-&gt;getConnection()),     'em' =&gt; new \\Doctrine\\ORM\\Tools\\Console\\Helper\\EntityManagerHelper($em) ));  \\Doctrine\\ORM\\Tools\\Console\\ConsoleRunner::run($helperSet); <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u043e\u043b\u044c Doctrine \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0432 \u043f\u0430\u043f\u043a\u0443 commands \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <code>php doctrine.php<\/code>.<\/p>\n<h4>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u0432\u0438\u0434\u0436\u0435\u0442\u0435 GridView.<\/h4>\n<p>  \u0422\u0435, \u043a\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 Doctrine 2 ORM, \u0437\u043d\u0430\u044e\u0442, \u0447\u0442\u043e \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u043e\u0431\u0449\u0435\u043f\u0440\u0438\u043d\u044f\u0442\u043e\u043c \u0438\u0445 \u043f\u043e\u043d\u044f\u0442\u0438\u0438 (\u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0411\u0414, \u0432\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0438 \u0442.\u0434.) \u043d\u0435\u0442, \u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0437\u0431\u0438\u0442\u0430 \u043d\u0430 2 \u0447\u0430\u0441\u0442\u0438 \u2014 <code>Entity <\/code>\u0438 <code>Repository<\/code>. \u0412 <code>Entity<\/code> \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0443, \u0430 \u0432 <code>Repository <\/code> \u2014 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0411\u0414 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 DBAL Doctrine (\u043b\u0438\u0431\u043e \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043b\u0438\u0431\u043e \u0434\u0440\u0443\u0433\u0438\u043c \u0438\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c).<\/p>\n<h5>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/h5>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438.<br \/>  \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 <code>User<\/code>.<br \/>  \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e, \u0447\u0442\u043e \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0436\u0435 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0443\u044e \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438\u0437 Yii, \u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 <code>CModel.<\/code><\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e-\u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c User \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 CModel. \u041f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"php\">use Doctrine\\ORM\\Mapping as ORM;  \/**  * User  *  * @ORM\\Table(name=&quot;user&quot;)  * @ORM\\Entity(repositoryClass=&quot;UserRepository&quot;)  * @ORM\\HasLifecycleCallbacks  *\/ class User extends CModel {     \/**      * @var integer      *      * @ORM\\Column(name=&quot;id&quot;, type=&quot;integer&quot;, nullable=false)      * @ORM\\Id      * @ORM\\GeneratedValue(strategy=&quot;IDENTITY&quot;)      *\/     private $id;      \/**      * @var string      *      * @ORM\\Column(name=&quot;name&quot;, type=&quot;string&quot;, length=255, nullable=false)      *\/     private $name;      \/**      * @var string      *      * @ORM\\Column(name=&quot;password&quot;, type=&quot;string&quot;, length=255, nullable=false)      *\/     private $password;      \/**      * @var string      *      * @ORM\\Column(name=&quot;email&quot;, type=&quot;string&quot;, length=255, nullable=false)      *\/     private $email;      \/**      * @var string      *      * @ORM\\Column(name=&quot;role&quot;, type=&quot;string&quot;, length=255, nullable=false)      *\/     private $role;      \/**      * @var \\DateTime      *      * @ORM\\Column(name=&quot;created&quot;, type=&quot;datetime&quot;, nullable=false)      *\/     private $created;      \/**      * @var \\DateTime      *      * @ORM\\Column(name=&quot;modified&quot;, type=&quot;datetime&quot;, nullable=false)      *\/     private $modified;       public function rules(){         return array(             array('name, password', 'required'),             \/\/ ...         );     }      public function attributeNames()     {         return array(             'id'=&gt;'id',             'name'=&gt;'name',             'email'=&gt;'email',             'created'=&gt;'created',             'updated'=&gt;'updated'         );     }      public function attributeLabels()     {         return array(             'description' =&gt; 'Description',             'createdString' =&gt; 'Creation Date'         );     }     \/\/ ...  } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u0430\u043a \u0441 \u044d\u0442\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c (\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0438\u0436\u0435):  <\/p>\n<pre><code class=\"php\">    \/**      * Creates a new model.      * If creation is successful, the browser will be redirected to the 'view' page.      *\/     public function actionCreate()     {         $user = new User();          $userData = $this-&gt;getRequest()-&gt;get('User');         $course-&gt;setAttributes($userData);         if(!is_null($userData) && $user-&gt;validate())         {             $user-&gt;setName($userData['name']);             \/\/ ... \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435 \u0432\u0441\u0435 \u043f\u043e\u043b\u044f              $this-&gt;getEntityManager()-&gt;persist($user);             $this-&gt;getEntityManager()-&gt;flush();             $this-&gt;redirect(array('view','id'=&gt;$user-&gt;getId()));         }          $this-&gt;render('create',array(             'model'=&gt;$user,         ));     } <\/code><\/pre>\n<h5>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u0432\u0438\u0434\u0436\u0435\u0442\u0435 GridView<\/h5>\n<p>  \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043f\u0440\u0435\u043b\u0435\u0441\u0442\u0435\u0439 Yii \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f, \u043f\u043e-\u043c\u043e\u0435\u043c\u0443, \u0432\u0438\u0434\u0436\u0435\u0442\u044b, \u0430 \u0432 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 Grid, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0434\u0443\u0442 \u0432 Yii \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438.<br \/>  \u041d\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u044e\u0430\u043d\u0441 \u2014 \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 <code>ActiveRecord<\/code> (\u044f \u0438\u043c\u0435\u044e \u0432\u0432\u0438\u0434\u0443 \u0432\u0438\u0434\u0436\u0435\u0442 <code>GridView<\/code>). \u0410 \u043b\u0438\u0447\u043d\u043e \u043c\u043d\u0435 \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 Doctrine \u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Repository<\/code>.<\/p>\n<p>  \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>GridView<\/code> \u0435\u0441\u0442\u044c 2 \u0443\u0437\u043a\u0438\u0445 \u043c\u0435\u0441\u0442\u0430 \u2014 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>dataProvider <\/code>\u0438<code> filter<\/code>. \u0418 \u0437\u0434\u0435\u0441\u044c \u044f \u043f\u043e\u044e \u043e\u0434\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c Yii \u2014 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b <code>GridView<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 \u043a\u0430\u043a\u0438\u043c\u0438-\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0438\u0437 <code> ActiveRecord<\/code>, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0432 <code>GridView<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <code>dataProvider<\/code> \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u043b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code> IDataProvider<\/code> (\u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c <code>UserRepository<\/code>), \u0430 \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0432 <code>filter<\/code>, \u2014 \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 <code>CModel <\/code>(\u043d\u0430\u0448\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c <code>User<\/code> \u0443\u0436\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e).<\/p>\n<p>  \u0412\u0441\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>UserRepository<\/code> \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u043e\u0431\u0440\u0438\u0441\u0443\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0449\u0443\u044e \u0441\u0445\u0435\u043c\u0443.  <\/p>\n<pre><code class=\"php\">use Doctrine\\ORM\\EntityRepository;  abstract class BaseRepository extends EntityRepository implements IDataProvider {     protected $_id;     private $_data;     private $_keys;     private $_totalItemCount;     private $_sort;     private $_pagination;      public $modelClass;     public $model;     public $keyAttribute;      private $_criteria;     private $_countCriteria;      public $data;      abstract protected function fetchData();     abstract protected function calculateTotalItemCount();       public function getId(){ \/\/... }      public function getPagination($className='CPagination'){ \/\/... }      public function setPagination($value){ \/\/... }      public function setSort($value){ \/\/... }      public function getData($refresh=false){ \/\/... }      public function setData($value){ \/\/... }      public function getKeys($refresh=false){ \/\/... }      public function setKeys($value){ \/\/... }      public function getItemCount($refresh=false){ \/\/... }      public function getTotalItemCount($refresh=false){ \/\/... }      public function setTotalItemCount($value){ \/\/... }      public function getCriteria(){ \/\/... }      public function setCriteria($value){ \/\/... }      public function getCountCriteria(){ \/\/... }      public function setCountCriteria($value){ \/\/... }      public function getSort($className='CSort'){ \/\/... }      protected function fetchKeys(){ \/\/... }      private function _getSort($className){ \/\/... }  } <\/code><\/pre>\n<p>  \u0412\u044b\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. \u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043d\u043e\u0433\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 Yii \u043a\u043b\u0430\u0441\u0441\u0435 <code>CActiveDataProvider<\/code> \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code> IDataProvider<\/code>. \u0412 <code>UserRepository<\/code> \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u0438\u0448\u044c 2 \u043c\u0435\u0442\u043e\u0434\u0430(\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u043d\u0438\u0436\u0435):<\/p>\n<pre><code class=\"php\">&lt;?php  class UserRepository extends BaseRepository {     protected $_id = 'UserRepository';      \/**      * Fetches the data from the persistent data storage.      * @return array list of data items      *\/     protected function fetchData()     {        \/\/...     }      \/**      * Calculates the total number of data items.      * @return integer the total number of data items.      *\/     protected function calculateTotalItemCount()     {         \/\/...     } } <\/code><\/pre>\n<h4>\u0420\u0435\u0437\u044e\u043c\u0435<\/h4>\n<p>  \u0412\u044b\u0448\u0435 \u044f \u043f\u0440\u0438\u0432\u0451\u043b \u043e\u0434\u0438\u043d \u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 Yii + Doctrine 2 ORM. \u041c\u043d\u043e\u0433\u0438\u0435 \u043c\u043e\u0433\u0443\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u0437-\u0437\u0430 Doctrine 2 ORM Yii \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430, \u043d\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e Doctrine \u0438\u043c\u0435\u0435\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0440\u0435\u0434\u0441\u0442\u0432 \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0434\u0430 \u0438 \u043d\u0438\u043a\u0442\u043e \u043d\u0435 \u0437\u0430\u043f\u0440\u0435\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u044b\u0435 \u043b\u0438\u0431\u043e \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 Plain SQL. <br \/>  \u0417\u0430\u0442\u043e \u0432 \u0442\u0430\u043a\u043e\u0439 \u0441\u0432\u044f\u0437\u043a\u0435 \u043c\u044b \u0432\u044b\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u043c \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u043e\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u0438 \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043a\u043e\u0434 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0447\u0438\u0449\u0435.<\/p>\n<p>  \u0411\u044b\u043b \u0431\u044b \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u0435\u043b\u0435\u043d, \u0435\u0441\u043b\u0438 \u0431\u044b \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0412\u044b \u043f\u043e\u0434\u0435\u043b\u0438\u043b\u0438\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 DataMapper, \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0434\u0440\u0443\u0433\u0438\u0445 ORM \u0432 Yii, \u043e \u0441\u0432\u043e\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044f \u0431\u0438\u0437\u043d\u0435\u0441 \u043b\u043e\u0433\u0438\u043a\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u044f\u0445 ActiveRecord \u0432 Yii, \u043e \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e-\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Yii.<\/p>\n<p>  \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/208182\/\"> http:\/\/habrahabr.ru\/post\/208182\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t<img decoding=\"async\" src=\"http:\/\/habr.habrastorage.org\/post_images\/c13\/8ed\/525\/c138ed52553f803328ead2f79d73a9fb.jpg\"\/><\/p>\n<p>  \u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f Yii Framework. \u041e\u043d \u0431\u044b\u0441\u0442\u0440\u044b\u0439, \u0443\u0434\u043e\u0431\u043d\u044b\u0439, \u0433\u0438\u0431\u043a\u0438\u0439. \u041c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0432 \u043d\u0451\u043c \u043f\u0430\u0442\u0442\u0435\u0440\u043d ActiveRecord. \u041d\u043e \u0431\u044b\u0432\u0430\u044e\u0442 \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430, \u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u044b\u043c, \u0434\u043e\u043c\u0435\u043d\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430, \u043e\u0447\u0435\u043d\u044c \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0438 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0440\u0430\u0441\u0442\u0451\u0442 \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u043c DataMapper.<\/p>\n<p>  \u0412 \u0442\u043e\u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u043d\u0435 \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f Doctrine 2 ORM. \u042d\u0442\u043e \u043f\u043e\u0436\u0430\u043b\u0443\u0439 \u0441\u0430\u043c\u0430\u044f \u043c\u043e\u0449\u043d\u0430\u044f ORM \u0434\u043b\u044f PHP, \u0438\u043c\u0435\u044e\u0449\u0430\u044f \u0448\u0438\u0440\u043e\u0447\u0430\u0439\u0448\u0438\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b. \u0414\u0430, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043e\u043d\u0430 \u00ab\u0442\u044f\u0436\u0435\u043b\u043e\u0432\u0430\u0442\u0430\u00bb \u0438 \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0442\u043e\u0438\u0442 \u0434\u0443\u043c\u0430\u0442\u044c \u043e\u0431 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a <i>\u00ab\u043f\u0440\u0435\u0436\u0434\u0435\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0440\u0435\u043d\u044c \u0432\u0441\u0435\u0445 \u0431\u0435\u0434\u00bb<\/i><\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u0430 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u043c\u044b\u0441\u043b\u044c \u0441\u0432\u044f\u0437\u0430\u0442\u044c 2 \u044d\u0442\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043c\u043d\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430. \u041a\u0430\u043a \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e, \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0438\u0436\u0435.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-208182","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/208182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=208182"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/208182\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=208182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=208182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=208182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}