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

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,

Related

Is it possible it use a link in a SwiftUI AttributedString to navigate to another view in the same app?

I know with AttributedString, I can link to an external website using something like:
Text("To learn more about AttributedString visit [this page](https://developer.apple.com/documentation/foundation/attributedstring/)")
Can I use this to go from ViewA to ViewB within the same app, kind of like this example in Twitter?
You can store an OpenURLAction in the environment to override how subviews like Text and Link open URLs.
This example is from the documentation:
Text("Visit [Example Company](https://www.example.com) for details.")
.environment(\.openURL, OpenURLAction { url in
handleURL(url) // Define this method to take appropriate action.
return .handled
})
You may want to apply the environment modifier at a high level of your view hierarchy (near your root view) rather than directly on each Text view.

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

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.