Correct interaction between page view and blocks

Permalink
Hi everybody!
I've tried to search for a solution but I really can't.
I know that single pages and page types can have own controller. So, I'm trying to find the best way to implement my pages.
I've composed a page type in 4 blocks. In order to avoid repeated requests, I've thought that the page type's controller do some SQL operations and elaborates them. Then, this information have to be fetched by the blocks that show or use them in some way.
What I can't understand is how can I let blocks fetch the information from controller's page type. And also, is this correct? Are there better ways to use blocks and page's controller?
Eg: "page_title" block and "product" page type. Page type's controller fetches the information of the product from the DB and then the page_title block have to show it's name and obtains some other related information.
Thank you!

 
jordanlev replied on at Permalink Reply
jordanlev
Your description is a bit confusing -- I can't tell exactly what it is you want to do. But it sounds like you want some blocks to automatically fill up with certain information, is that correct? What information is it exactly that you want to put into these blocks? Getting the page title is easy enough, but what else besides that are you wanting to do?

And did you see this tutorial:
http://www.concrete5.org/documentation/how-tos/developers/build-a-s...
danielebr replied on at Permalink Reply
Ok I'm sorry. I try to explain it in a better way.
Tell me if my procedure is correct.
In a previous website that I built without any CMS, I was used to fetch and manipulate the necessary information in the head of the selected page. Then, this information were shown in the page -so view and controller were the same file.
(eg, fetched the product information and then its name were shown as the page title).
With Concrete5 instead, the same page is logically divided in controller, view and several blocks. So, I have to let them interact one with each other but I can't understand how. In this case, with concrete5, the on_start() function of the page's controller should fetch and manipulate the necessary information. But in this case we have blocks that show them or even do some personalized tasks depending on that information.. That is in order to avoid repeated operations like sql query.
If this procedure is correct, how can I let the blocks call the functions of the page's controller ?
jordanlev replied on at Permalink Reply
jordanlev
What is it exactly that you want to display? What is this information you are referring to?

Is it actually a product catalog, or is that just an example? Are these products being sold on the site? If so, I highly recommend purchasing the eCommerce addon, it is well worth the money as it contains a ton of features that will be very time-consuming to program yourself. If you don't need to sell products on the site, you could just have a separate page for each product, and then use the Page List block to list out the products on another page (like an "index" or "listing"). You can use the free Page List Teasers addon if you want the page list to display actual content from each page, or if you need to customize it with specific information, you could make a custom template for the page list block that pulls out certain pieces of information from page attributes.

If you can give me a specific example of what it is you're trying to build, including what information gets entered on what pages and then what other pages are trying to show that information, I can give you more specific help.
danielebr replied on at Permalink Reply
It's actually an example to show one kind of interaction between page and block.
Isn't it a normal way to program a page?
Each block is not meant to be completely independent from the page in which it is installed, is it? So do I have to let the blocks obtain some infos directly from the page in which they are installed or is it viceversa?
If is the first case, how can I do that?
Thank you!
jordanlev replied on at Permalink Reply
jordanlev
Yes, actually, blocks are meant to be independent from the page they're on. Users should be able to add any blocks to any page, move them around, copy them to the scrapbook and paste them elsewhere, etc.

Without you explaining what the exact situation is here it's really difficult to provide more specific details of what you should do. Care to share? You say "show one kind of interaction between page and block". What is this interaction you refer to? What is it on the page that you need the block to know?
danielebr replied on at Permalink Reply
Ok, so this is my situation:
when an user chooses an article category, him opens the page that let him see a list with the preview of several articles.
In this page I need that:
1. the preview block of articles makes show the articles with title, description etc
2. the block of page_title makes show some of the article titles
3. the filter block makes show the articles typologies
but, if (as you said) each block works in a independent way, I have to do several times the same sql query because the infos like titles or articles typologies are repeated in the articles preview block.
What can I do?
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Learn to love the Page List block -- it is what you want to use in situations where you're listing several other pages on a different page (which is what it sounds like you want to do).

By default (without any customization), the Page List block will display the title and whatever is in the "description" property of each page.

If you grab the "Page List Teasers" addon from the marketplace (http://concrete5.org/marketplace/addons/page-list-teasers... ), that provides a custom template for the page list block that will display all of the content blocks in each page's "Main" area, so you could set up 2 areas on your "detail" pages -- one for the blocks that will be displayed on the "list" page, and another for content that's only on the details page and won't be pulled into the list.

Hope that helps.
danielebr replied on at Permalink Reply
Ya, thank you, I've understood something more... to the end I've to use more the page properties and re-think a bit the way I fetch and store information in database...
danielebr replied on at Permalink Reply
I'm understanding which is the best way to use Concrete5 but I have another question.

As told before, I've already built an ad-hoc database and with concrete5 I want to preserve it. I've understood that I need to implement my site like a blog (for example like the sample site present in the installation of Concrete5). I really want to implement it in that way but, however, I don't want that the data related to my site would be mixed with concrete5 data (eg, product title as page title). Is it correct using the concrete properties, attributes etc saving, for example, the product title as page title but, in the same time, saving it in my personal database? obtaining this, I would have few repeated information but they would be saved in my database in the way I want to store them. (for example if, one day, I would change to another CMS).
Thanks
jordanlev replied on at Permalink Reply
jordanlev
I see. Well I am not sure what the best way to do this would be. You could just store it in your own database and then use SQL queries to display it on C5 pages (you would want to add a "cID" field to your database tables so you could match up c5 pages with database records). The hard part is going to be making an interface for your users to edit this data -- probably will want to build C5 dashboard pages for this so they don't have to log into 2 places.

But really Concrete5 is designed to work with pages and to intermingle the data with the pages (which is not considered "pure" to some programmers, but I think it makes a lot of sense for the kinds of website projects that C5 is great for). If your requirements fall outside of this too far, it may be worthwhile to look at more of a lower-level platform that won't give you as nice of a user experience as C5 but does give you more flexibility as a programmer. In PHP, I know that SilverStripe is pretty good about this. There's also some promising CMS plugins for Rails and Django (if you're not tied to PHP). But these will require more development time than C5 because they are more flexible.

-Jordan
danielebr replied on at Permalink Reply
So there's no real problem using my own database for storing the information but you've given me a doubt about the creation of the interface for users.
I see the dashboard useful and indicated only for the "administrators" of the site and not for the final user (a final user who wants to edit his data like, for example, his products infos). So, I thought to build ad-hoc single pages to let users edit they're infos or adding new products pages.
That said, the question is: is it the correct way to use the CMS or, for this purposes, is better a framework?
Otherwise, if it is correct, I can let the final user edit his data using a personalized limited dashboard...

Thank you. Your answers are very useful.
jordanlev replied on at Permalink Reply
jordanlev
In my opinion, no this is not the "best way" to use C5. That being said, it doesn't mean you're wrong to use C5 for this, just that it falls outside of the built-in tools and functionality so you're going to need to custom code a lot of it -- which is something you'd have to do in pretty much any system I think.

I love Concrete5 and use it a lot, but to me there is definitely a sweet spot of when it's the best tool for the job -- basically a site that is edited by the site owners and not one that requires a lot of interaction by end-users to edit things. Also one that revolves around pages of information. When a project comes along that does require a lot of custom functionality, I usually look at how much of the website is the basic Concrete5 pages that need the CMS functionality versus how much of the website is custom. For example, if someone wants a site that is primarily a blog but has a few additional informational pages, I wouldn't hesitate to use Wordpress for that. But on the other hand, if a site is primarily CMS pages, and one small section of the site is a blog, I'll use C5.
Another example is with e-commerce. If a site is only a product catalog that allows purchases, I would probably use something like OpenCart or maybe even a hosted service like Shopify. But if the site has a lot of informational pages that require CMS functionality, and the ecommerce is only a portion of that site, I'll use C5 with the eCommerce addon.

Just my opinion -- there are a few people in the community here who like to use C5 for anything and everything, because when you are familiar with one system it can make sense to stick with that so you don't have to learn new environments and API's (not to mention deployment hassles). So there's no right or wrong answer, at some point you just have to pick something and go with it, then after it's done you will have a better idea of if you should keep doing that in the future or not.

Good luck!