|
posted 09/8/2008 by Chris
First off, I'd like to put it out there that my bias in this article partially exists to help spark debate - although it's based on my real opinion. I think the CakePHP framework is a very helpful tool in building websites. Although, I try to rely on cake as little as possible.
Why? Because if for some unforeseen reason I someday want to either use another framework instead or build my own framework from scratch, then every line of code using cake's api must be edited. I'm perfectly fine with this fact in relation to certain tasks - database interaction, friendly url routing, overall project organization, etc. But I feel like some of cake's features are unnecessary, or even a bad idea.
The unnecessary CakePHP features I am going to target in this article are found in helper classes. The functions in question can be found in the FormHelper and HtmlHelper classes.
EXAMPLE #1 = Creating a text input field for a form
Using the 1.1 core, I create a text input object using the HtmlHelper class like this : <?php echo $html->input('Supporter/name', array('value'=>'', 'style'=>'width:200px;')); ?>
Using the 1.2 core, I create a text input object using the FormHelper class like this : <?php echo $form->text('Supporter.name', array('value'=>'', 'style'=>'width:200px;')); ?>
Using normal html, I create the same text input object like this : <input type="text" name="data[Supporter][name]" id="SupporterName" value="" style="width:200px;" />
EXAMPLE #2 = Creating a tag to include a css file
Using the 1.1 core, I create a tag to include a css file using the HtmlHelper class like this : <?php echo $html->css("stylesheet"); ?>
Using the 1.2 core, I create a tag to include a css file using the HtmlHelper class like this : <?php echo $html->css("stylesheet"); ?>
Using normal html, I create a tag to include a css file like this : <link rel="stylesheet" type="text/css" href="<?php echo $this->webroot;?>css/stylesheet.css" />
Hopefully the above examples show that using helper functions to output a single line of code can be more work than simply writing the code yourself. In the first example, an upgrade from core 1.1.to 1.2 required changes, while using the actual html required no change. The code to actually create the html also seems equally complex (if not less complex) as either api calls. In the second example, no changes were needed when upgrading cores, but the complexity of the actual html does not seem more intense.
So, in the long run I feel that avoiding CakePHP's HtmlHelper and FormHelper classes is the best long-term option. Do you have an example of a helpful cakephp helper? Or do you disagree with me? Please send me an e-mail or leave a comment below. COMMENTS (displaying 0 comments) POST (leave a comment) |
POPULAR BLOG TAGS
spam
sports
php
geek
debuggeddesigns
whoami
snowboard
defcon
quicksilver
security
bakery
published
google
code
1984
youtube
color
boston
trice
release
email
mbta
ableton
rot13
charlie
mit
launch
class
open source
gmail
regular expressions
usort
routes
magazine
drum machines
captcha
cakephp
science
orwell
brain
general
php5tube
skateboard
mailto
privacy
hobnox
encryption
as
flash
germans
|