Recent Posts
- (02/24) Calling an Element from a Helper TAGS:CakephpWeb ProgrammingUsageTutorialExample
- (10/14) Forcing A Single Join in CakePHP PaginationTAGS:CakephpCakephp 13DatabaseErrorsHabtmMysqlMssqlWeb ProgrammingUsage
- (08/11) Inserting NOW() into MySQL Using CakePHPTAGS:CakephpDatabaseMysqlMssqlWeb ProgrammingUsage
- (08/07) Best PaginateCount for CakePHP - with Group By SupportTAGS:CakephpBehaviorsWeb ProgrammingUsageDatabaseExampleMysqlHabtmHack
- (04/03) CakePHP Error Messages Not Showing on FormTAGS:CakephpCakephp 13Web ProgrammingErrorsUsage
- (02/06) Sorting Paginated Results Using a Related Model Field in CakePHPTAGS:CakephpWeb ProgrammingUsageExample
- (11/02) Changing CakePHP's Model useTable on the FlyTAGS:CakephpWeb ProgrammingMysqlDatabaseExampleTutorial
- (10/18) The Funniest Error Message Ever - Thank You EclipseTAGS:EclipseWeb ProgrammingErrorsHumorWindowsUsageSoftwarePhpCakephp
Subscribe to my feed
MainelyDesign.com Blog
A tale of caution: naming CakePHP "view" functions
Posted on 05/06/2009 at 05:13 pm by Kevin Wentworth
Viewed 3,274 times | 2 comments
Spoiler: functions that generate a view must be named using lower_case_with_underscores()
I just ran into a very interesting problem. I was testing out some of my plugins to make sure they were still working with Cake version 1.2.2.8120. They worked fine except for one function. I had a form that updates a shopping cart, changing the quantities of products placed in the cart. When I hit the submit button to change the quantities, I was getting redirected to my site root.
The first thing I did was put a simple echo command at the top of the function and a die(); right after that. This is my favorite-first-way of telling what's going on. I noticed that I could comment out the call to beforeFilter() and my echo command would work. I moved my die(); statement all the way up the beforeFilter chain and couldn't find any place that was redirecting before my die(); call. I knew it wasn't something I coded (first thought).
The next thing I did was create a dummy function with almost the same name. That worked! I copied my function and added some characters after the name to make a new function... redirected to the site root. What gives? Finally I had a thought- the one that worked wasn't small-capped, while the function that was redirecting was named in small-caps. I did a quick search and found this tidbit that reinforced my thinking:
"For functions that are used as views pages, use underscores to break words. Also use all lower caps." - source
What this means is that functions that are ultimately views MUST be named in lower_case_with_underscores! For whatever reason, my function named updateQuantities() worked since 1.2.6311 beta up until the release of 1.2.2.8120. I'm glad I found that post.
Happy coding! Cheers,
-Kevin Wentworth
Tags for A tale of caution: naming CakePHP "view" functions
Cakephp | Upgrade | Site Avenger | Web Programming
Comments for this Posting
Posted by ipod to mac transfer
on 16/2/11
Hello.
I think either your system is too slow or your having a heating problem
blu ray to dvd converter
Sorry, comments are closed for this posting.
Please Email Kevin if you have any questions. Thanks!

Posted by vafReepay
on 16/2/11
Amazing. Love this nice thought. Please also check out the last user products and services reviews, including the most requested bali villas review.
http://www.bali-villas.net