Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

The CMS.. How does it work? 
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

The CMS in Magento is very very lacking, as to be expected since Magento is an eCommerce platform, not a CMS. I do however want to create my own CMS for Magento, one with custom database feilds, images, etc. I am working on learning the ins and outs of Magento modules on both the frontend and the backend, but there is another critical peice of information that I need: How does the CMS work to begin with?

In the backend of Magento you can edit the URL of the pages you create. This URL is stored in the the database, and then magically that URL pulls up the correct page. Can anyone tell me how Magento knows that one page should bring up information out of the CMS DB table, and others should just pull up the 404? (Also a CMS page now that I look at it.)

If you can tell me that much, can you also tell me how I might best interface or emulate this action?

Right now you can edit the entire content block on a CMS editable page. In my CMS, I would like my clients to be able to edit cetain peices of information, and have the rest filled in by a template file. Example: The client would see a few different pages that are editable in my CMS, one of which being the Home Page. When they go to edit the Home Page they see an editor page with the sepcific needs of that page. Those needs may be choosing a title and uploading 3 images. I would then want that title and those three images integrated in key ways into a template file that I would later create.

As you can imagine, this is going to be very complex, but I know there are people on this forum that have the knowledge I need to help make this a reality, and any help is appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

Yes, this is something that needs to be expanded upon.  As far as I understand it the CMS is just another module like any other.  What happens is that as a url is called, it is checked against the module name first (i.e. /checkout goes to the checkout module).  If it does not find that then it looks into the CMS table and if it finds a corresponding entry will pull up that page and if it doesn’t, the default 404 page is called no-route (an editable CMS page).  I believe that the CMS might be expanded upon on 1.1 but probably not to the extent that you are looking into for it.  Most of Magento is controlled by the ‘controllers’ and the actions defined in the code.  From there it loads the resource code and the associated blocks for display (hence the MVC pattern).  As you can see in my Wiki about custom database tables, the default functions you get from extending the base code allow access to the database table’s defined in the XML configuration.  You can override those functions if need be but usually they are enough and they extend the database abstraction in the Zend framework.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

On a slightly separate, but very important note, can you explain how Magento decides what the content is, and where to get it? It would be nice if I could go look at the exact function it uses to decide what to go get when you say getChildHtml(’content’)

Now for the CMS: The CMS as it exists now holds all of the HTML and Magento Code (?) for a page’s content area, so it should be a simple database call for Magento. “Get the contents of this page and put them between this code and this code, and you have yourself a page.” Thats not what I want for my CMS, because I don’t want my clients to have to deal with all of the code involved in a given content block. I wanted them to be able to deal with simple pieces of information such as the title, what images to use, etc.

Would it be plausible to have my CMS store it’s individual pieces of data in the database, while at the same time “render” those pieces of data into the full code block, and enter them into Magento’s CMS? Effectively making my CMS a a CMS for Magneto’s CMS? If so, how do you suggest that I go about storing the content block that those pieces of information would go into?

Do you have another suggestion about how I might accomplish what I’m after?

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

I know what you are getting at and sure it is doable but quite a bit of work and I’m trying to think if there is a better way.  Basically you want to use the tab like functionality of the admin section to define sections of a CMS page that are editable without using strict html code.  The part where you extend the Edit screen to do that, seems like that would be easy enough.  I would have to look at how the CMS displays it’s blocks to see how easy it would be to only show certain sections based on a template.  But what you are proposing might overcomplicate it a bit, I would think we would be able to extend the CMS module as is.  A new version of the 1.1 branch just got released so I am trying it out right now to see if there are any improvements.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

i assume you mean 1.1Beta? I don’t see 1.1* on the download page.

The reason that i’m not sure that editing the existing CMS will work, is because each page would have different information to collect. For example, the homepage might have a title and 3 main images, while the about us page would have a person’s name and bio. I think the best way to do it would be to have different tables and subsections under my CMS for each page. “My CMS > Home Page”, though i’m not sure the correct name for it. In your example wiki for creating a module you have the Module name, and then Items, (and a Manage Items link,) what is that part called? i think we should have one of those for each page.

That part doesn’t seem to hard to do in Magento. The part that i’m still confused about is how to tell Magento to look up specific phtml files for each address. So if my CMS is called SCMS, I would want mysite.com/about-us to bring up SCMS/aboutus.phtml Any ideas on how to do that, or specifics on another method?

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

Hmm, it would have to be through the controller class I would think.  Depending on what is given, it would match against a database key (like the url key) and then pull up the associated file by using maybe a setTemplate().  On the other hand, one of the benefits of storing it in the database is that if the url that is given matches the key in the database you can have more control over what is there without relying on a bunch of templates that you have to create.  Would you put together the initial design and then create the editable sections in the database and that is what the user would modify?  Or are you trying to automatically pull in the data based on flags in the template file?  Also one solution might be that you pass the custom module->www.example.com/mymodule/cmspage and then use .htaccess to rewrite that too->www.example.com/cmspage, that way we don’t have to hijack the CMS page’s ability to catch all the pages.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

Either an htaccess trick or hijacking the CMS. htaccess would probably be easier.

I’m looking to create the template file, and then have a database, lets say SCMS_aboutus, where each row in the table is another person, with a name, phone number, email address, and bio. So you would go to mysite.com/aboutus, it would pull up SCMS/aboutus.phtml, and then phtml would use SCMS’s controller class to load the table rows and insert them into the template.

The problem is that I don’t know how to tell Magento that mysite.com/aboutus should bring up the SCMS template file. Thats the biggest part I need yourhelp on right now.

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

Alright, well the easiest way to accomplish this is pretty much all there.  If you use the Module Creator, it will give you all of the setup you need.  Let us say that you create a module with the namespace of ‘SCMS’ and a module name of ‘aboutus’.  If you go to http://www.example.com/aboutus it will bring up your page.  Then it is just a matter of formatting the display to pull out all the data and iterate through it with a foreach loop which should be in the example template file.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

Keep in mind you will have to edit the sql php file with your database fields before you actually navigate to it so it installs what you want the first time.  In addition, you can use the get<Fieldname>() function to pull down the data you need.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

About the install script, is there a way to get Magento to re-install a module? How does it know to install it in the first place?

Thanks for all your help. My learning curve in the last 24 hours has been substantial.

 
Magento Community Magento Community
Magento Community
Magento Community
 
alistek
Sr. Member
 
Total Posts:  293
Joined:  2008-04-02
Normal, IL
 

This is quoted from the main thread about custom databases by Danieln:

Magento checks the config xml file for module name and version. if you disable cache, it’s checking this on every call. If you go to your database to table ‘core_resources’ you’ll find you module and version. If you delete this record (and your module’s table) magento is installing your module upon next request.

-Adam

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top