Displaying 91-100 of 112 results.
Wiki: Yii 1.1 Add Yii Translation to website, multilanguage functionalitywiki
posted by admin on March 5, 2016
1. Step
Create Messages Folder in directory protected

2. Step
Create your multilanguage translation folder in directory Messages, for example hy, ru etc.

3. Step
Create files translation.php in your translation folders, which you created hy, ru

4. Step
Edit your translation.php files, and open massive like

/* ру */
return array(
'Username'=>'Имя пользователя',

5. Step
Call translation function on your project

Yii::t('translation', 'Username')//translation - translation.php, 'Username' - the word, which you want to translate

* You can have many translation to same word

You can create for example app.php on your translation folders 'hy', 'ru' etc., and you can call same word by another translation.

6. Step
You can Create files app.php in your translation folders, which you created hy, ru

7. Step
Edit your app.php files, and open massive like

/* ру */
return array(

8. Step
Call translation function on your project by different translation

Yii::t('translation', 'Username')//translation - translation.php, 'Username' - the word, which you want to translate


Yii::t('app', 'Username')//app - app.php, 'Username' - the word, which you want to translate
Read more
Resolved: Yii 1.1 How to change home name breadcrumbs to another or multilanguage
posted by admin on March 5, 2016
In main layout i have this code

<?php if(isset($this->breadcrumbs)):?>
<?php $this->widget('zii.widgets.CBreadcrumbs', array(
)); ?><!-- breadcrumbs -->
<?php endif ?>

I want to change the word Home and include multilanguage outputRead more
Wiki: Yii 1.1: More information to Yii::app() user - id, userrole etc.wiki
posted by admin on March 2, 2016
By default, the expression Yii::app()->user returns a CWebUser application component which represents the information that are closely related with the current user. Some information can be persistent throughout the current user session. For example, CWebUser already comes with a name property that stores the username of the current user.

In order to store more information, we need to modify the identity class used together with CWebUser. Each application may have one or several identity classes which are mainly responsible to provide ways of performing user authentication.

Here we use the UserIdentity class included in the testdrive application as an example, assuming our goal is to add the ID and the last login time of the user to CWebUser. We would modify UserIdentity as follows,

class UserIdentity extends CUserIdentity
private $_id;

public function authenticate()
else if($user->password!==md5($this->password))
$this->setState('userrole', $user->userrole_id);
return !$this->errorCode;

public function getId()
return $this->_id;

In the above, during authentication we retrieve the ID and the last login time information of the authenticated user. We save the ID in a private variable $_id and save lastLoginTime in a state by calling setState(). The reason that we use different approaches to save id and lastLoginTime is because id is a pre-defined property that is recognized by CWebUser. If we want to store more information, we should use setState(), like we do with lastLoginTime.

We also override the getId() method to return the private variable $_id. The parent implementation is to return the username.

That's all we need. Now if we want to retrieve the id or lastLoginTime information in our code, we can do the following:

Read more
Resolved: Yii check action create and update in view _form
posted by admin on February 2, 2016
I want to check is action create or update and write specific view form row

<?php if (action check syntax here like isUpdate) : ?>
<?php echo $form->labelEx($model,'newpassword'); ?>
<?php echo $form->passwordField($model,'newpassword',array('size'=>55,'maxlength'=>255)); ?>
<?php echo $form->error($model,'newpassword'); ?>
<?php endif; ?>
Read more
Resolved: Yii cjuidatepicker not saving
posted by admin on January 30, 2016
I have this field in my _form.php

'model' => $model,
'attribute' => 'founding',
'language' => Yii::app()->language,
'flat' => false, // tells the widget to show the calendar inline
'options' => array(
'showOn' => 'both', // also opens with a button
'dateFormat' => 'yy-mm-dd', // format of "2012-12-25"
'showOtherMonths' => true, // show dates in other months
'selectOtherMonths' => true, // can seelect dates in other months
'changeYear' => true, // can change year
'changeMonth' => true, // can change month
'yearRange' => '2000:2099', // range of year
'minDate' => '2000-01-01', // minimum date
'maxDate' => '2099-12-31', // maximum date
'showButtonPanel' => true, // show button panel
'htmlOptions' => array(
'size' => '10',
'maxlength' => '10',

Controller SAVE() saving NULL. I var_dump($model) and see NULL.
Please help me to correct.Read more
Resolved: Stop loading jquery library from assets folder in Yii
posted by admin on January 24, 2016
I had problem in my app that made it slow , after checked firebug I noted that jquery-ui loaded twice first from google.com and second from assets folder ("232kb") .

How to force it to load from google.com, or localhost, or jquery.com without assets version ?Read more
Wiki: Upgrading Instructions for Yii Framework v1.1.7wiki
posted by admin on January 23, 2016

The following upgrading instructions are cumulative. That is,
if you want to upgrade from version A to version C and there is
version B between A and C, you need to following the instructions
for both A and B.

General upgrade intructions
- Make a backup.
- Clean up your 'assets' folder.
- Replace 'framework' dir with the new one or point SVN to a fresh
release and update.
- Check if everything is OK, if not — revert from backup and post
issues to Yii issue tracker.

Upgrading from v1.1.6
- Make sure you are using latest stable PHPUnit 3.5 if you are using unit tests.

Upgrading from v1.1.5
- In CActiveRecord::relations(), if a relation involves composite foreign keys, the foreign key
columns must be separated by commas now. Previously, the columns can be separated by either
commas or spaces. If your mode code are generated by Gii or yiic shell, you do not need to
worry about this.
- CLDR data was updated to a newest available version so data formats, month
names and other regional data can be changed.

Upgrading from v1.1.4
- CHtml will no longer render null attributes for HTML tags. This means if $htmlOptions is
array('class'=>null), it will no longer render the 'class' attribute in the HTML tag.
it would render the class attribute as class="". We expect this will not cause much trouble
in upgrading. However, in case problems happen, you may set the attribute to be an empty string
to solve them.

- Now by default CWebLogRoute does not render logs in FireBug for ajax calls.
To get logs rendered for ajax calls in FireBug set CWebLogRoute::ignoreAjaxInFireBug to false

- The implementation of CCache::flush() was changed a little. Child classes should now implement
a flushValues() method. If you use any custom cache class with flush functionality, you should
rename the flush method accordingly.

- The prompt and empty options used in CHtml methods will NOT be HTML-encoded anymore. It will now
always convert ">" and "<" into ">" and "lt;", respectively. This should be sufficient in most
cases. But if your application uses some other special characters, or if you allow user inputs
to be used as prompt and empty text labels, please call CHtml::encode() explicitly on these option

Upgrading from v1.1.3
- Zii was merged into Yii so if you are using SVN to keep framework
up to date, you'll need to delete 'framework/zii' and then update it.

Upgrading from v1.1.2
- When using the skin feature, you now need to explicitly configure
the 'enableSkin' property of 'widgetFactory' application component
to be true. Also, if you have configured the 'widgets' property, you
should rename it to be 'skinnableWidgets'. These changes are due to
the introduction of the global widget customization feature.
Please see the guide (the "Theming" section) for more details.

- CAutoComplete is now deprecated and will be removed in Yii 1.2. Consider
using CJuiAutoComplete.

- Now it's not possible to reuse CActiveFinder. So if you have code like this:

$finder = Post::model()->with('comments');
$posts1 = $finder->findAll();

$posts2 = $finder->findAll();

you should rewrite it to:

$posts1 = Post::model()->with('comments');

$posts2 = Post::model()->with('comments');

- The 'condition' declared in the scopes of the related AR classes will now
be put in the 'ON' clause of the JOIN statement when performing relational AR queries.

Upgrading from v1.1.1

Upgrading from v1.1.0
- CHtml::beginForm() will automatically generate hidden fields to represent
the parameters in the query string when the form uses GET method.
To avoid submitting duplicated query parameters, you may use createUrl()
to explicitly specify the action of the form. You may also need to remove
the hidden fields that you previously render for the same purpose.

- The code generated by yiic tool is changed. If you are using yiic tool
to generate new CRUD code on a previously generated skeleton, you are recommended
to run "yiic webapp" again to re-generate the skeleton. Make sure you backup
your work before you do this.

- CMenu now renders the 'active' CSS class for the 'li' tag instead of the
hyperlink tag. You should adjust your CSS code accordingly if you use CMenu
in your application.

- CUrlManager:: parsePathInfo() is changed to be non-static. If you override
this method or your existing code calls this method directly (neither is common),
you need to change your code accordingly.

- CController::forward() will exit the application by default now. If you want
to keep the old behavior, you may pass false as the second parameter.

- The jQuery copy included in the framework has been upgraded to version 1.4.2.
This may cause some incompatibility problems to your existing jQuery code or plugins.
If you want to keep using version 1.3.2, you may do so by configuring
CClientScript::scriptMap property.

- The default theme for JQuery UI widgets was changed from 'smoothness' to 'base'.
If you are using 'smoothness', you will need to manually download this theme from
jqueryui.com and configure the 'theme' property of the JQuery UI widgets accordingly.

Upgrading from v1.1rc
- CRudColumn is renamed as CButtonColumn
- CDataColumn.dataField and dataExpression are renamed as name and value, respectively
- The alias name for the primary table in an AR query is fixed to be 't'

Upgrading from v1.1b

Upgrading from v1.1a
- CSort::attributes is changed. Now the array keys refer to attribute names
and array values refer to virtual attribute definitions. Please read the
API documentation for this property to learn more details. This change will
affect your code only when you explicitly specify this property.

Upgrading from v1.0.x
- Application and module parameter names are changed to be case-sensitive.
In 1.0.x, they are case-insensitive.

- For tabular input, using Field[$i] is not valid anymore. Attribute names
should look like [$i]Field in order to support array-typed fields
(e.g. [$i]Field[$index]).

- Please read the Guide for further details on how to upgrade from v1.0.x to v1.1.

Upgrading from v1.0.12

Upgrading from v1.0.11

Upgrading from v1.0.10

Upgrading from v1.0.9

Upgrading from v1.0.8
- ActiveRecord lazy loading is changed for optimization purpose. Previously,
when lazy loading occurs, the related table will be joined with the primary
table. Now, the related table will be queried without joining the primary table.
As a result, if you are using lazy loading and the corresponding relation
declaration includes reference to the primary table, the query will fail.
To fix this problem, please specify the lazy loading query options with the
actual primary table column values.

Upgrading from v1.0.7
- A directory imported using Yii::import() will have precedence over
any existing include paths. For example, if we import 'application.models.*',
then the corresponding directory will be searched before any other
existing include paths. This also means, a directory imported later will
have precedence over directories imported earlier. Previously, this order
was reversed. This change may affect you if you have several classes with
the same name and they are imported via different directories. You will need
to adjust the import order of these directories to make sure your existing
applications are not broken due to this change.

Upgrading from v1.0.6
- Default named scope will no longer be applied to INSERT, UPDATE and
DELETE queries. It is only applied to SELECT queries. You should be aware
of this change if you override CActiveRecord::defaultScope() in your code.

- The signature of CWebUser::logout() is changed. If you override this method,
you will need to modify your method declaration accordingly.

Upgrading from v1.0.5

Upgrading from v1.0.4
- CWebUser::checkAccess() takes an additional parameter to allow caching
the access check results. If you override this method, you will need to
modify your method declaration accordingly. Because the new parameter will
enable caching the access check results by default, please double check
your code containing this method call to make sure the behavior is as expected.

- CDateParser has been renamed to CDateTimeParser

Upgrading from v1.0.3
- The signature of CWebModule::init() is modified. Its parameter is removed.
If your application uses modules, you have to modify your module class
files accordingly.

Upgrading from v1.0.2
- Controllers that are organized in subdirectories are now referenced
using the ID format "path/to/xyz". Previously it was "path.to.xyz".
If you use "path.to.xyz" in your application, you have to modify it
to "path/to/xyz".

- CHtml::coreScript() is removed. If you used this in your application,
please use the following alternative:


Upgrading from v1.0.1
- Due to the introduction of the scenario-based massive assignment feature,
we removed CActiveRecord:: protectedAttributes(). Please use safeAttributes()
to specify which attributes are safe to be massively assigned.

For more details about scenario-based assignment and validation,
please read the following tutorial section:


- The signature of CModel::validate() has been changed to:

CModel::validate($scenario='', $attributes=null)

That is, the order of the two parameters has been swapped. If your application
contains code that invokes the validate() method (of either a CFormModel
or a CActiveRecord object) with some parameter, please make sure you fix
the parameter order.

- The usage of CActiveRecord::with() and the 'with' option in relations
has been changed. In order to query child relations, we should specify the 'with'
parameter/option like the following now:

Post::model()->with(array('comments', 'author.profile'))->findAll();

Previously, this should be written as:

Post::model()->with(array('comments', 'author'=>'profile'))->findAll();

If your code does not involve child relations (like 'profile' in the above),
nothing needs to be changed.

This change has been introduced in order to support dynamic relational
query options. For example, we can specify that comments be sorted in
descending order (assuming in the relations() method it is specified as
ascending order):

'comments'=>array('order'=>'createTime DESC'),

Upgrading from v1.0.0
- An $scenario parameter is added to both CModel::beforeValidate() and afterValidate().
If you override these methods in your child classes (form models, AR classes),
make sure you change the method signature accordingly.Read more
Resolved: Yii DbConnection failed to open the DB connection: invalid data source name
posted by admin on January 22, 2016
DbConnection failed to open the DB connection: invalid data source name error, after uploading project to live. In local host all is right.

// This is the database connection configuration.
return array(
//'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
// uncomment the following lines to use a MySQL database

'connectionString' => 'abcdefg.mysql.com;dbname=janna',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
Read more
Wiki: Yii - пример создания виджета - widget example - шаблон для контроллераwiki
posted by admin on January 22, 2016
Итак - вот мой контроллер - он лежит в папке /protected/components

/* рассмотрим здесь "параметризированный" виджет*/
class AdminMenuWidget extends CWidget {

/*в общем случаем может
хранить целый массив свойст - нас же интересует
только текущее действие
- чтобы подсветить активный элемент меню*/
public $params = array(
// пусть по умолчанию будет активна ссылка на главную
// следующие два не использую - просто для примера
'parameter 2'=>'value 2',
'parameter 3'=>'value 3',

public function run() {
// передаем данные в представление виджета
$this->render('adminmenu',array('params' => $this->params));

представление контроллера для этого вижжета лежит рядом - а именно так -


и выглядит так:

< ul class="nav nav-pills" >
< li<?php if ($params['action']=='index')
echo ' class="active"' ;
<?php echo CHtml::link('Админка', array('perfomance/index')); ?>
< /li >

< li<?php if ($params['action'] == 'showtickets')
echo ' class="active"' ;
<? php echo CHtml::link('Заявки', array('perfomance/showtickets')); ?>
< /li >

< li<?php if ($params['action'] == 'rebuildroles')
echo ' class="active"' ;
<?php echo CHtml::link('Роли', array('perfomance/rebuildroles')); ?> < /li >

Как отобразить виджет
Это просто - например в представлении некоего контроллера я пишу:

//получаем текущее действие чтобы подсветить активный элемент меню
'action' => Yii::app()->getController()->getAction()->getId(),
Read more
Wiki: Yii 1.1: Archive Yearly and Monthly in Blog systemwiki
posted by admin on January 22, 2016
Hi I had made simple archive system for blog system that can handle tbl_post. I had used simple CDbCriteria not more than that. I know there is more and many better way to this but I think this will give some idea to users to generate new idea or customized or modified this version of code.

//in module define

public $year;
public $month;

In controller controller of view you can use this. I had used here view for testing.

$monthsvalue = array('1'=>'January','2'=>'Feburary','3'=>'March','4'=>'April','5'=>'May','6'=>'June','7'=>'July','8'=>'August','9'=>'September','10'=>'October','11'=>'November','12'=>'December');

$condition = new CDbCriteria;
$condition->select='YEAR(t.createddate) as year'; //declare year in post model model
$condition->order ='createddate DESC';

$yeardataarticle = Post::model()->findAll($condition);

foreach ($yeardataarticle as $ya):
$year =$ya->year;
echo '
echo $year;
$monthcriteria = new CDbCriteria;
$monthcriteria->select ='MONTH(t.createddate) as month'; // declare month in post model
$monthcriteria->condition ='YEAR(t.createddate)=:year';
$months = Post::model()->findAll($monthcriteria);
foreach ($months as $month):

$montth = $month->month;
echo '

foreach($monthsvalue as $key=>$value):

if (!isset(${'printed'.$key.$year})) ${'printed'.$key.$year} = false;


if($key==$montth and !${'printed'.$key.$year}){

echo CHtml::link($value,array('//post/archivepost','year'=>$year,'month'=>$montth));

$postcount = new CDbCriteria;
$postcount->addCondition('MONTH(t.createddate)=:month AND YEAR(t.createddate)=:year');
$postcount->params = array(':month'=>$montth,':year'=>$year);
$count = Post::model()->count($postcount);
echo ' ('.$count.')';



Read more