Recent Posts
- (09/10) Fixing Warning: the ECDSA host key for 'github.com' differs from the key for the IP addressTAGS:Web Server Admin
- (12/26) CakePHP 3 - Getting List of Column Definitions from a Table (like schema())TAGS:CakephpCake3
- (09/14) Change Order of Loaded Behaviors in CakePHP 3TAGS:Cake3CakephpWeb ProgrammingPhp
- (05/29) CakePHP 3 - Accept JSON Header Only Working When Debug FalseTAGS:Web ProgrammingCakephpCake3
- (05/23) Remove All Events from Google Calendar (Reset Calendar)TAGS:Web ProgrammingPhp
- (11/08) Google Tag Manager (GTM) Not Firing Default PageView EventTAGS:Web ProgrammingJavascriptGoogle Tag Manager
- (10/13) In PHP, how do you get __toString() Magic Method Result without calling echo?TAGS:CakephpCake3Cakephp 13PhpWeb Programming
- (11/14) Getting output from shell_exec() at all timesTAGS:Web ProgrammingWeb Server Admin
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 14,382 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