Archive for category Yii
Yii Class Reference
Posted by mahamuddhk in Yii on February 19, 2012
1
//Default Yii jquery registration
Yii::app()->clientScript->registerCoreScript(‘jquery’);
// Java Script funcion add
if(!Yii::app()->clientScript->isScriptRegistered(“defaultVariable”))
{
Yii::app()->clientScript->registerScript(
‘defaultVariable’,
‘
if(window.location.hash != “”)
{
window.location = window.location.hash.replace(“#”, “”);
}
$(“#mainmenu li a”).click(function(event){
event.preventDefault();
var url = $(this).attr(“href”);
$.ajax({
type : “POST”,
async : false,
url : url,
success : function(response){
window.location.hash = url;
$(“#content”).html(response);
}
});
});
if(window.location.hash != “”)
{
console.log(window.location.hash);
}
‘,
CClientScript::POS_HEAD
);
}
// Check ajax request
if(Yii::app()->request->isAjaxRequest)
{
$this->renderPartial(‘login’,array(‘model’=>$model));
return;
}
2. Modules assets folder link add
public $assetsUrl;
public $defaultController = ‘Personal’;
// import the module-level models and components
$this->setImport(array(
‘profile.models.*’,
‘profile.components.*’,
));
Yii::app()->getClientScript()->registerCSSFile($this->assetsUrl . ‘/css/facebook.alert.css’);
Yii::app()->getClientScript()->registerScriptFile($this->assetsUrl . ‘/js/facebook.alert.js’);
3. Session set (UserIdentity component)
$this->setState(‘firstName’, $user->first_name);
$this->setState(‘lastName’, $user->last_name);
4. Wiget call in view file
//view folder call wiget
$this->widget(‘profile.components.widgets.sections.profileSection’,array());
// view file call partial view files
$this->renderPartial(“application.modules.profile.views.personal._basic”,$info);
5.
// CArrayDataProvider
$contactdata[] = array(“contact_id” => $id[“contact_id”], ‘contact_meta’ => $respectiveMeta);
$dataProvider = new CArrayDataProvider($contactdata, array(‘keyField’ => ‘contact_id’, ‘pagination’ => array(‘pageSize’ => 5)));
$this->render(‘addContact’, array(
‘dataProvider’ => $dataProvider,
));
//call view file addContact.php
$this->widget(‘zii.widgets.CListView’, array(
‘dataProvider’=>$dataProvider,
‘itemView’=>’_view’,
));
// _view.php
print “
DAO Command
Posted by mahamuddhk in Yii on February 18, 2012
Yii::app()->db->createCommand($sql)->execute() // execute the non-query SQL
Yii::app()->db->createCommand($sql)->query() //execute a query SQL
Yii::app()->db->createCommand($sql)->queryAll() //query and return all rows of result
Yii::app()->db->createCommand($sql)->queryRow() // query and the first row of result
Yii::app()->db->createCommand($sql)->queryColumn() // query and return the first column of result