Can cakephp have multiple 'content'? - cakephp

So in cakephp's layout we have the
$this->fetch('content')
right? does it mean i can only have one 'content' in one layout? I really need multiple content from multiple controller can it be done? how? please help me!!!

The layout isn't capable of pulling information from the controller. The controller is the place where the view is prepared to be placed within the layout.
When you access a CakePHP URL, it's in the following format:
http://example.com/controller/action
In other words, you're connecting directly to the controller, not the layout.
You use the controller to get data from the Models and then when everything is ready you set it to a view and then the view is displayed, with the layout wrapped around it. So, you only put HTML/CSS etc in your layout if you want it to appear in all of your views.
To answer your question, though, your controllers don't actually have any content. Your content is (presumably) in your database. Databases are accessed using Models and it's possible to pull data from multiple Models using a single controller, which is usually done by defining relationships between multiple Models.

Related

Share data between controllers AngularJS

In our case, we have a search function in our application which shows the search results after entering a search term. The search results are products in our case. When we click on one of these products we are send to the page with information regarding this product. Now our problem, when we want to go back to the search page we want a method to return to the exact same page as before we left the search page. And not an entirely new search page.
We have divided our HTML in 3 views, which we load with the UIRouter.
We need to share data between the header, content and footer. When we show our search results, we want to show the amount of results in the header for example.
In short; we need to share our data between controllers / views. What will be the best solution?
We have thought about:
Adding a mainController to the body and using this as a medium to communicate data between controllers..
Store all data in a factory and access this factory direct from all controllers. But will all views be updated directly on data change? (2 way binding?)
However, we didn't get it working yet. What would be the best way to manage this?
As mertins mentioned in his comment, a service would do fine for this purpose.
Inject that service to all relevant controllers and indeed, thanks to 2-way binding all relevant data will be updated properly.
Don't use a controller, that's not what they are meant for!
If you need a code example for the service injection comment and I'll update this answer.

General approach of left side menu that loads different content in a center of the page

I've started to learn AngularJS but I need some application design hints. Of course I'm not asking about the layout but ... how to design my application and it's controllers in a proper way. I have left sidebar with a menu that is loaded from the web using JSON. That needs a controller. That's fine. It works for me. There's a content box as well in a center of my page that loads some data dynamically. In my opinion it requires another controller.
And now comes my solution, that somehow doesn't look good IMHO. When I click a menu item in my sidebar I'm loading a content. Then I'm passing this data into a Service which emits an Event afterwards to the Second controller (which is responsible for controlling my content in a center of my page). When it receives this event it simply gets previously loaded data from the Service and displays it. It generally works.... but ... I'm pretty sure that's not the proper way of doing this.
I would be grateful for any hints. AngularJS has a really poor documentation and tutorial :(
cheers
EDIT:
OK. That's my basic application using JQuery:
http://greatanubis-motoscore.rhcloud.com/index
And that's the same application I'm converting into AngularJS:
http://greatanubis-motoscore.rhcloud.com/angular/index
No worries, some text is in Polish but... I think it really doesn't matter ;)
Note for the AngularJS version: At the moment the content is a HTML but finally it will load JSON data as the other controllers.
I would go about doing this with angular ui-router. With ui-router you can achieve this in a couple of ways. You can use nested routing to have a base state (Your sidebar menu, header etc.) which will act as your shell page, this can have its own controller as well. You could then define each of those other views as child states of the base state. These child states can also have their own controller/views as well, but they will be sitting inside the base state (both visually, and also inherit $scope properties of the base state) optionally they can have separated URLs themselves, but they don't have to, you can just change states without changing the url, by leaving the URL bit empty when you define different states in your $stateProvider configs. Another way would be to use the multiple named views feature.

ExtJS mvc: where to keep the active tab data

I'm using ExtJS with the MVC pattern. My app has, among other things, a tab area in which multiple instances of a data are shown. Each tab has its own storage, but they share the same controller instance, since they are exactly the same view. This is allowed by the fact the Controller is completely stateless. But in the controller there is plenty of code looking for "the active tab", since controller need somehow to know on which view is acting in order to recover some data from the store to properly work. Where is the place to maintain the current active tab? I have another controller, call it main, who orchestrate tab creations, but I cant keep there since this violates the state requirement for the controller. Any idea/suggestion?

angularjs: tabbed view design issue

[EDIT]
Similar question to Complex nesting of partials and templates
As of now, is it better to use Angular-UI state solution or should I stick with ng-includes ?
So far I had one view per URL in my AngularJS application. I need to build a new view, which should have 3 tabs and I'm having troubles trying to figure out how I'm going to design the view - architecture-wise that is.
Note that the business model object behind these 3 tabs is the same one.
The first tab is for viewing and editing data on the business object. So that's already two 'views' within the first tab.
The second tab is for viewing a paged-table showing data from a child collection of the business object.
The third tab does the same thing as the second one but for another child collection.
Obviously, I do not want to load the entire business object at once. I'll load the collections only if the user navigates to the 2nd or 3rd tabs.
My main concern right now is how am I going to organize the views ? AngularJS has this limitation of only 1-view per page.
Also, I need to handle browser history, so the URL must change when a tab is selected, but I should have to reload any data (i.e I must not reload the controller).
Any tips would be much appreciated.
For the record, I ended up using ui-router and its state management, which is awesome. It took me a bit of time to understand the concepts and to put that in practice, but I managed to build a pretty complex set of layouts effortlessly !

Creating multiple views with different Models on one page with Backbone boilerplate

What is the best way to create multiple views with different models using the backbone boilerplate? It seems like things are set up to render individual pages, but not to render multiple resources simultaneously.
I think I am understanding you correctly, but please let me know if I am not. Backbone shines in SPA's (Single Page Apps). I am not saying that it should only be used for an SPA. If you start thinking of views as sections on a single page, I think Backbone starts to make more sense. So when your model updates or changes, the section/view is being re-rendered and not the entire page.
Look at the Trello and read this article http://blog.fogcreek.com/the-trello-tech-stack/ - especially the part on Backbone. I think the above will answer your question more thoroughly.
Tyrone

Resources