difference betwern require __DIR__ and __DIR__ - yii

i a new yii developer and i do not understand one thing. In common/config/params.php file, i have following code:
<?php
return [
'adminEmail' => 'admin#example.com',
'supportEmail' => 'support#example.com',
'user.passwordResetTokenExpire' => 3600,
'regions' => require __DIR__ . '/region.php',
];
what is the difference between 'regions' => require __DIR__ . '/region.php', and 'regions' => __DIR__ . '/region.php',

In 'regions' => __DIR__ . '/region.php' regions will contain a string variable (path to region.php based on current dir)
In 'regions' => require __DIR__ . '/region.php' regions will contain an object of region.php class

Related

How to print YII Logger without Yii::app()->end

I am using YII 1.0 logger but i am not able to print YII logs without Yii::app()->end.
Below is my test program :
$test = 123;
if($test){
Yii::log('Test', CLogger::LEVEL_INFO, "This is for testing");
}
Below is my configuration settings :
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'class' => 'CFileLogRoute',
'levels' => 'trace, info, error, warning, vardump',
),
array(
'class' => 'CWebLogRoute',
'enabled' => YII_DEBUG,
'levels' => 'error, warning, trace, notice',
'categories' => 'application',
'showInFireBug' => true,
),
array(
'class'=>'CFileLogRoute',
'logFile'=>'custom.log',
'categories'=>'custom.*',
),
),
),
Is there something wrong in my code ?
Thanks in advance.
You may learn CLogger api for more useful information.
Yii::getLogger()->flush(true);
Also hope it helps:
http://www.yiiframework.com/forum/index.php/topic/8671-force-message-routing-before-the-end-of-the-application/
http://www.yiiframework.com/forum/index.php?/topic/8158-logger-and-flush-problem/
Messages can be logged using yii::log,
syntax:
Yii::log($message, $level, $category);
example:
Yii::log("This is for testing","error","custom");

How to Configure yiibooster

thanks for reading, i am wondering how to install
YiiBooster
, do i need to install
YiiBootstrap
first ?
I want to install it by hand , is it enough to extract it to extensions folder and than configure the main.php or is there something i am missing ?
Also how can i make this point to the right path
'booster' => array(
'class' => 'path.alias.to.booster.components.Booster',
),
You don't need to install bootstrap. Yiibooster includes all bootstrap files it needs. Just download Yiibooster, unpack to the extension folder and add the below to your main config file,
'booster' => array(
'class' => 'ext.yiibooster.components.Bootstrap',
'responsiveCss' => true,
),
Then add the following in the preload section of the config,
'booster',
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
// preloading 'log' component
'preload'=>array('log','bootstrap'),
// application components
'components'=>array(
//
'bootstrap' => array(
'class' => 'bootstrap.components.Booster',
'responsiveCss' => true,
),
Rename folder name yiibooster-4.0.1 to yiibooster
Step 1:
'preload' => array(
'booster',
),
Step 2:
'booster' => array(
'class' => 'ext.yiibooster.components.Booster',
'responsiveCss' => true,
),
Note: Booster this Class name
//Use view file
<?php
$this->widget('booster.widgets.TbExtendedGridView',
array(
'filter' => $model,
'fixedHeader' => true,
'type' => 'striped bordered',
'headerOffset' => 40,
// 40px is the height of the main navigation at bootstrap
'dataProvider' =>$model->search(),
'template' => "{items}",
'columns' => array(
'id',
'firstname',
'lastname',
'age',
'address',
'email',
),
)
);
?>

friendly urls with yii history.js

currently when using history.js in my view my url looks like this
http://localhost/dev/clubs/
when i sort OR go to the next page it adds the modulesName, Clubs and relationTable to the url
http://localhost/dev/modulesName/clubs/index/?Clubs_sort=relationTable.Make.desc&page=2
how would i make it look nicer? Say something like this maybe (without the /index/ too)
http://localhost/dev/clubs/?sort=Make.desc&page=2
currently in my modules controller i have this
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Clubs', array(
'criteria' => array(
'with' =>'Make',
),
'sort'=>array(
'defaultOrder'=>'Make.Make ASC',
'attributes'=>array(
'Make.Make'=>array(
'asc'=>'Make.Make',
'desc'=>'Make.Make DESC',
)
)
),
//for friendly url when history,js is enabled
'pagination'=>array(
'pageVar'=>'page'
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
and in my url manager i have this
'<action:(clubs|finance)>' => 'modulesName/<action>',
any idea how to fix this? Thanks
You can use the url manager to do this in config
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'mypagename' => 'modulename/controllername/actionname'
//any number of url's can be changed from here and no js is needed
)
),
Here I can give any name as my page name and as many as url's I like

yiibooster show already added record in select2 widget

I have already added data using select2 yiibooster widget but how i can update data using select2 widget.
how i show already added records in yiibooster select2 widget
<?php
echo $form->labelEx($model, 'measurement');
$this->widget(
'bootstrap.widgets.TbSelect2', array(
'name' => 'measures[]',
'data' => Ingredient::getmeasurementhere(),
'htmlOptions' => array(
'multiple' => 'multiple',
'class' => 'span3',
'id' => 'select1li_id'
),
//'events' => array('change' => 'js:getsubcategories')
)
);
?>
i am getting data using Ingredient::getmeasurementhere() function how i fetch this using update or write new function but how to show in select2 ?
Thanks in advance

Cakephp password change not working

I'm using cakephp 2.1, where I'm trying to change the password of an user through a link which the user will receive when a forgot password request is make.
The link looks something like this
../myApp/users/change_password/1
I'm passing the user id in the link. i.e, 1 as in above.
The view i.e, change_password.ctp is as below
<?php echo $this->Form->create('User', array('controller' => 'users', 'action' => 'change_password', 'class' => 'well')); ?>
<?php echo $this->Form->input('User.id',array('value' => $this->params['pass'][0],'type'=>'hidden')); ?>
<?php echo $this->Form->label('password', 'Password', array('class' => 'control-label')); ?>
<?php echo $this->Form->password('password', array('class' => 'span3', 'type' => 'password')); ?>
<?php echo $this->Form->error('password', null , array('wrap' => 'span', 'class' => 'help-inline')); ?>
<?php echo $this->Form->submit('Change Password', array('class' => 'btn')); ?>
<?php echo $this->Form->end(); ?>
And the controller is as follows
public function change_password() {
if($this->request->is('post')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash('Password has been changed.', 'default/flash_success');
$this->redirect(array('controller' => 'movies', 'action' => 'index'));
} else {
$this->Session->setFlash('Password could not be changed.', 'default/flash_error');
$this->redirect(array('controller' => 'movies', 'action' => 'index'));
}
}
}
But I'm not able to save the password.
So if i just change the user id in the url, i can change the password of an other user?
/myApp/users/change_password/2
That is not secure at all. You should reconsider an other approach.
However, the answer for your question is:
You are probably not able to change the password because the data is not validated.
Do you have setup validation rules in the User.php model? If yes, you must unset the validation rules before saving the User.
Example: unset($this->User->validate['username']);
For more information about model validation, read the documentation