cancel
Showing results for 
Search instead for 
Did you mean: 

Running PHP code within Magento environment

Running PHP code within Magento environment

Hi,

We are new to using PHP within the Magento2 environment and have a question.

 

We are able to display the PHP page by just using the URL : https://southernrecords.co.uk/music.php but as you can see this just displays it in it's own tab.
What we are trying to achieve is for it to be displayed as part of the system within the Magento window like things display on the home page

 

Are we missing something smple or is there more to it than we think?

Any help would really be appreciated

Thanks
Rich

 

3 REPLIES 3

Re: Running PHP code within Magento environment

Short of integrating the code into your Magento code base as a module, you could try putting it in an iframe inside of a CMS page.

 

Go to Admin -> Content -> Pages, then Add a new page.

Fill out the following fields (if you're using PageBuilder):

Page Title: Music (or whatever you want to call it)

Search Engine Optimization -> URL Key: music   (this will make it accessible at /music) 

Content: You'll need to drag the HTML block to the content section

cmspagehtml.png

 

Then click the little gear icon to edit the HTML.

cmspagehtml2.png

 

Add the following HTML to that block:  

 

<iframe src="https://southernrecords.co.uk/music.php" frameborder=0 width="100%" height="100%" />

Click save at the top, then go to your site's address with /music

 

It's definitely not an ideal solution. You should add that code as a module to M2 instead.

 

Re: Running PHP code within Magento environment

Hi Seanbreeden,

 

Thanks for your reply - that works a treat, thanks

 

We have just created a "Hello World" module which works if you point to the URL but how would we include that as part of our Magento site as we would probably want to add other functionality and would be best to do it properly 

 

Thanks again for your help

Rich

Re: Running PHP code within Magento environment

Hi,

 

The iFrame option worked fine but for future development we would like to know the best approach to including the PHP as part of the system.

Can you give us any guidence on how to do this

 

Thanks

Rich