- (11/14) Getting output from shell_exec() at all timesTAGS:Web ProgrammingWeb Server Admin
- (06/12) View Layer - Getting count of Entities in View in Cakephp 3TAGS:CakephpCake3
- (05/23) Changing URL in beforeRedirect() in Component - Cakephp 3TAGS:CakephpCake3Web Programming
- (01/28) Foundation CSS Framework ResourcesTAGS:FoundationCss
- (01/27) Change View File from Controller in CakePHP 3TAGS:CakephpCake3UsageWeb Programming
- (01/13) Loading Model/Table Anywhere in Cake3TAGS:Cake3Cakephp
- (10/06) CURL PHP 5.5 Issue on Windows (Using Twilio SDK)
Subscribe to my feed
A tale of caution: naming CakePHP "view" functions
Posted on 05/06/2009 at 05:13 pm by Kevin Wentworth
Viewed 9,433 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 22.214.171.12420. 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 126.96.36.19920. I'm glad I found that post.
Happy coding! Cheers,