aboutsummaryrefslogtreecommitdiff
path: root/vim/bundle/vim-snippets/snippets/yii.snippets
blob: 1f9fc6f78b4c7eb6391720ee00b38977f55788ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#Yii session offset
snippet yse
	Yii::app()->session['${0}'];

#Yii renderDynamic
snippet yrd
	$this->renderDynamic('${0:callback}');

#Yii set cache
snippet ycas
	Yii::app()->cache->set('${1:key}', ${2:value}, ${3:expire}, new C${4:}CacheDependency(${0}));

#Yii Add cache
snippet ycad
	Yii::app()->cache->add('${1:key}', ${2:value}, ${3:expire}, new C${4}CacheDependency(${0}));

#Yii register CSS file
snippet yregcf
	Yii::app()->clientScript->registerCssFile('${0: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(${0}));

#Yii register CSS
snippet yregc
	Yii::app()->clientScript->registerCss('${1:id}', '${0}');

#Yii log
snippet ylog
	Yii::log('${1:msg}', '${0:info}');

#Yii userHostAddress
snippet yuserip
	YYii::app()->request->userHostAddress

#Yii register script file
snippet yregsf
	Yii::app()->clientScript->registerScriptFile('${1:scriptUrl}', CClientScript::POS_${0:END});

#Yii CLinkPager
snippet ylinkpager
	$this->widget('CLinkPager', array('pages'=>$pages,'header'=>'${0}'}))

#Yii CJSON::encode
snippet yjec
	CJSON::encode(${0:text});

#CActiveDataProvider
snippet yadp
	$dataProvider = new CActiveDataProvider('${1}', array(
	  'criteria' => array(
			'condition' => '${2}',
			'order' => '${3}',
			'with' => array('${4}')
		),
	//'pagination' => false,
		'pagination' => array(
			'pageSize'=>${5},
		),
	));
	${0}
	// $dataProvider->getData() will return a list of Post objects

#Yii renderDynamic internal
snippet yrdi
	$this->renderDynamic('${1:callback}', array('${2:key}'=>${0:value}));

#Yii register script
snippet yregs
	Yii::app()->clientScript->registerScript('${1:id}', '${2}', CClientScript::POS_${0:READY});

#Yii Flush cache
snippet ycaf
	Yii::app()->cache->flush();

#Yii Yii::app()->request->cookies
snippet yco
	Yii::app()->request->cookies['${0}']

#Yii user->
snippet yuser
	Yii::app()->user->

#Yii refresh
snippet yrf
	$this->refresh();

#Yii import
snippet yimp
	Yii::import('${0}');

#Yii trace
snippet ytrace
	Yii::trace('${0:msg}');

#Yii params
snippet ypar
	Yii::app()->params['${0}']

#Yii isPostRequest
snippet yispost
	Yii::app()->request->isPostRequest

#Yii IF isAjaxRequest
snippet yifisajax
	if(Yii::app()->request->isAjaxRequest == TRUE)
	{
		${0}
	}

#Yii Yii::app()->cache->delete
snippet ydelcache
	Yii::app()->cache->delete('${0:key}');

#Yii render view
snippet yr
	$this->render('${1:view}',array('${2:key}'=>${0:value}));

#Yii redirect
snippet yre
	$this->redirect(array('${1:controller}/${0:action}'));

#Yii Get cache
snippet ycag
	Yii::app()->cache->get('${0:key}');

#Yii render text
snippet yrt
	$this->renderText('${0}');

#Yii render partial
snippet yrp
	$this->renderPartial('${1:view}',array('${2:key}'=>${0:value}));

#----------------Yii Model-----------------------------
#Yii Model count
snippet ycountm
	${1:ModelName}::model()->count(${2:condition}, array('${3:key}'=>${0:value}));

#Yii Model countBySql
snippet ycountbs
	${1:ModelName}::model()->countBySql(${2:sql},array('${3:key}'=>${0:value}));

#Yii Model updateAll
snippet yupdatea
	${1:ModelName}::model()->updateAll(${2:array('attributes')}, ${3:condition},array('${4:key}'=>${0:value}));

#Yii Model updateByPk
snippet yupdatebp
	${1:ModelName}::model()->updateByPk(${2:pk}, ${3:array('attributes')}, ${4:condition},array('${5:key}'=>${0:value}));

#Yii Model deleteAll
snippet ydela
	${1:ModelName}::model()->deleteAll(${2:condition},array('${3:key}'=>${0:value}));

#Yii Model deleteByPk
snippet ydelbp
	${1:ModelName}::model()->deleteByPk(${2:pk}, ${3:condition}, array('${4:key}'=>${0:value}));

#Yii Model find
snippet yfind
	${1:ModelName}::model()->find(${2:condition},array('${3:key}'=>${0:value}));

#Yii Model findAll
snippet yfinda
	${1:ModelName}::model()->findAll(${2:condition},array('${3:key}'=>${0:value}));

#Yii Model findByPk
snippet yfindbp
	${1:ModelName}::model()->findByPk(${2:pk}, ${3:condition}, array('${4:key}'=>${0:value}));

#Yii Model findAllByPk
snippet yfindabp
	${1:ModelName}::model()->findAllByPk(${2:pk}, ${3:condition},array('${4:key}'=>${0:value}));

#Yii Model findBySql
snippet yfindbs
	${1:ModelName}::model()->findBySql(${2:sql}, array('${3:key}'=>${0:value}));

#Yii Model findAllByAttributes
snippet yfindaba
	${1:ModelName}::model()->findAllByAttributes(array('${2:attributeName}'=>${3:attributeValue}), ${4:condition}, array('${5:key}'=>${0:value}));

#Yii Model exists
snippet yexists
	${1:ModelName}::model()->exists(${2:condition}, array('${3:key}'=>${0: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 '${0: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}()
		  {
		      ${0}
		  }

		// -----------------------------------------------------------
		// 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})
	{
		${0}
	}