Pass data from the controller to view

bsoremsugar —  January 29, 2013 — 3 Comments

Here’s a good question on StackOverflow recently…

Good Morning, I want to know if there’s a magical way to pass variable created in the controllerModule to the ViewModule. exemple:

$this->assign['result'] => $resultValue;

and in the view display()

echo $this->request['result'];

Maybe there’s a better way to exchange data between Controller and View? Thanks you.

There is a good way, as pointed out by C├ędric Mourizard of SugarCRM Gold Partner Synolia. You can use the view_object_map property of the Controller class as shown below…

The view_object_map var is made for you.

In your controller you could do:

$this->view_object_map['myDataKey'] = 'MyData';

And you could retrieve your data easily like that:

$this->ss->assign('myData', $this->view_object_map['myDataKey']);

or

echo $this->view_object_map['myDataKey'];

Thanks Cedric for the great answer here!

3 responses to Pass data from the controller to view

  1. 

    Good to know there’s a way to ‘un-magically’ pass data to the view in Sugar. I hope the ‘Sugar heroes’ would help clarify things even more and address newbies more than the experts. I have been trying to figure out how to include a custom field values in a particular custom field i created as part of my advanced search parameters for about 2 months now – and i still have no clue to finding a solution yet.

    thanks in advance

    • 

      Can you detail more what you are trying to do? Would be glad to see if we could help come up with a solution

      • 

        I am currently customizing Sugar CE 6.5 and I have started out to introduce branch units into the App such that information may be loca lized based on a custom field entry called branch_c. which i have attached to all the module tables using the Studio.
        Example the branch column takes entries such as Branch_A or Branch_B etc
        depending on the user’s branch. and the records also have branch code
        tied to every entry. so that you see only the ‘object entries’ that
        belong to your branch only. but i need to include the branch into the
        advanced search such that an administrator or even users with permission
        to view more than one branch can filter using the values entered into
        the branch field of the object (e.g accounts) based on the selected
        value eg (Branch_A). I hope this is clear but please i will appreciate
        your insight and assistance. Besides i just bought your book on Amazon,
        it should arrive in a few days from now, i hope it would really help. Thanks again in advance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s