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 */

}
shayster01
  • 214
  • 3
  • 17

1 Answers1

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})) }}

honzalilak
  • 366
  • 2
  • 11
  • 1
    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 – shayster01 Aug 26 '15 at 16:36
  • 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 – shayster01 Aug 26 '15 at 18:56
  • @shayster01where does the exception "Product does not exist" come from? – honzalilak Aug 27 '15 at 07:44
  • 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. – shayster01 Aug 27 '15 at 17:01