/
XTabularInputAction.php
74 lines (71 loc) · 1.67 KB
/
XTabularInputAction.php
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
<?php
/**
* XTabularInputAction action
*
* This action (partial)renders tabular input for XTabularInput widget
*
* The following shows how to use XTabularInputAction action.
*
* First set up the action on RequestController actions() method:
* <pre>
* return array(
* 'addFields'=>array(
* 'class'=>'ext.actions.XTabularInputAction',
* 'modelName'=>'Person',
* 'viewName'=>'/person/_inputFields',
* ),
* );
* </pre>
*
* And then XTabularInput widget can be configured as follows:
* <pre>
* $this->widget('ext.widgets.tabularinput.XTabularInput',array(
* 'models'=>$persons,
* 'inputView'=>'_inputFields',
* 'inputUrl'=>$this->createUrl('request/addFields'),
* ));
* </pre>
*
* Example of _inputFields partial view:
* <pre>
* echo CHtml::activeLabel($model,"[$index]firstname");
* echo CHtml::activeTextField($model,"[$index]firstname");
* echo CHtml::error($model,"[$index]firstname");
* </pre>
*
* @author Erik Uus <erik.uus@gmail.com>
* @version 1.0.0
*/
class XTabularInputAction extends CAction
{
/**
* @var string name of the model class.
*/
public $modelName;
/**
* @var string name of the partial view.
*/
public $viewName;
/**
* Runs the action.
*/
public function run()
{
if(Yii::app()->request->isAjaxRequest && isset($_GET['index']))
{
$this->getController()->renderPartial($this->viewName, array(
'model'=>$this->getModel(),
'index'=>$_GET['index']
));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
/**
* @return CActiveRecord
*/
protected function getModel()
{
return CActiveRecord::model($this->modelName);
}
}