Zend passing data from action in controller to view in another controler - zend-framework

How can I pass data from action in controller to view in another controller?
From action in controler to view in the same controller is easy:
I simply write in action's function :
$this->view->assign('error', 'Wrong login');
and in view I recieve it in this way:
<?=$this->escape($this->error);?>
but how can I do it to receive it in view of another controller?

I might be wrong but my guess is that for every request there is only one Zend_View, so if you set something on ControllerA and forward execution to ControllerB you could access that data in the same way.
It´ll not work if you use the action helper _redirect because it´s a browser redirection, to just forward execution to another "place" use the _forward helper instead.
Another option is the flashMessenger helper, that a look at the docs
http://framework.zend.com/manual/en/zend.controller.actionhelpers.html

Related

Symfony - Getting the controller action path in a controller that renders a modal twig.

If you are grabbing the route path (i.e. /employees/edit/5) inside a controller that renders a modal div, you can't use $request->getPathInfo() in setting the modal's form's target/action, because the controller hasn't been called yet and therefore $request->getPathInfo() inside the controller will only return "_fragment", which is perfectly understandable.
Is there a way to do this?
I think you call your controller with
{{ render(controller(' ... ')) }}
There is no HTTP Request, just a function call in your Controller :)
If you want, you can get MasterRequest in your controller :
dump($this->get('request_stack')->getMasterRequest());

Accessing ViewHelper from another ViewHelper specifically FlashMessenger

So I created a view helper to specialize/simplify some of the functionality of the Flash Messenger helper.
I have been looking around a lot and saw that you should be able to access the FlashMessenger helper through code like this:
$this->view->_helper->flashMessenger->getMessages();
This won't work for me. I can access view but not anything under _helper. My helper class does extend Zend_View_Helper_Abstract. Do you have to explicitly pass in the view from the view script?
The $_helper property of Zend_Controller_Action stores an instance of the Zend_Controller_Action_HelperBroker, so instead of passing it from the view to your helper, you can get an instance of the HelperBroker and then get the FlashMessenger object from there.
// inside your view helper
$messenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
Now you have access to the Flash Messenger from within your view helper. You can do the same from anywhere in the application to get a reference to any Action Helpers.
Also note, if the helper has not yet been created, calling getStaticHelper will initialize it for you.
See Action Helpers - The Helper Broker for more information.

Call ActionResult of Another View from form

I am trying to create a search form in my MVC application in View 1. The form was working very well when I used to submit the form to same page (View1). That way I can have two ActionResults - one of which accepts HttpPost requests. Everything is cool here
Now things have become slighly complex and I wish to separate the views. So in View1 there is a form and I wanted the results to be displayed in View2. So how do I call ActionResult of View2 from a form in View1?
In short - User enters keyword in View1. Hits Enter. Form in View 1 calls View2. ActionResults in View2 calls some logic to search and return View2 as the view and then I can display the results.
I tried some basic things like action="/View2" but I was pretty sure it would fail. It says 'the resource cannot be found'. Is it even possible to do this? Kindly advice.
*UPDATE*
It can be solved as answered below.
use Html.BeginForm(Name of the ActionResult,Name of the controller)
You need to specify the URL of the other action in the form, preferably by calling the Html.Form("ActionName", "ControllerName") helper.

How do I get the RouteData associated with the parent action in a partial view?

In the action for a PartialView, I'd like to know the RouteData associated with the Parent Action.
This partial view is part of my masterpage template, and I'd like for it to know the Controller and Action that was called as part of the page rendering.
In my PartialView's action, I inspect RouteData.Values["controller"] and RouteData.Values["action"], but I only get the controller and action for my PartialView.
Any suggestions?
--edit--
It looks like off of the ControllerContext (from which ViewContext derives) you can get the ParentActionViewContext:
ViewContext.ParentActionViewContext.RouteData["controller"]

How to Notify View Controller that a Property of an Object has Changed

I have a view controller which gets an NSObject conforming to a protocol and then displays a view with the object's properties.
The question : How can my controller know that a property of this object has been modified and then refresh the view ?
Thanks a lot
Thierry
There are three ways of doing this:
Have the object call a method in the controller in response to an event e.g. a user clicking the button. This is usually done using an IBAction.
Set the controller to be the delegate of object e.g. a UIWebView sends a message to its delegate when it finishes loading a page.
Use a notification. The object generates the notification and then one or more objects (including the controller) registers to listen for the notification. This is usually not used with interface elements although it can be.
I can't tell you more without more detail about the specifics of your project.
Your viewcontroller should conform to your .
In your model, all your set methods should trigger appropriate functions you define in your modelchangedprotocol.
This OO design pattern is also known as "Observer" design pattern.