CUrlRule
class cannot handle (for example, when part of the URL depends on values in the database), you can write your own classes for handling URLs and use them in the CUrlManager
configuration: array( // '/login' → 'site/login' .. '<action:(login|logout|about)>' => 'site/<action>', // '//' array( 'class' => 'application.components.CarUrlRule', 'connectionID' => 'db', ), // 'post/update' '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ),
CBaseUrlRule
and looks like this: class CarUrlRule extends CBaseUrlRule { public $connectionID = 'db'; public function createUrl($manager,$route,$params,$ampersand) { if ($route==='car/index') { if (isset($params['manufacturer'], $params['model'])) return $params['manufacturer'] . '/' . $params['model']; else if (isset($params['manufacturer'])) return $params['manufacturer']; } return false; // } public function parseUrl($manager,$request,$pathInfo,$rawPathInfo) { if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches)) { // $matches[1] $matches[3] // ? // , $_GET['manufacturer'] / $_GET['model'] // 'car/index' } return false; // } }
// Yii Yii::registerAutoloader($autoloader);
// true Yii Yii::registerAutoloader($autoloader, true);
index.php
bit: require('path/to/yii.php'); // PHP include path Yii::$enableIncludePath = false; Yii::createWebApplication($config)->run();
// Yii::getLogger()->autoFlush = 1; // Yii::getLogger()->autoDump = true;
CActiveRecord
class has a new saveCounters()
method, similar to the existing CActiveRecord::updateCounters()
. The main difference is that saveCounters()
works only with the current object while updateCounters()
works with the entire table: $post = Post::model()->findByPk(1); // $post->saveCounters(array('views'=>1)); // Post::model()->updateCounters(array('views'=>1), 'id=1');
yiic message
it was often necessary to delete the old file and replace it with a new one that was generated next. Now you can write directly to the old file, if you set the overwrite
option to true
in the command configuration.CUrlManager
is usually used to generate a URL, which was previously not available to console applications. Now both in web applications and in console you can use Yii::app()->createUrl()
, which is very convenient, for example, to build a sitemap that lists the URL of a web application. <?php // clip ?> <?php $this->beginClip('hello')?> <p>, {username}!</p> <?php $this->endClip() ?> <?php // clip ?> <?php $this->renderClip('hello',array( '{username}'=>'Qiang', ))?> <?php $this->renderClip('hello',array( '{username}'=>'Alex', ))?> <?php $this->renderClip('hello',array( '{username}'=>'Michael', ))?>
Source: https://habr.com/ru/post/122770/
All Articles