简体   繁体   中英

How to pass multiple variables from twig to symfony controller action with render

I am attempting to render an action from within twig to list results of a table. The first variable is passing through fine and I am getting the list populated, but the second variable is not arriving.

{% render 'RiskAssessmentBundle:Assessment:assessmentlist' with {'offenderId': entity.getId, 'assessmentStatus': 'Complete' } %}

Above is the render call in my twig template. offenderId is arriving with a value.

    /**
 * List widget
 *
 * @param int $offenderId   id of the offender
 * @param string $assessmentStatus   const value of desired status
 *
 * @Template("RiskAssessmentBundle:Assessment:assessmentlist.html.twig")
 */
public function assessmentlistAction($offenderId, $assessmentStatus = null)
{
    var_dump($assessmentStatus);
    $em = $this->getDoctrine()->getEntityManager();

    $offender = $em->getRepository('RiskOffenderBundle:Offender')->find($offenderId);

    if (is_null($assessmentStatus)) {
        $assessments = $em->getRepository('RiskAssessmentBundle:Assessment')
            ->findAllByActive(true, $offenderId, 5);
    } else {
        $assessments = $em->getRepository('RiskAssessmentBundle:Assessment')
            ->findAllByStatus($assessmentStatus, $offenderId, 5);
    }

    return array(
        'assessments' => $assessments,
        'offender' => $offender,
    );
}

Above is the action called. The var_dump of the $assessmentStatus is always NULL. I am new to symfony, but every piece of documentation I can find makes me think this should work. Anyone have a clue what I am doing wrong?

The above code works perfectly. We have an extension system running and the entire twig template had been extended. The render I modified was not the render being called. Once I modified the other template it all works perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM