Friday, February 25, 2011

Integrating MAMP PHP and Eclipse PDT for CakePHP Debugging

There are a few steps necessary to get Eclipse PDT, MAMP, and a CakePHP app synchronized for debugging. Summarily, after adding the Zend Debugger to Eclipse, the php initialization file in MAMP must be modified so it can respond to Eclipse. MAMP is not pre-configured for use with Zend Debugger, so you must edit the php.ini file for MAMP. Find the location of this file in the phpinfo tab of MAMP (near the bottom in the screenshot):

Open this in a text editor such as vim, and you will find this info near the bottom (italicized configuration info added at this step):

[xdebug]
;zend_extension="/Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

[Zend]
zend_extension="/Applications/MAMP/Library/modules/zend/ZendDebugger.so"
zend_debugger.allow_hosts=127.0.0.1
; zend_debugger.expose_remotely=always


Now that you have detailed the location of ZendDebugger.so, you need to actually add a copy of the file in that location. Go ahead and put a copy of ZendDebugger.co (which either you have already downloaded into your Eclipse plugin filesystem, or you can download it as part of the Zend Debugger package ) into this directory. Incidentally, ZendDebugger.co can be where ever you like, so long as the path in php.ini resolves to it.

Comment out any references to zend in php.ini, other than the ones in italics above. In addition, comment out xdebug references if they are not already commented out.

Finally, restart MAMP and look for this confirmation in your restarted phpinfo():


If debugging in Eclipse succeeds, the debugger will halt at the first instruction. Be sure to step through a few instructions (F5) to ensure it is working properly. Here is a thoughtful and concise external resource to follow as a further guideline.

Incidentally, CakePHP:


As stated above, this guide will help you get debugging to work with CakePHP. That part of the process entails a further step. Once you are in Eclipse debugging a CakePHP project, you may find the debugger prompts you to resolve the location of core php files as it steps through them. This will happen, for instance, when you debug CakePHP apps you have created by using the cake bake CLI prompt.

To resolve these prompts, simply make sure the following conditions are met:
  1. Your CakePHP app is in a project folder in Eclipse ( it has to be! )
  2. Your CakePHP core library is in a project folder in Eclipse. This way, the files are available to the IDE so Eclipse can step through them in a debug process.
This is a unique requirement of CakePHP. Since you are building from an external core library and debugging involves the core, it has to be in the IDE.

Wednesday, February 23, 2011

CakePHP / Eclipse Project Integration

Creating projects in Eclipse that work with CakeBake is a multi-step process consisting of:
  1. Initiate a new PHP Project in Eclipse, e.g. php_project
    • enable JavaScript code checkbox
  2. Create your initial database so you can input the settings in step 3.
  3. In Terminal, run cake bake /path/to/php_project
    • add database settings if you have them
    • heed this info if you are using MAMP and the database does not resolve
  4. Use eGit or SVN in Eclipse to bring in any plugins you may need
  5. Configure Run > External Tools > External Tools Configurations to run further operation such as
    • cake bake model
    • cake bake view
    • cake bake controller
  6. You can also simply use Terminal to invoke interactive cake commands. Refresh Eclipse to see subsequent filesystem changes.
See this earlier integration post for more background.

Tuesday, February 22, 2011

Authorization in CakePHP

From the Cake Book 1.3:
User authentication systems are a common part of many web applications. In CakePHP there are several systems for authenticating users, each of which provides different options. At its core the authentication component will check to see if a user has an account with a site. If they do, the component will give access to that user to the complete site.
In short, authentication is a turnkey option in CakePHP. All you need to do to enable it is open and edit your app controller at site_name/app/app_controller.php, adding:

var $components = array('Auth');

This single line will implicitly password-protect your entire site. For explicit, group-or-user-based password protection, add to Auth the ACL:
This component can be combined with the ACL (access control lists) component to create more complex levels of access within a site. The ACL Component, for example, could allow you to grant one user access to public site areas, while granting another user access to protected administrative portions of the site.

CakePHP's AuthComponent can be used to create such a system easily and quickly.
Finally, don't forget to run by the fridge for a cold can of PBR, 'cause you're going to want to celebrate the ease of this authentication framework.

Thursday, February 17, 2011

CakePHP Cake Bake is Awesome

After taking CakePHP's Cake Bake CLI for a spin, I find myself exclaiming aloud:
This is good cake.
Following loads of exploration in IDEs and PHP MVC options, I have CakePHP running on Eclipse, served by MAMP Apache and MySQL, and debug enabled by PDT. Incidentally, this how-to on CakePHP/Eclipse integration from power-user rynop is invaulable.

View along with me as I run through a friendly interactive prompt called Cake Bake from within the Eclipse console. This will summarily build out the underpinnings of my entire site structure - model, view and controller - along with push-button validation (!!):


Note: working CakePHP install in Eclipse. Menu is Run > External Tools > Cake bake


Says the interactive shell script:


---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)


I can has cake - so simple!


Select validation options from the list


Look okay? *nods and pops open a beer*

So good! I will detail further on this. Gotta drink my beer now...

Wednesday, February 16, 2011

Zend Debugger for PDT

If you are attempting to debug in PHP, PDT is your answer. Listed in Software Updates as the Zend Debugger Feature, it can be plugged into your Eclipse build via the following address:

http://downloads.zend.com/pdt

It's free and it works seamlessly in conjunction with MAMP. When you run it, debug dialog is displayed in the panels in the Eclipse IDE. Objects can be halted via breakpoints for inspection.

Something else that is not free but I'm evaluating in response to upward trending: JetBrains PHPStorm IDE. On initial inspection, seems to offer the same web tools as Eclipse offers.

As a potential mid-weight candidate between TextMate and Eclipse, it could bust the whole thing wide open. After all, informative and easy's all I'm asking for, doesn't matter who provides it. Open source development is fine, but it tends to force platform specialization on the end user. I don't mind paying to avoid that.

Eclipse IDE with Aptana

I had recently set up Aptana on Eclipse to test out HTML5/JS/CSS/PHP integrated development. Among the options:
  • WTP
  • Aptana Stand-alone
  • Aptana Plug in
  • JSEclipse
I have tested them all, starting with Aptana. At the time, the plug-in server they offer was down, so I moved on. The other options were found lacking in particulars previously detailed. Now the plug-in service is back online, so I revisited it. The verdict: In hindsight, I'm glad it was down so I could see what other options are available. Now that it is working, I can thoroughly endorse this solution. Here's why:

Full AC functionality:


Enable third-party js libraries:


Predictive incorporation of project libraries:

Rails, Python, and PHP Debug support:


I will see about PHP frameworks with unit testing next. Ah the comforts of a comprehensive IDE.

Eclipse IDE Part 2

To summarize the posts before this one, I have been exhaustively demoing IDEs for standards-based Web 2.0 site development. My prerequisites, assuming these items can be met in the vendor community, are the following:
  • Content Assist for multiple languages (JS, PHP, Python)
  • functional debug perspective for PHP and Python
  • ability to add 3rd party and custom libraries to CA
  • integrated repo management
  • integrated file management
  • launch run/debug perspective from IDE
I've tested out the latest Eclipse release, Helios, which I use for AS3, under several configurations, including:
  • Eclipse Helios EE IDE, which includes the WTP and JSDT
  • Aptana plugin for Eclipse
  • JSEclipse
Collectively and individually, the results were less than ideal. At worst, I had a good editor environment with Aptana for CSS and HTML but no luck with JavaScript CA in Aptana. I did not have success with JSEclipse.

At best, Helios EE IDE provides CA only upon demand (ctrl+space), even when the preferences are set to insert CA automatically without delay. JQuery can be integrated, there is a process detailed here. I found the procedure to work though it leaves no provision to include further 3rd party JS.