Yii1-清理before操作中的GET参数
我试图找到是否可以使用控制器中的beforeAction访问注入参数 例如,控制器中的每个操作都接受type参数,我需要对其进行清理:Yii1-清理before操作中的GET参数,yii,Yii,我试图找到是否可以使用控制器中的beforeAction访问注入参数 例如,控制器中的每个操作都接受type参数,我需要对其进行清理: public function actionGetCustomPaymentsChunk($type) { $type = TextUtil::sanitizeString($type); // Get filter data $filter = FilterHelper::getFilterData();
public function actionGetCustomPaymentsChunk($type) {
$type = TextUtil::sanitizeString($type);
// Get filter data
$filter = FilterHelper::getFilterData();
// Initialize components
$totalCostPayableComponent = new TotalCostPayableComponent($filter);
// Get chunk data
$data = $totalCostPayableComponent->getCustomPaymentChunk($type);
// Return content to client side
$this->renderPartial('/partials/_payable_cost_chunk', array(
'data' => $data,
'route' => 'totalCostPayable/getCustomPaymentsGrid',
'type' => $type,
'paymentType' => 'Custom',
));
}
}
这可能做到吗(我正在努力避免重复)?你应该能够做到,你尝试了什么 假设
$type
通过GET传递,您可以在beforeAction
中对其进行修改,修改后的值将应用于目标操作,请求如下
http://myhost.com/route/test?type=something
在此控制器中的任何操作中使用以下命令,$type=“foo”
protected function beforeAction($action)
{
if (isset($_GET['type'])) {
$_GET['type'] = 'foo';
}
...
return parent::beforeAction($action);
}
public function actionTest($type)
{
# $type === 'foo'
...
}
更改beforeAction中的操作以满足您的任何要求。这工作正常,对我来说有点太冒险了。谢谢你的帮助:)。