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

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

Related

How to dynamically change view in Swift (e.g. for a settings page)?

I found a good settings page tutorial at https://www.simpleswiftguide.com/how-to-use-userdefaults-in-swiftui/ and implemented it into my app. However, the settings page is completely static and can't be changed based on the user's choices. Often a program needs to have constraints where the allowed choices for field B might change based on the user's choice of field A. How do I add an on-click listener to the settings which can call the UIViewController to somehow change the structure of the view after it has already loaded? I am using UIHostingController to wrap the SwiftUI View which is declared as a struct instead of a class. If I try to access the view via self.view I don't see any relevant functions that could give me access into the inner workings or fields of the view.
It doesn't look like there's an easy way to do this in Swift like there is in Android. I'll resort to using a sequence of UIAlertController each with multiple choices. Unlike the View struct with "var body" protocol, the alerts can be built programmatically depending on what the user has already set.
Some if else in the View
if $userSettings.username.wrappedValue == "username"{
SomeView()
}else{
SomeOtherView()
}

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 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,

Showing another View from my current Viewmodel and closing a view from my viewmodel?

I have another view setup and ready and waiting with its viewmodel. My RelayCommand arrives in my "Current" viewmodel. What is the best way to show the new view from my current viewmodel?
I have been reading and it appears that I need to use the Messenger to send a message from my viewmodel to ??? my new viewmodel that is associated with my view I wish to show? But how would I show the View?
Also is there a way to support closing a view from a viewmodel? I wonder if mvvm-light brings anything extra to the table - ie.. Triggers to force the viewmodel to close the view?
In WPF, you have two ways (out of the box) for "showing"/"closing" views. The first, is simply, by showing a Window, or Dialog via the .Show() or .ShowDialog() methods, and they can be closed with the .Close() method. In this case, you can use the MVVMLight Messenger class as you mentioned to send the show/close messages to the view in a decoupled way. here's an example with "closing".
In the ViewModel:
CloseTheView()
{
Messenger.Default.Send(new CloseTheViewMessage);
}
in the code-behind of your view:
//Constructor
public TheView()
{
...
Messenger.Default.Register<CloseTheViewMessage>( () => this.Close() );
}
as you can see, this involves some code in the code-behind file, but it's no big deal, since it's just one line of functionality.
The second approach is to use the Navigation Framework (which is available for both WPF and Silverlight). You define a "Shell" which is the main Window (or UserControl), you put a frame inside of it, and you make your other views inherit from Page, and then initiate the navigation from your ViewModel using the instance of the NavigationService associated with Frame (or directly the one associated with the page itself).
Hope this helps :)

How to disable a view script in a controller - Zend Framework

I am playing with zend framework's MVC. One thing I found out is that Zend Framework tries to include a view script whenever a controller is called. I can disable it in bootstrap with the following code.
$frontController->setParam('noViewRenderer',true);
However, I have to initialize Zend_View class in a controller method then render a script file myself.
How can I stop including a view script in a controller method so I can disable it if only I want to?
you can disable the view renderer controller helper, with this code in your controller:
public function myAction()
{
$this->_helper->viewRenderer->setNoRender(true);
// from now on, ZF won't search for a matching view script file.
}
The best example would be to use both commands above:
public function myAction() {
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
}
First one disables layout,in general is enabled
application.ini
default
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
$this->_helper->layout->disableLayout();
and second disables view script (.phtml) so exception is not thrown if view script file is not found
$this->_helper->viewRenderer->setNoRender(true);
There are also view helpers that include bouth listened abowe and are not necessary, for example you want to return JSON from array data and not render view element.
public function myAction() {
$this->_helper->json(array());
}
will not render layout nor view script.
Easy, just disable it from within your action.
$this->_helper->layout->disableLayout();
If you aren't talking about layouts, then just add an exit() to your action. Just understand what sort of impact that will have on your application.