add yii snippets

This commit is contained in:
raydeal 2012-11-22 22:25:28 +01:00
parent 28d23a390b
commit e7d5824daa
2 changed files with 548 additions and 0 deletions

248
snippets/yii-chtml.snippets Normal file
View File

@ -0,0 +1,248 @@
#--------------------Yii CHtml---------------------------------
#Yii CHtml::radioButton
snippet yhrb
echo CHtml::radioButton('${1:name}', ${2:false},array(${3:optionName}=>${4:optionValue} );
#Yii CHtml::asset
snippet yhass
echo CHtml::asset('${1:path}');
#Yii CHtml::activeLabelEx
snippet yhale
echo CHtml::activeLabelEx(${1:model}, '${2:attribute}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::encodeArray
snippet yheca
echo CHtml::encodeArray(array(${1}));
#Yii CHtml::normalizeUrl
snippet yhnurl
echo CHtml::normalizeUrl(array('${1}'));
#Yii CHtml::resetButton
snippet yhsb
echo CHtml::submitButton('${1:label}',array('${2:optionName}'=>${3:optionValue}));
#Yii CHtml::linkButton
snippet yhlinkb
echo CHtml::linkButton('${1:lable}',array('${2:optionName}'=>${3:optionValue}));
#Yii CHtml::activeTextArea
snippet yhata
echo CHtml::activeTextArea(${1:model}, '${2:attribute}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::ajaxButton
snippet yhajb
echo CHtml::ajaxButton('${1:label}', '${2:url}',array('${3:ajaxOptionName}'=>${4:ajaxOptionValue}),array('${5:optionName}'=>${6:optionValue}));
#Yii CHtml::activeId
snippet yhai
echo CHtml::activeId(${1:model}, '${2:attribute}');
#Yii CHtml::activeCheckBox
snippet yhacb
echo CHtml::activeCheckBox(${1:model}, '${2:attribute}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::activeHiddenField
snippet yhahf
echo CHtml::activeHiddenField(${1:model}, '${2:attribute}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::encode
snippet yhec
echo CHtml::encode(${1:text});
#Yii CHtml::metaTag
snippet yhmtag
echo CHtml::metaTag('${1:content}', '${2:name}', '${3:httpEquiv}',array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::dropDownList
snippet yhddl
echo CHtml::dropDownList('${1:name}', '${2:select}', array(${3}),array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::listBox
snippet yhlb
echo CHtml::listBox('${1:name}', '${2:select}',array(${3}),array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::script
snippet yhjs
echo CHtml::script('${1:test}');
#Yii CHtml::ajax
snippet yhaj
echo CHtml::ajax(array(${1}));
#Yii CHtml::textField
snippet yhtf
echo CHtml::textField('${1:name}', '${2:value}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::activePasswordField
snippet yhapf
echo CHtml::activePasswordField(${1:model}, '${2:attribute}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::listData
snippet yhld
echo CHtml::listData(array(${1}),'${2:valueField}', '${3:textField}','${4:groupField}');
#Yii CHtml::mailto
snippet yhmt
echo CHtml::mailto('${1:text}', '${2:email}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::image
snippet yhimg
echo CHtml::image('${1:src}', '${2:alt}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::activeListBox
snippet yhalb
echo CHtml::activeListBox(${1:model}, '${2:attribute}', array(${3}),array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::activeFileField
snippet yhaff
echo CHtml::activeFileField(${1:model}, '${2:attribute}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::closeTag
snippet yhct
echo CHtml::closeTag('${1:tag}');
#Yii CHtml::activeInputField
snippet yhaif
echo CHtml::activeInputField('${1:type}', ${2:model}, '${3:attribute}',array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::scriptFile
snippet yhjsf
echo CHtml::scriptFile('${1:url}');
#Yii CHtml::radioButtonList
snippet yhrbl
echo CHtml::radioButtonList('${1:name}', ${2:select}, array(${3}),array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::cssFile
snippet yhcssf
echo CHtml::cssFile('${1:url}','${2:media}');
#Yii CHtml::error
snippet yherr
echo CHtml::error(${1:model}, '${2:attribute}');
#Yii CHtml::passwordField
snippet yhpf
echo CHtml::passwordField('${1:name}', '${2:value}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::hiddenField
snippet yhhf
echo CHtml::hiddenField('${1:name}', '${2:value}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::cdata
snippet yhc
echo CHtml::cdata(${1:text});
#Yii CHtml::link
snippet yhlink
echo CHtml::link('${1:text}',array(${2}),array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::errorSummary
snippet yherrs
echo CHtml::errorSummary(${1:model},'${2:headerHtml}','${3:footerHtml}');
#Yii CHtml::tag
snippet yht
echo CHtml::tag('${1:tag}',array('${2:optionName}'=>${3:optionValue}),${4:false},${5:true});
#Yii CHtml::ajaxLink
snippet yhajl
echo CHtml::ajaxLink('${1:label}', '${2:url}',array('${3:ajaxOptionName}'=>${4:ajaxOptionValue}),array('${5:optionName}'=>${6:optionValue}));
#Yii CHtml::label
snippet yhlabel
echo CHtml::label('${1:label}', '${2:for}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::activeName
snippet yhan
echo CHtml::activeName(${1:model}, '${2:attribute}');
#Yii CHtml::statefulForm
snippet yhsform
echo CHtml::statefulForm(array('${1}'), '${2:post}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::fileField
snippet yhff
echo CHtml::fileField('${1:name}', '${2:value}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::activeTextField
snippet yhatf
echo CHtml::activeTextField(${1:model}, '${2:attribute}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::css
snippet yhcss
echo CHtml::css('${1:test}','${2:media}');
#Yii CHtml::imageButton
snippet yhimgb
echo CHtml::imageButton('${1:src}',array('${2:optionName}'=>${3:optionValue}));
#Yii CHtml::ajaxSubmitButton
snippet yhajsb
echo CHtml::ajaxSubmitButton('${1:label}', '${2:url}',array('${3:ajaxOptionName}'=>${4:ajaxOptionValue}),array('${5:optionName}'=>${6:optionValue}));
#Yii CHtml::button
snippet yhb
echo CHtml::button('${1:label}',array('${2:optionName}'=>${3:optionValue}));
#Yii CHtml::listOptions
snippet yhlo
echo CHtml::listOptions('${1:selection}', array(${2}), array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::activeCheckBoxList
snippet yhacbl
echo CHtml::activeCheckBoxList(${1:model}, '${2:attribute}', array(${3}),array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::openTag
snippet yhot
echo CHtml::openTag('${1:tag}', array('${2:optionName}'=>${3:optionValue}));
#Yii CHtml::checkBox
snippet yhcb
echo CHtml::checkBox('${1:name}', ${2:false}, array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::textArea
snippet yhta
echo CHtml::textArea('${1:name}', '${2:value}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::linkTag
snippet yhlinkt
echo CHtml::linkTag('${1:relation}', '${2:type}', '${3:href}', '${4:media}',array('${5:optionName}'=>${6:optionValue}));
#Yii CHtml::resetButton
snippet yhrsb
echo CHtml::resetButton('${1:label}',array('${2:optionName}'=>${3:optionValue}));
#Yii CHtml::activeRadioButtonList
snippet yharbl
echo CHtml::activeRadioButtonList(${1:model}, '${2:attribute}', array(${3}),array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::checkBoxList
snippet yhcbl
echo CHtml::checkBoxList('${1:name}', ${2:select}, array(${3}),array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::form
snippet yhform
echo CHtml::form(array('${1}'), '${2:post}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::beginForm
snippet yhbeform
echo CHtml::beginForm(array('${1}'), '${2:post}',array('${3:optionName}'=>${4:optionValue}));
${5}
echo CHtml::endForm();
#Yii CHtml::activeDropDownList
snippet yhaddl
echo CHtml::activeDropDownList(${1:model}, '${2:attribute}', array(${3}),array('${4:optionName}'=>${5:optionValue}));
#Yii CHtml::activeRadioButton
snippet yharb
echo CHtml::activeRadioButton(${1:model}, '${2:attribute}',array('${3:optionName}'=>${4:optionValue}));
#Yii CHtml::activeLabel
snippet yhal
echo CHtml::activeLabel(${1:model}, '${2:attribute}',array('${3:optionName}'=>${4:optionValue}));

300
snippets/yii.snippets Normal file
View File

@ -0,0 +1,300 @@
#Yii session offset
snippet yse
Yii::app()->session['${1}'];
#Yii renderDynamic
snippet yrd
$this->renderDynamic('${1:callback}');
#Yii set cache
snippet ycas
Yii::app()->cache->set('${1:key}', ${2:value}, ${3:expire}, new C${4:}CacheDependency(${5}));
#Yii Add cache
snippet ycad
Yii::app()->cache->add('${1:key}', ${2:value}, ${3:expire}, new C${4}CacheDependency(${5}));
#Yii register CSS file
snippet yregcf
Yii::app()->clientScript->registerCssFile('${1:file}');
#Yii requestType
snippet yreqtype
Yii::app()->request->requestType
#Yii isAjaxRequest
snippet yisajax
Yii::app()->request->isAjaxRequest
#Yii translate
snippet yt
Yii::t('${1:category}', '${2:message}',array(${3}));
#Yii register CSS
snippet yregc
Yii::app()->clientScript->registerCss('${1:id}', '${2}');
#Yii log
snippet ylog
Yii::log('${1:msg}', '${2:info}');
#Yii userHostAddress
snippet yuserip
YYii::app()->request->userHostAddress
#Yii register script file
snippet yregsf
Yii::app()->clientScript->registerScriptFile('${1:scriptUrl}', CClientScript::POS_${2:END});
#Yii CLinkPager
snippet ylinkpager
$this->widget('CLinkPager', array('pages'=>$pages,'header'=>'${1}'}))
#Yii CJSON::encode
snippet yjec
CJSON::encode(${1:text});
#CActiveDataProvider
snippet yadp
$dataProvider = new CActiveDataProvider('${1}', array(
'criteria' => array(
'condition' => '${2}',
'order' => '${3}',
'with' => array('${4}')
),
//'pagination' => false,
'pagination' => array(
'pageSize'=>${5},
),
));
${6}
// $dataProvider->getData() will return a list of Post objects
#Yii renderDynamic internal
snippet yrdi
$this->renderDynamic('${1:callback}', array('${2:key}'=>${3:value}));
#Yii register script
snippet yregs
Yii::app()->clientScript->registerScript('${1:id}', '${2}', CClientScript::POS_${3:READY});
#Yii Flush cache
snippet ycaf
Yii::app()->cache->flush();
#Yii Yii::app()->request->cookies
snippet yco
Yii::app()->request->cookies['${1}']
#Yii user->
snippet yuser
Yii::app()->user->${1}
#Yii refresh
snippet yrf
$this->refresh();
#Yii import
snippet yimp
Yii::import('${1}');
#Yii trace
snippet ytrace
Yii::trace('${1:msg}');
#Yii params
snippet ypar
Yii::app()->params['${1}']
#Yii isPostRequest
snippet yispost
Yii::app()->request->isPostRequest
#Yii IF isAjaxRequest
snippet yifisajax
if(Yii::app()->request->isAjaxRequest == TRUE)
{
${1}
}
#Yii Yii::app()->cache->delete
snippet ydelcache
Yii::app()->cache->delete('${1:key}');
#Yii render view
snippet yr
$this->render('${1:view}',array('${2:key}'=>${3:value}));
#Yii redirect
snippet yre
$this->redirect(array('${1:controller}/${2:action}'));
#Yii Get cache
snippet ycag
Yii::app()->cache->get('${1:key}');
#Yii render text
snippet yrt
$this->renderText('${1}');
#Yii render partial
snippet yrp
$this->renderPartial('${1:view}',array('${2:key}'=>${3:value}));
#----------------Yii Model-----------------------------
#Yii Model count
snippet ycountm
${1:ModelName}::model()->count(${2:condition}, array('${3:key}'=>${4:value}));
#Yii Model countBySql
snippet ycountbs
${1:ModelName}::model()->countBySql(${2:sql},array('${3:key}'=>${4:value}));
#Yii Model updateAll
snippet yupdatea
${1:ModelName}::model()->updateAll(${2:array('attributes')}, ${3:condition},array('${4:key}'=>${5:value}));
#Yii Model updateByPk
snippet yupdatebp
${1:ModelName}::model()->updateByPk(${2:pk}, ${3:array('attributes')}, ${4:condition},array('${5:key}'=>${6:value}));
#Yii Model deleteAll
snippet ydela
${1:ModelName}::model()->deleteAll(${2:condition},array('${3:key}'=>${4:value}));
#Yii Model deleteByPk
snippet ydelbp
${1:ModelName}::model()->deleteByPk(${2:pk}, ${3:condition}, array('${4:key}'=>${5:value}));
#Yii Model find
snippet yfind
${1:ModelName}::model()->find(${2:condition},array('${3:key}'=>${4:value}));
#Yii Model findAll
snippet yfinda
${1:ModelName}::model()->findAll(${2:condition},array('${3:key}'=>${4:value}));
#Yii Model findByPk
snippet yfindbp
${1:ModelName}::model()->findByPk(${2:pk}, ${3:condition}, array('${4:key}'=>${5:value}));
#Yii Model findAllByPk
snippet yfindabp
${1:ModelName}::model()->findAllByPk(${2:pk}, ${3:condition},array('${4:key}'=>${5:value}));
#Yii Model findBySql
snippet yfindbs
${1:ModelName}::model()->findBySql(${2:sql}, array('${3:key}'=>${4:value}));
#Yii Model findAllByAttributes
snippet yfindaba
${1:ModelName}::model()->findAllByAttributes(array('${2:attributeName}'=>${3:attributeValue}), ${4:condition}, array('${5:key}'=>${6:value}));
#Yii Model exists
snippet yexists
${1:ModelName}::model()->exists(${2:condition}, array('${3:key}'=>${4:value}));
#Yii Create model class
snippet ymodel
<?php
class ${1:ModelName} extends ${2:CActiveRecord}
{
/**
* Returns the static model of the specified AR class.
* @return CActiveRecord the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return '${3:table_name}';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
return array(
);
}
/**
* @return array relational rules.
*/
public function relations()
{
return array(
);
}
/**
* @return array customized attribute labels (name=&gt;label)
*/
public function attributeLabels()
{
return array(
);
}
}
#------------Yii Controller------------------------------------
#Yii Create controller class
snippet ycontroller
<?php
/**
* ${1:}
*/
class ${2:Site}Controller extends ${3:CController}
{
public function action${4:Index}()
{
${5}
}
// -----------------------------------------------------------
// Uncomment the following methods and override them if needed
/*
public function filters()
{
// return the filter configuration for this controller, e.g.:
return array(
'inlineFilterName',
array(
'class'=>'path.to.FilterClass',
'propertyName'=>'propertyValue',
),
);
}
public function actions()
{
// return external action classes, e.g.:
return array(
'action1'=>'path.to.ActionClass',
'action2'=>array(
'class'=>'path.to.AnotherActionClass',
'propertyName'=>'propertyValue',
),
);
}
*/
}
#Yii Create controller action method
snippet yact
public function action${1:Index}(${2:params})
{
${3}
}