Zend - Conditional Based on Controller Action - Possible? - zend-framework

From a header.php layout we can give instructions based on a given controller by doing:
$this->controller === "mycontrollerhere";
Can we do more or less the same but with a specific controller Action ?
Thanks in advance,
MEM

Not totally sure what you're after but the front controller request object contains the names of the requested module, controller and action.

Related

How destroy (de-istantiate) or change reference for a xml view?

By this code I instantiate a xml-view and associate it to a name:
sap.ui.xmlview(welcomeApp, "apps.app1.welcomePage")
I want change set apps.app2.welcomePage to my new welcomePage xml view...
How can I destroy (de-istantiate) the view (after I re-istantiate it by the new path) or change the path?
You should use Routing to handle navigation from view to view. Please check out this step by step example to understanding UI5 routing mechanism.

Is it necessary to have a view file with every controller action

Whenever I create a new action in the zend framework controller using the zf CLI tool it creates the corresponding view file. However, I don't need the view file for every action in the controller.
If I delete that view file manually will it affect my project.xml file or have any other effect on my project ?
If your action does not require a view then you can disable it:-
public function myactionAction()
{
$this->_helper->layout()->disableLayout();//to disable layout
$this->_helper->viewRenderer->setNoRender(true);//to disable view
}
If you want to disable the view/layout for the whole controller then you can put the lines above in the init() method of your controller like this:-
public function init()
{
$this->_helper->layout()->disableLayout();//to disable layout
$this->_helper->viewRenderer->setNoRender(true);//to disable view
}
Once you have done that you can safely delete the view files without affecting anything else.
More details are available in the Action Controller manual.
No you don't need to.
Been a while since i worked with Zend Framework. But if memory serves me well, you have two options here.
1 - $this->_helper->viewRenderer->setNoRender(true);
Which will stop the view being rendered
2- You can simply do what you need to do and call exit() in the end of the of your action.
Hope it helps.
Cheers

Is there a way to disable a view helper inside the controller/action?

I have my view helpers in the layout like:
$this->viewSearchForm();
that is ok, in all the pages is show it, but what if a have two or tree page where i don't want to show that view helper? is this possible?
something like in an action:
$this->view->disable('viewSearchForm');
You could pass a flag to your view from your controller (init method or specific action).
In your layout you can have something like
if (!isset($this->disableSearchForm)) {
echo $this->view->viewSearchForm();
}
and from your controller send the following
$this->view->disableSearchForm = true;
I think you can't "disable" a view helper. If the helpers you have are in a specific folder, a workaround could be to remove that folder from the helper path using setHelperPath(), but the default view helpers path is never overwritten. See the Zend_View_Helper documentation for details.
Hope that helps,

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.

Zend passing data from action in controller to view in another controler

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