Showing posts with label cakephp. Show all posts
Showing posts with label cakephp. Show all posts

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...

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.