SugarCrm pass data from controller to view - variable-assignment

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.

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 easyly like that:
$this->ss->assign('myData', $this->view_object_map['myDataKey']);
or
echo $this->view_object_map['myDataKey'];

Related

yii2: how to send a model from a create form to the controller

I have a dropdownlist in my form:
<?= Html::activeDropDownList($model, 'Id_tipoprograma',
ArrayHelper::map(Tipoprograma::find()->all(), 'Id_tipoprograma', 'Id_tipoprograma', 'Descripcion'))?>
i want to receive "Id_tipoprograma" in the controller, i tried with:
$idtp = $model->Id_tipoprograma;
But doesn't work. thanks.
First read docs here and here. Normally you should get form data in Yii::$app->request->post() or Yii::$app->request->get()

Grails - Render a template by email

I have a controller's method which renders a template.
This works fine to render the template within my .gsp view.
I am also using the mail-plugin, and I would like to used the same controller's function to render the template by email, hence populating some email with it.
I know how to do that from a .gsp view via Ajax request but do not know any way to do that from within a controller or a service.
The idea would be to use my controller's action more like a function, take the rendered teplate and populate my email with it.
Also, my controller's action needs to have some 'params' properties to work properly.
Any suggestion most welcome.
Regards,
You can use the render tag( http://grails.org/doc/latest/ref/Tags/render.html ) can be used to return a string.
I would move whatever logic you have in your controller that is reusable into a service, and then use this to return a model, then you can simply call this via:
def model = myService.method( ... )
def emailContent = g.render( template: 'mytemplate', model: model)

Zend framework - access controller or model from the view

I need to give the front-end designer the ability to choose whether or not to display a single xml feed or an mash-up, from the view.phtml file
This means I need to be able to call a method from the controller or model which then returns a variable to the view containing the requested feed(s).
So how do I access methods of the controller or model from the view?
you don't call controller methods in view , but you can create an instance of model (for read only purposes) inside view and then call its public methods .eg
Foo.phtml
<?php $feedsTb = new Default_Model_Feeds() ?>
<?php $allFeeds = $feedsTb->fetchAll(); ?>
I don't know if i got your problem right, but this is something i'd probably do in a way like
Controller:
if($this->_getParam('single')) {
$this->view->data = $model->getFeedSingleData();
$this->render('single_feed.phtml');
} else { //mashup
$this->view->data = $model->getMashUpData();
$this-render('mashup_feed.phtml');
}
Though admittedly an example like this is better off with two different actions (singleAction() and mashupAction())
But i really don't know if i got your problem figured out at all :S You may explain it further

ZEND, rendering different view with data

I have a problem as I want to render view from different controller and pass there datas. Do You know how to do it?
I was trying:
$this->renderScript('index/index.phtml')->entries = $result;
But my if:
if (count($this->entries) <= 0)
return 0
Do You know how to do it?
THANKS!
Do you mean you just want to render a different controller action's view script?
$this->view->entries = $result;
$this->_helper->viewRenderer('index/index', null, true);
Check out the manual page for the ViewRenderer helper.
Render view with action's output data.
in view page you wish to display data write this simple code.
echo $this->action('list','users','main');
list is my action name
users is my controller name
main is my module name (if module using in your project).

passing values from model to view in CI

I have this library in CI that retrieves my latest twitter updates. It has a function that sends my latest updates as objects to my controller.
I would like to show these twitter updates on the footer of my page, so they're visible at all times.
Now my question is how I call these directly from a view? I know this is not a good practice in MVC but I don't see how else I could do this.
My controller currently takes care of all my different pages (it's a small website) and I don't think it's very good practice to call my twitter class at the end of every page-function in the controller and then send it through to the views.
Typycally I do this in my controller:
<?php
function index(){
$data['page'] = 'home';
//i don't want to call my twitter class here every single time I write a new page. (DRY?!)
$this->load->view('template', $data);
}
?>
And it loads the "template" view that looks like this:
<?php
$this->load->view('header');
$this->load->view('pages/'.$page);
$this->load->view('footer');
?>
So any suggestions how I should do this?
I have a helper library that takes a page Partial and wraps it in the master theme. You can use the optional parameter on your load->view to render to a string.
Then when you render your master page, you can load the twitter updates, and display them. Although, I highly suggest caching your twitter response for 5 minutes at least, will save you a LOT of overhead.
Example:
// Controller somwhere:
$content = $this->load->view('pages/'.$page, array(), true);
$this->myLibrary->masterPage($content);
// Your library:
function masterPage($content)
{
$twitterData = $this->twitter->loadStuff(); // whatever your function is
$twitter = $this->load->view('twitter_bar', array('data' => $twitterData), true);
$this->load->view('master', array('content' => $content, 'twitter' => $twitter);
}
An alternative approach is to use a base controller. All my controllers extend my custom base controller which holds things I need on every page, for example an object containing the current user.