Set onload from view level in Zend Framework - zend-framework

I am facing one issue and I am not sure if what i would like to do makes sense.
In fact I would like to set layout's body onload from one particular view. In my approach onload should not be modified in case user is elsewhere than one view.
Do you know if it is possible at all?
Kind Regards,

You could do that with Route Context. You can add unique class for actions/action that you want the onload to be added on. And then use some javascript library depending on which class the body tag has.
Once you have body classes that are unique for various modules, controllers, and actions you can use those as part of your selectors in jQuery (or whatever JavaScript library you're
using).
Ref: Route Context
Hope it helps

Related

jquery ui spinner change style of one specific spinner

I want to remove the ui-corner-tr and ui-corner-br classes from one specific spinner with an id of test and a class of testSpinner as an example.
I tried... and many combinations of classes with no luck.
$('.ui-spinner .testSpinner').removeClass('.ui-corner-tr');
$('#test').removeClass('.ui-corner-tr');
Any ideas?
It can be an order issue: maybe the jqueryUI library loads after your code, nullifying it.
(I'm just guessing... You should provide more details).
the removeClass method does not require CSS selector names, just class names.
$('.ui-spinner .testSpinner').removeClass('ui-corner-tr');
$('#test').removeClass('ui-corner-tr');
Reference: https://api.jquery.com/removeclass/

How main.scala.html get called in Play Framework

I am trying to understand the architecture of Play Framework (internally how it works). In other framework like struts we can create index.html page and place in web folder with entry in web.xml file.
In Play the start point is main.scala.html page and all other pages inherited from it by placing all the content wrapped in
#main(title =""){
}
like index.scala.html page. But I couldn't find the place where main.scala.html page is registered to Play framework (no entry in routes file or other place?) or may be I am missing some points here.
So far from the play docs I understood that every scala.html page is basically a method call which sounds right to me.
So my goal is basically create other pages like main.scala.html page which will act as container for other sub pages and arrange my code in more modular way
Sorry if I am asking a dumb question.
Thanks in Advance
According to the Play docs main.scala.html is a layout - just common view which allows to inject HTML from other views and references to it by (content: Html) . main layout just wraps code that index view injected to it. (with optional arguments)
The opposite situation is usage of include or tag so just pointing the place where another view should be placed in the current view (also with optional arguments).
You don't need use them at all - Play doesn't enforce you to do that, you can use separate view (without layout) for each action.
On the other hand if some number of views should share same set of JS and/or CSS then layout(s) are native choice to do that job.
For an example instead of using main.scala.layout you can create ie. frontend.scala.html, backend.scala.html, guest.scala.html so your FE views will use #frontend(){ code...}, BE #backend(){ code... } etc.
You are unlimited in number of layouts/views/tags and other includes ;) All belongs to you. That's Play!

Creating reusable widgets

I`m using asp.net mvc 2.0 and trying to create reusable web site parts, that can be added at any page dynamically.
The problem I have is how to load a partial view with all related js and data? Ive tried the following ways to do that:
Use partial view and put all the js into it. In main view use render partial. But to initialize partial view I need to add model to current action method model to be able to make RenderPartial("MyPartialView", Model.PartialViewModel).
Also I do not have a place to put additional data I need to fill my form(like drop down lists values, some predefined values etc).
Use RenderAction, but it seems it have same problems as RenderPartial, except for I do not need to add anything to any other model.
Any other oprions are greatly appreciated.
As I understand it, RenderAction performs the full pipeline on the action, then renders the result - so what is rendered is the same as what you'd see if you'd browsed to the action.
I've used RenderAction to render 'widgets' throughout a site, but in my view they should be independent of the page rendering them, otherwise they're not really widgets and should be part of the rendering page's code instead. For instance, if there's a log in form, you will always take the user to a page that can process the information, no matter what page they are currently on, so this makes for a good widget. Other ways I've used it is to show a shopping basket or advertising. Neither of which are dependent on the page being shown.
Hope this helps a little!

How do I implement base view functionality on Windows Phone 7?

Lets say that on all my views, or generally at any time in my app, I want to be able to show an error message popup, and it always looks the same. How do I do that?
First thought is having all my view models extend a base view model which facilitates these things, but after that, do I have this base view model actually create the UI widgets and display them?
thanks,
Mark
If you've got some common functionality that you want to provide across a range of views, then you can implement a base class that inherits from the PhoneApplicationPage, and then derive all your classes from that class instead. The XAML for your pages then looks like this:
<local:BasePage xmlns ...
xmlns:local="clr-namespace:MyNamespace"
x:Class="MyNamespace.MyPage">
However, you will not be able to define common UI components in the XAML for your base page. If you wanted to have common UI components you would have create them manually in the code-behind for the base page, perhaps in a handler for the Loaded event, but I think a better solution would be to provide your common UI in a UserControl, which you then add to each of your pages.
If you want to show a Toast or Message Box, then I would recommend the ToastRequestTrigger and MessageBoxRequestTrigger from the Silverlight Toolkit as described in the patterns & practices WP7 Developer Guide.
you could probably define an event on base view model, which is fired inside view model whenever an error occurs, then in view, you can subscribe to this event and display the popup. You can carry error context in EventArgs of the fired event.
Additionally you could unify the logic for displaying the popup but that's probably another story :)
This is testable and nicely decoupled from the view.
Hope this helps,
Robert

Widgets inside Zend Framework - Where should they go?

I've been working with Zend Framework (using Doctrine as the ORM) for quite a while now, and done a few projects with it.
In a few upcoming projects I am requiring the need for widgets similar to how Wordpress does them. You have a post/page, which could look like:
Subscribe to my newsletter:
[subscribe/]
View my events
[events limit=5 sort=date/]
View this page's comments
[comments/]
Where say the subscribe widget would be replaced with Blog::subscribeWidget, and the events could be replaced with Events::eventsWidget, etc.
Now it has done my head in the past few weeks about how on earth do I do this??? I've come up with the following options:
I could place the widgets within controllers, and then call them like actions. Problem here is that code could be flying between controllers, and I have read this is expensive due to the amount of dispatches.
I could place the widgets as view helpers. So within the view I could have $this->renderPage($Page), which would then attend to all the widgets. Problem here is that what if the widgets need to do some business logic, like for example posting a new comment, that really shouldn't be within the view, should it?
The other option is to place widgets within the model? But then how on earth do they then render content for display?
Extra complications come when:
Say the comments widget would also handle posting, deleting of comments etc.
Say for the events listing, if I want to do an ajax request to the next page of events, using method #2 (view helpers) how would this work?
If I understand you correctly your widgets will need their own action controllers, which is where their logic for fetching data to be displayed, parsing form submissions, etc. should go. The difference between a widget and a page in this case is in how it's rendered, i.e. as an HTML fragment instead of as a whole page; you can use the Action View Helper to achieve this.
If your widget includes a form it should probably use AJAX to submit the form data back to the server, so that using the widget doesn't cause the user to accidentally navigate away from the page. You can inject the required JavaScript into the page you've included the widget into by using the Head Script Helper in your widget's view and/or action.
I left Richards reply, the problem, and further use cases cook in my brain for a while longer and ended up coming to a solution.
I will have the following view helpers and methods:
Content; with methods: render, renderWidgets, renderWidget, renderCommentsWidget (comments).
Event; with methods: renderEventsWidget (many events), renderEventWidget (one event)
Subscription; with methods: renderSubscribeWidget (subscription form).
I will have inside my configuration file:
app.widgets.comments.helper = content
app.widgets.subscribe.helper = subscription
app.widgets.events.helper = event
I will also have the following models:
Content for use for all pages.
Event for use for all events.
Subcriber for use for subscriptions to content
So inside my view I will do something like this:
echo $this->content()->render($this->Content)
Content::render() will then perform any content rendering and then perform rendering of the widgets by passing along to Content::renderWidgets(). Here we will use the configuration of app.widgets to link together the widget bbcode tag to it's appropriate view helper (using the naming convention 'render'.ucfirst($tag).'Widget'). So for example Content::renderCommentsWidget() would then proceed to render the comments.
Perhaps later on I will decide to have a Widget View Helper, and individual view helpers for each widget eg. ContentCommentsWidget View Helper. But for now that would just add additional unrequired complexity.
Now to answer the AJAX problem I mentioned. Say for the comments widget allowing for comments to be posted via ajax. It would simply have an appropriate method inside the Content Controller for it. So pretty much we also have a Event and Subscription controllers too - corresponding with the view helpers. Interaction between the view helper and controller will all be hard coded, there is no purpose for it to be soft coded.
I hope this helps someone else, and the current plan is to make the project where all this is used to be an open-source project. So maybe one day you can see it all in action.
Thanks.
Update:
You can find the source code of these ideas in action in the following repositories:
BalCMS - this is the actual CMS which contains the widgets in /application/modules/balcms/view/helpers and contains the configuration in /application/modules/config/application/balcms.yaml
BalPHP - this is the resource library which contains the widget view helper at /lib/Bal/View/Helper/Widget.php