我对 symfony 还是很陌生,所以如果这是一个愚蠢的问题,我很抱歉。我将 symfony 1.4 与 Doctrine 一起使用。我的同事编写了一个 JavaScript 来从我们的客户端小部件向我们的服务器生成报告:
$j.post(serverpath, {widget_id:widget_id, user_id:user_id, object_id:object_id, action_type:action_type, text_value:stuff_to_report });
我在 routing.yml 中创建了一个路由来接收这个请求:
widget_report:
url: /widget/report/
options: {model: ReportClass, type: object }
param: {module: widget, action: reports}
requirements:
object_id: \d+
user_id: \d+
action_type: \d+
sf_method: [post]
我在 actions.class.php 中创建了一个动作来处理请求:
public function executeReports(sfWebRequest $request) {
foreach($request->getParameterHolder()->getAll() as $param => $val) {
// $param is the query string name, $val is its value
$this->logMessage("executeReports: $param is $val");
}
try {
[...]
$actionHistory->setUserId($request->getParameter('user_id', 1));
$this->logMessage("executeReports success: ");
} catch {
[...]
}
}
我的日志文件报告:
Jul 20 18:51:35 symfony [info] {widgetActions} Call "widgetActions->executeReports()"
Jul 20 18:51:35 symfony [info] {widgetActions} executeReports: module is widget
Jul 20 18:51:35 symfony [info] {widgetActions} executeReports: action is reports
Jul 20 18:51:35 symfony [info] {widgetActions} executeReports success:
我一定在这里错过了一步。在传递 URL 中的变量(当然,在路由中指定变量)时,我们已经完成了这项工作,但由于各种原因,我们希望使用 POST 来代替。
为什么我的 POST 参数无法在 actions.class.php 中访问?