PHP Framework IDE: PhpED for Magento
|
In this tutorial we will go over creating a simple module in Magento - a popular Php Framework, or more exactly e-commerce platform. We are using
We will demonstrate NuSphere's PHP IDE's support for Magento, just like for any other PHP Framework specifically the use of code completion, code navigation and debugging of the framework. For example, we will show how PhpED displays all of the Magento's classes, interfaces, functions etc in its Code Explorer. We will be adding a simple Hello World like module "helloworld" to Magento.
Setting up PhpED Project for Magento
The easiest way to setup any project in PhpED is to run the Project Wizard. Below are the screenshots of the wizard setting up the project called "magento". It will have magento source in the project tree and setup php debugger to work on magento projects. Below are the most important pages of the wizard:
- Select webserver located on the this machine for magento project:
|
|
|
- The following are recommended selections for Web Document root and Web Root URL with the installation structure like ours:
|
|
|
- On the next pages set the Porject Root directory to C:\xampp\htdocs\magento - this will include all of magento directories and files into your project:
|
|
|
- On the subsequent screens if the debugger is not installed on your localhost yet the wizard will note the problem and offer to install it - accept the prompt and other default selections, finally you should end up with this debugger check window:
|
|
|
After that you are all set with your magento project. Immediately you can see the hierarchy of Magento's PHP objects, classes, functions, interfaces etc in PhpED Code Explorer:
|
|
|
Adding new custom module to Magento
To add our module to magento we need to create a directory structure for it - all can be done using PhpED's menus:
|
|
|
We will make directories
app/code/local/phpedtutorial/helloworld/Block
app/code/local/phpedtutorial/helloworld/controllers
app/code/local/phpedtutorial/helloworld/etc
app/code/local/phpedtutorial/helloworld/Helper
app/code/local/phpedtutorial/helloworld/Model
app/code/local/phpedtutorial/helloworld/sql
and make a new configuration file for the module
(app/code/local/phpedtutorial/
helloworld/etc/config.xml):
|
|
|
(code folding and syntax color highliting are available not just for PHP but for the most of the languages used on the web)
PHP Code Completion for Magento
We will also make a number of other files required by Magento to activate the module
Now we can add our own controller and in process of doing that see how PHP IDE helps with code completion for Magento classes and functions:
|
|
|
Finally we can proceed with PHP code for our module to demonstrate debugging.
Debugging Magento with PHP IDE
We will demonstrate debugging in PhpED by stopping at and stepping through the code in our new controller. With the setup described above starting the debugger is extremely simple:
Set the break point in your new controller file IndexController.php opened in PHP Editor
|
|
|
Open index.php file in the editor as your starting point
Start debugging by pressing Run in debugger button (F9) in PhpED
|
|
|
By default the execution breaks on the first line of the code in index.php, but you can change this by unchecking the corresponding box in Project->Properties->Debugger Settings or if you want to do the system wide change the same UI is available under Tools->Settings-Run & Debug. If you do stop in index.php you can step through magento code and inspect what's going on in Mage.php file - or just hit Run in debugger again to continue to your code.
|
|
|
Now simply type in the url triggering the controller in the browser (we are using PhpED's built in Chrome browser, but you can choose either any external browser on your computer or built in Firefox or Internet Explorer). Debugging session continues and the process will stop at the break point
As you can see on the picture above you can now step through the code , inspect and watch the variables , reassign the values on the fly etc.
In our example the output of new magento's module will be shown in PhpED's built-in browser
|
|
|
Other ways to invoke Php Debugger
You can also make use of DebugBreak() function available when you have dbg debugger installed. When this function is hit in the code it invokes debugger automatically
Another way to start the debugger is by using NuSphere DBG toolbar available in IE or Firefox browsers - simply point your browser to the page you want and select Debug from the toolbar's menu. There is also an option to start debugging session on the next page (after you click a link on the current page)
In this tutorial we find out how to debug PHP code written with Magento and use PhpED's powerful code intelisense with Magento - or any other PHP Framework. Download PhpED's FREE trial at https://nusphere.com/download.php.ide.htm and see for yourself how NuSphere PHP IDE works with PHP Frameworks
|
|
Download NuSphere PHP IDE
Download a free trial of the fast PHP EDitor and robust Integrated Development Environment for PHP.
|
Buy NuSphere PhpED® now
|
Special Team4 Offer
Get 4 copies of PhpED for the price of 3!
Optimum solution for development teams.
|
|
Need more than 4 licenses? Contact Us for more quantity discounts, please use "Ordering/Payment issue" subject on the form.
|
|
|