Above the ecommerce part like adding/modifying products, it also has a built-in CMS. It looks quite useful. Not very powerful though. It just evaluates html code and not php. In most of the time this is prefered by the way. Because of security risks and things like that. But there are also cases which you want to do if you are importing something to magento or if you are just wanting to do in a quick and dirty way!
Fetured Links
Well, the workarounds you find are not quite good. Simply they just take the CMS code, write it to a temporary file and include it, or writing a bit complicated parser inspired from joomla/mambo. Check out here for the details of the workaround. The tutorial I’m putting here is from there to, however I will also try to write solutions to problems that I have encountered (mostly because of magento versions).
This tutorial is working for magento version 1.1.8. You can download the latest version from here.
Now open up your favorite php/xml/html editor. While it will open up, also open your magento installation folder. Magento has a lots of folders for lots of things, which I do not know why. The code part is in app/ directory as you may guess. In the app folder you will find the etc/ where there are configurations for magento generally. Our PHP Code will be a module to the Magento, so we have to go modules directory and create a new xml file, named according to your module. The syntax is like: Parkyeri_customPHP. The first part till underscore means the name of the module, int this case Parkyeri. The second part indicates the component of the module. So you may have different components in one module, in this case customPHP, If we are talking about custom codded PHP pages, so in this module named Parkyeri, there can be different pages like: About, Contact, Jobs. And these are all different components, doing different things. If we were trying to create the About page then we had to use something like Parkyeri_About. You can add all of them in the same xml file.
Open up /app/etc/modules/ and create a file named Parkyeri.xml (the name of the module) and add these lines to file:
- <config>
- <modules>
- <parkyeri_customphp>
- <active>true</active>
- <codepool>local</codepool>
- </parkyeri_customphp>
- </modules>
- </config>
As you get it now we pass to the next stage. Now open up app/code/local/Parkyeri/customPHP/etc/ and create a file named config.xml (the default configuration file name for every module.) and add these lines in it.
- <config>
- <global>
- <blocks>
- <parkyeri_customphp>
- <class>Parkyeri_customPHP_Block</class>
- </parkyeri_customphp>
- </blocks>
- </global>
- </config>
Now the fun part, open up app/code/local/Parkyeri/customPHP/Block and create a file named Test.php and add these lines in it:
- class Parkyeri_customPHP_Block_Test extends Mage_Core_Block_Abstract
- {
- protected function _toHtml()
- {
- //put here your custom PHP code with output in $html;
- //use arguments like $this->getMyParam1() , $this->getAnotherParam()
- $html = "Hello" . $this->getWorld();
- return $html;
- }
- }
So, we have finally reached the part which you are most comfortable, writing code! You will write down all the code you want to evaluate in this file. The _toHtml() method is called when you call it in the cms part. A magical function just like toString(). As you may remark the name of the class, is conventional according to the location of the class. That was how the previous configuration knew where to look when mapping.
And the final part is to embed it in the CMS, this is easy part. But the part where you get dissapointed most.
Add this to page you want to show your custom php code:
- {{block type="parkyeri_customphp/test" world="World"}}
So this was it! Did it worked? No I didn’t did it? The real reason that it did not worked, is because, you did not refresh the caching system!! Yes, it’s that simple! It gave me a lots of headache though, hope it won’t to you. You can disable the caching from System -> Cache Management by the way. Better then refreshing every time :)
We are professional Magento Development Company based in India providing Magento eCommerce development services, Magento customization , Magento themes at affordable rate. We’ve been working with Magento development since the early days when the platform just came out in early 2008 and have been using it ever since.
Net World Solutions.
India:
Telephone : +91 088 26147 606 (Delhi, India)
Email Id : info@networldsolutions.org
Business Partners : http://find4sites.com
Website: http://www.networldsolutions.org/magento_development_solutions.php