1

I am trying to get the orgid from the form so I can pass it to the Ormember:test Controller:Action as outlined in my.html.twig using:

{{ render(controller(
    'CompanyNameofBundle:OrgMember:test', {'orgid':1})) }}

Where for now there is a static "1" but I would like to be a variable.

my.html.twig

{% extends 'CompanyNameofBundle::base.html.twig' %}

{% block body -%}
    <h1>Organization Edit</h1>

    {{ form(edit_form, {'attr': {'novalidate': 'novalidate'}}) }}

        <ul class="record_actions">
    <li>
        <a href="{{ path('org') }}">
            Back to the list
        </a>
    </li>
    <li>{{ form(delete_form) }}</li>
</ul>

    {{ render(controller(
    'CompanyNameofBundle:Search:shortjq')) }}
    {{ render(controller(
    'CompanyNameofBundle:OrgMember:test', {'orgid':1})) }}

{% endblock %}

OrgController.php

/**


* Org controller.
 *
 * @Route("/org")
 */
class OrgController extends Controller
{
public function editAction($id)
    {
        $em = $this->getDoctrine()->getManager();

        $entity = $em->getRepository('CompanyNameofBundle:Org')->find($id);

        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Org entity.');
        }

        $editForm = $this->createEditForm($entity);
        $deleteForm = $this->createDeleteForm($id);

        return array(
            'entity'      => $entity,
            'edit_form'   => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),

        );
    }
}

Org.php (Entity)

/**


* Org
 */
class Org
{
     /**
     * @var string
     */
    private $orgName;


     /**
     * @var integer
     */
    private $orgId;
    /** of course setters and getters for above */

}

1 Answer 1

1

So getting the entity is OK and your only problem is passing it into the template? Then I would say this is your answer:

{{ render(controller( 'CompanyNameofBundle:OrgMember:test', {'orgid':entity.orgId})) }}

Sign up to request clarification or add additional context in comments.

4 Comments

I hate you! I had tried that a lot but kept changing entity to my entity name. In this case I put "Org" in lieu of "entity" which did not work. Then I pasted exactly what you typed and it worked as expected. Thanks and hopefully this helps someone else! @honzalilak
How could I check if the field exist? I tried wrapping the above with {% if entity.orgId is defined %} to avoid getting the error: An exception has been thrown during the rendering of a template ("The product does not exist"). @honzalilak
@shayster01where does the exception "Product does not exist" come from?
It comes from the my.html.twig after I insert the code {{ render(controller( 'CompanyNameofBundle:OrgMember:test', {'orgid':entity.orgId})) }} but only when there is no value in the orgId. It works perfect for all the rows that have an orgid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.