请在下面的模板部分查看我的问题:
表格(showSuccess):
<?php echo form_tag('job/salarySubmit') ?>
<input type="hidden" name="job_id" value="<?php echo $job->getId(); ?>">
<input type="submit" value="View Salary">
</form>
动作:
public function executeSalarySubmit(sfWebRequest $request)
{
$this->forward404Unless($request->isMethod('post'));
$param = array('job_id' => $request->getParameter('job_id'), );
$this->redirect('job/salary?'.http_build_query($param));
}
public function executeSalary(sfWebRequest $request)
{
$this->object_id = $request->getParameter('job_id');
$this->salary = $this->getRoute()->getObject();
}
模板(salarySuccess.php):
<?php echo $object_id; ?> // returns correct job_id: 6100, but when I try to access the object's other getters (example: echo $object_id->getName(), I get "Fatal error: Call to a member function getName() on a non-object"
<?php echo $salary->getName(); ?> //works, but it gets the wrong name. It's returning the first job in my DB with an ID of "1" which is not correct... it needs to be 6100
路由:
job_salary:
url: /job/salary/:job_id
param: { module: job, action: salary }
class: sfDoctrineRoute
options: { model: Job, type: object }
requirements:
id: \d+
sf_method: [GET]
答案 0 :(得分:1)
在模板变量上使用var_dump()
。
您将看到$object_id
不是对象(它是非对象,如错误消息所示)。 $object_id
很可能是字符串或整数,其值必须为“6100”。
$salary
不是您要查找的对象,因为sfDoctrineRoute查找名为id
的参数,并在routing.yml中将其命名为job_id(这很奇怪,因为您将其命名为{{1}在这条路线的要求中。