Friday, February 25, 2011

Pointers in Python resemble variable assignments in PHP5

I encountered the PHP5 clone operator '=&' and a very good illustration of its use. Incidentally, PHP5 variable assignment resembles the use of pointers in Python.

In short, a variable assignment in PHP is a reference to the assignment object. If an object ( $pointer = object ) is reassigned ( object = 'foo'; ), the pointer will reference the OLD object ( $pointer = object ). If however you clone the object ( $clone =& object), when the object is reassigned, ( object = 'foo' ), clone will change as well ( $clone = 'foo' ).

Cloning, then, is making the variable operand synonymous with its counterpart, rather than a reference to the counterpart. There are some particularly enlightening examples of 'clone' aka '=&' on php.net.

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.

Tuesday, February 15, 2011

Eclipse updates pt 1

This day has allowed me to explore the capabilities of Eclipse as a standards-based SDK. Perhaps not news to those who already use it for such, but since I use Flash Builder almost exclusively for Flash-based development, this is fresh territory. This further exploration came about as the result of a recent back-end dev project where the IDE options played out as either:
  • TextMate
  • vi on the Terminal CLI
  • Coda
I haven't delved into Coda, though I have a good amount of exposure on the other two. Let me state for the record that I endorse the viability and value of TextMate as an IDE. Now, clarifications duly stated, I would like an IDE that provides:
  • managing repositories such as svn and git
  • code lookup and completion for JavaScript, including 3rd party libraries
  • code lookup and completion for PHP
  • bracket pairing assistance that is broadside-of-a-barn obvious
  • local file, folder and directory management
  • quick access to function and property definitions (cmd-click seeking)
  • optionally, FTP management
I'd be happy to address which of these are addressed to my satisfaction in the above-listed IDEs, but for now I will summarily say none of them hit all the targets. That could be due to my own habits - perhaps blinders on my part - I would love nothing more than to be further educated on this. Beyond that, some of the newer PHP frameworks at large (CodeIgniter, CakePHP, Symfony) boast unit testing, and I would prefer an IDE with debugging breakpoints and object inspection so I can see what fury my code hath wrought in the runtime.

Thus far, I have done the following to spec up Eclipse:
  1. Update to Eclipse Helios 3.6
  2. Install PHP and JavaScript language packs for Eclipse
  3. Install eGit for Helios (tested and working)
  4. Install Aptana (see mild apprehension*)
  5. Install Eclipse Web Tools
*Aptana bills itself as:
a set of application development tools for Web 2.0 and ajax for use with programming languages such as JavaScript, Ruby, PHP and Python.
They had a big buzz out of the gate as a premium solution vendor to the open-source community. By late 2009 their revenue stream was lacking to the point of significant downscaling and they have consequently reduced their support and development staff. Their current 2.x release is bemoaned as unpredictable, buggy and meretricious, resulting in retrograde support for the deprecated 1.5 version package. Furthermore, Aptana was aquired less than a month ago by an outfit called Appcelerator. In short, Aptana has a legacy of step-child treatment.

Thus my concern with installing and testing out Aptana. Since it is one of only two commonly-employed means of third-party javascript code completion, I went ahead with it. Installing Aptana is the first step. Following success with that, its proprietary set of plug-ins allows jQuery to work with it. I succeeded with the first part, but unfortunately their plug-in service has proven to be currently offline. On to the next option: Eclipse Web Tools.

Eclipse Galileo 3.5 to Helios 3.6

I did Windows for a long time. And I'm still ok with it (though I stopped upgrading at XP SP2). Just the same, I'm all in with Mac for the past couple of years. The wherefore comes down to OS X, and more specifically, Unix. Can't beat having an underlying layer of open source OS!

I'm upgrading Eclipse today. I had announced with great fanfare the coming of Eclipse Galileo, but Helios found me focused on other things, so I'm stepping up the SDK to 3.6 now. On the Windows/Mac front, I prefer the small install and configuration footprint of unix apps vs the windows registry. Power Windows users may opine otherwise, but I find the modularity of apps on the mac to be quite painless.

That said, I'm opting not for a clean install of Eclipse 3.6, but rather an upgrade from 3.5 using the software updates dialog. A little background, I use both Flash Builder and Eclipse on my MacBook, the former for AS3 and Eclipse for JS, PHP, Python, basically 'everything else'. I have added Subversive SVN to FB and it works great, and with the possible exception of mylyn in the future, I plan to keep FB in quarantine. (update: broke my own rule there, I added eGit to FB and it is flawless.)

This is just a safety, as I have had issues with other FB installs going off the rails when too many open-source libraries are added to the SDK. It can be a real train wreck when this happens, especially if you're facing a killer deadline. For the record, any deficiencies with Eclipse as a platform are simply the small and acceptable dark side to a robust and maverick developer community. So I keep FB static and use Eclipse as my test lab.

As for the SDK upgrade, it worked great. Here is a simple FAQ from Eclipse to follow. When the dialog presents you with a list of available upgrades, choose only those listed as 3.6. Better not to upgrade too many things all at once.

This is part of a larger operation which I will also post about. Namely, getting a JS/PHP/Git environment up and running within the Eclipse SDK. I've worked with TextMate thus far and will sing its charms, however, I've used Eclipse long enough to love what it does, so developing in a fully Integrated DE is my goal.

Thursday, February 10, 2011

MVC PHP CakePHP vs Symfony

Yet more to consider:

http://stackoverflow.com/questions/1242060/symfony-vs-cakephp

Symfony is another contender.

MVC PHP Frameworks Evaluated

PHP frameworks are my current focus, particularly CodeIgniter. I have extensive experience with AS MVC frameworks, e.g. Cairngorm, RobotLegs, and Mate. Following a recent project, my thoughts on PHP frameworks are starting to crystallize. Here incidentally is IMO one of the best summaries on CI from the community at large, reposted courtesy of Action on this stackoverflow post :
CodeIgniter is, without a doubt, the most well-documented and approachable PHP MVC framework out there. CakePHP's documentation is also very good, but the learning curve is slightly higher.
  • CodeIgniter's models are optional and serve no function other than code separation. There's no integrated CRUD and its "Active Record" class is really just an alternative SQL syntax. It also doesn't support table associations. So, you will be building many large queries essentially from scratch. CakePHP's models are far more advanced and similar to those in Ruby on Rails. It supports table associations, has integrated CRUD, and behaviors. In addition, CakePHP has command line tools (Bake) that allow you to generate all the code for basic CRUD operations. Tweak a few things here and there and you've got a working prototype in minutes.
  • CodeIgniter lacks some essential libraries that are needed in most applications (i.e. Authentication and ACL). You will need to rely on 3rd party libraries in many of your applications. CakePHP has integrated Auth and ACL, but both frameworks integrate with 3rd party libraries easily.
  • Since CodeIgniter lacks much of the automation that CakePHP brings, there are no strict conventions to follow (this can be viewed as good or bad). This makes CodeIgniter a more flexible framework. Furthermore, its lack of features and automation do give it an advantage when it comes to speed. CodeIgniter is one of the fastest PHP MVC frameworks out there. That said, the framework is rarely the bottleneck in your in application...and you should be choosing a framework based on productivity, not its execution speed.
  • Both frameworks have large and helpful communities. CodeIgniter has their official forums and an IRC channel. CakePHP has a google group and an active IRC channel. CakePHP is currently the most popular PHP MVC framework with the largest community behind it.
In conclusion, if you want a fast, flexible, well-documented framework, and don't mind writing extra code and relying on 3rd party libraries, go with CodeIgniter. If you want a powerful, feature-rich framework that does most of the heavy lifting through automation, and you don't mind having to follow strict conventions, go with CakePHP.
As you can see, it is a comparison of CI with another framework, CakePHP, which is now on my shortlist to test out. Here is a Google Trends search of the relative trendiness of these two open-source frameworks (update: now three OS frameworks with symfony).

http://www.google.com/trends?q=codeigniter%2C+cakephp%2C+symfony&ctab=0&geo=all&date=all&sort=0

CakePHP has an earlier footprint. Next, I will examine CakePHP support of php5. I'm curious to know of any more advanced, more OO and generally more hurricane-nestled-in-a-typhoon-wrapped-in-a-tornado PHP frameworks out there. I would prefer a stricter MVC pattern with a higher degree of decoupling.