3. Create your custom PHP code: app/code/local/Mayerwin/Custom/Block/Test.php
<?php
class Mayerwin_Custom_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()
Thank you very much! That’s great! I couldn’t guess how to do that. Maybe it should be added to the Wiki or KB so that it could benefit to many people in other circumstances.
I love the way things are secured and organized in Magento (although at the beginning you’re not used to it).
Well, I have tried your solution, with $html = “Hello world” inside Test.php, but nothing shows up. Is there a mistake somewhere? Again, there is no doc regarding this so I can’t check by myself :-(.
As for my previous solutions, there are problems with variables that become undefined if they are not in the same <?php ?>. So I’m even more interested in your solution.
I also checked this : http://www.magentocommerce.com/wiki/how_to_create_an_admin_form_module but it’s not very appropriate (for admin modules apparently).
Ok, it now works perfectly! Thank you Moshe for your speed and acurracy, I appreciate a lot. There is no doubt this will be also helpful for others who want to embed some custom PHP.
This new way of building a website is not easy but I think I start understanding the positive aspects in the long term. And it is probable that as time goes on, more non-developers-friendly CMS features will become available in the back-end (just like those offered by Joomla). But even right now, thanks to your help, I have already managed to migrate my whole PHP website (mainly CMS pages, the store was not completed before) to Magento and I will take the most of the multi-website engine.
By the way, have you any idea concerning the possibility to display a CMS page or Static Block to several stores (cf. this feature request : http://www.magentocommerce.com/boards/viewthread/4179/) instead of all stores or only one of them?
I’ve been following this, and I would highly suggest adding PHP support for CMS pages. Perhaps as like a little check box or ratio boxes that would enable or disable PHP, HTML… etc.
My company works on motorcycles and sells parts. We would like to be able to provide our customers with a tool to check up the status of their bike when it is in the shop.
I was thinking about having a CMS page that would redirect the customers to another page relative to their account name.
I’m not against writing the custom module, but would there be a way to do this without creating a custom module?
I feel like I should be able to do something like:
Sure, you may also create a new template file for your page (which is a phtml file, found in app\design\frontend\default\default\template\page), and insert your PHP code at the very beginning of this file.
To be able to select this template in the back-end, you should then declare it in app\code\core\Mage\Cms\etc\config.xml just by duplicating the lines like this ones :
i just wanted to say thanks for this thread
while i currently have no need for php in my cms, its great to know that its possible, and i might design for it in the future knowing that
thank for all the great explaining. I´m trying to integrate the Phorum php-based forum into my up an coming Magento Shop. However when following your instructions to get the MayerErwin HelloWorld example running I run into a Mage tracing error:
I do use the TelescopeTheme - may be an issue there, since the inline translation does not work with that template either?
While both mage and phorum seem to work fine, the integration piece seems to be som while of yet…
Moshe: is there any reason this would suddenly stop working? Was working fine on a local site, we moved today to our own dedicated server and the PHP inside the CMS you wrote at the top of the page no longer works - just doesn’t do anything...?
Hello and thank you for all of your help on these forums, just reading your answers to other peoples issues has helped me immensely in setting up Magneto.
I have tried the code you posted at the top of this page and it does not seem to be working correctly in 1.0.19870.1. To test I am setting $html = “Hello World”; inside of the Test function right above the return statement and I am not getting any output on the CMS page. I however can confirm it is entering this function because I can echo text from this function and it displays on the page, such as echo “Hello Echo”;.
Also how can these blocks receive query string variables? I am trying to add some sorting functionality to a small data grid display I have.
Any insight?
UPDATE: Never mind, it just started working.... odd. Also as far as receiving q-string variables it seems we can still use the super globals, so that solves my 2nd question. Thanks again!
I am trying to do this and so far it seems like the right path for what I need to do I need to allow my custom to upload an image to go onto a t-shirt this is done on the catalog-product-view page when the user is ready to add the item to the cart they will upload an image and then the item will be added to the cart I have followed Moshe’s directions and the form displays fine but when I submit the form it will not post back to the module it posts back to the catalog-product-view page and I cannot seem to figure this out I have tried $_SERVER[’PHPSELF’] (posts to product view) I have hard coded the module and got client denied by server configuration: /var/www/internal_oscommerce/magento_apparel/app/code/loca
l/Mayerwin/Custom/Block/Test.php, referer: http://domain.com/grid/magento_apparel/index.php/default/cotton-t-shirt/Blank-t-shirt.html
if I creat a new php file in the root of the site to handle the upload after submit i get “not found The requested URL /var/www/internal_oscommerce/magento_apparel/index.php was not found on this server.”
I don’t know what else to do. can someone please help me…
Here is my code and Thank you in advance for your help.
<?php
class Mayerwin_Custom_Block_Test extends Mage_Core_Block_Abstract { protected function _toHtml() { $html = "";
$html .="</p></form></p></div></div>"; } // put here your custom PHP code with output in $html; // use arguments like $this->getMyParam1() , $this->getAnotherParam()
All other files are exactly as posted by moshe. Is there something I have done wrong? Am I misunderstanding? I am a little confused on the parameters, I removed them and still didn’t get any results.