Strange behavior with CakePHP conventions (2.3.1.) on different servers - cakephp

I've created an application on XAMPP packet on Windows 8. It works great.
Now, when I've uploaded it on a server (Linux) there are some problems.
Let's say, "ClientStatus".
Controller name: "ClientStatuses".
File name: "ClientStatusesController.php".
Plural: "ClientStatuses".
Singular: "ClientStatus".
But on the Linux server, it says that I must have "ClientstatusesController.php". Why is that? What I need to change in configuration so the conventions would be the same on XAMPP and Linux server? Is it something in .htaccess?
Any info will be great. Thank you. :)
It's CakePHP 2.3.1.

The conventions always was "plural" for controllers, therefore there is only one correct name:
ClientstatusesController
see http://book.cakephp.org/2.0/en/getting-started/cakephp-conventions.html
or try http://inflector.cakephp.org/clientstatus

It appears that "*nix" are case-sensitive with folder names. It has to be ClientstatusesController.php.
Well, here I want to tell you one more thing I've solved when I've uploaded a project on the server.
For transforming JavaScript array to JSON I've used JSON.stringify() and server's json_decode() always returned "null" when converting back.
I think it's because of 3 BOM characters. This solved the problem.
$table = json_decode(stripslashes($_REQUEST['table']), true);

Related

CakePHP CamelCase names after upload on server

My problem is quite strange. I'm developing CakePHP application. At the beginning I was doing all stuff on my local server with Windows... and works pretty good. But now I had to do upload to company's server. Now the app doesn't work due to CamelCase convention. My filenames looks like this: PostCategoriesController. On local Windows server there's no problem. But after upload when I type web address in my browser I see PostcategoriesController could not be found. I know Windows and Linux are case-sensitive in different ways. However in Cookbook we can read that developers should use CamelCase convention, so what I'm doing wrong?
As figured in the comments, you were using postcategories instead of something like post_categories in the URL, and so CakePHP cannot properly inflect this to PostCategories as there is no separator for the the words, and so you'll end up with Postcategories, which only works only Windows systems as its filesystems are case-insensitive (except for NFS on some server version if I remember correctly).
See also Cookbook > CakePHP conventions > URL Considerations for Controller Names
As can be seen in the docs it's also possible to use uppercase chars to indicate multiple words, ie postCastegories or PostCategories would work in a URL too.

Work with Database using Spock and Geb.

I hope someone have already faced an issue to verify that application shows correct data from database. I reviewd how groovy used SQL, but I have no idea where and how I should do that. I'm just starting to use gradle+Spock+Geb for testing application. I have a few files where I described a couple of pages from application, a couple of modules and a file with spock specification. Where and how I need to connect to Oracle DB, use SQL and compare result's data with application's ones?
P.S. I write everything in notepad++ and launch from command line writing 'gradlew firefoxTest'. Does exist any more comfortable way to work with gradle+spock+geb?
Thanks in advance.
Because there are no other answers, I wanted to provide a solution someone at my company thought of. This assumes you already have a project that uses some sort of JDBC. In our case it is JDBI.
The idea is to extend Classloader and then use that to directly access the data access object class via the JVM. That idea should work.
I have not tested it out because it doesn't completely fit our use-case. I'll admit that this does not completely apply to your use case, but technically you could just run the jar of an existing project, which can access the database.

CakePHP database file specification

I'm trying to find something about CakePHP configuration, and I'm not having any luck googling and looking around.
I want to make a CakePHP app use "database.local.php" instead of "database.php", but I can't find the line in the app/Config files where the database file is defined as "database.php".
Does anyone know where it is defined so I can change it?
Thanks for your help ahead of time!
If i get it right, you want to have a local database... for development purpose?
If you want to switch the database due to your server-name, you can try to use:
http://www.edwardawebb.com/web-development/cakephp/automatically-choose-database-connections-cakephp
Not quite an answer for you, but I wouldn't change it.
If you're using different files for different environments (dev, staging, production etc) you could use your naming convention, but have your deploy process rename the relevant file to whatever CakePHP's expecting. That is, have:
database.local.php
database.uat.php
database.live.php
or whatever, and just rename to database.php when deploying your code to one of those environments.

CakePHP from localhost to remote server - blank page

i am trying to figure this out for a long time now, but so far no luck, maybe somebody can help me.
I have a 2.2.2 cakephp installed on my computer (localhost) and everything works perfectly. But now i want that same project to be online on remote server. I upload everything, set mysql path but i get a blank page when trying to access the site.
If i upload a fresh cakephp it works, but my project doesnt. The debug is set to default, think that should be 2? I also deleted files in cache/tmp, but still no errors or anything, just blank page.
Any info would be helpful, thank you.
I hate when that happens :). Usually it does if there is an error somewhere and you can't see it because the errors are turned off, so you should call phpinfo() and see if display_errors is on. Changing the debug mode doesn't work every time since display_errors is set from php.ini.
Unfortunately, if this is the problem and you don't have access to edit the php.ini file, you might need to ask the hosting provider to change it and restart the php service.
You can also try this: error_reporting(E_ALL)
I uploaded changes to my cakephp website and discovered that all actions for a particular controller returned a blank page. I discovered what the error was and was able to reproduce it with another controller.
The problem was that in the first line of my controller file I had a space before the opening php tag.
One space cost me hours.
Just uploading all files won't cut it. Make sure you work through this checklist:
First and foremost, check the error log file located under app/tmp/logs/error.log, this usually holds some very good pointers as to what is wrong.
Make sure you have uploaded the app/Config/database.php file with the proper details. Local installs usually have user root without password. Online servers (obviously) do not!
To that extent, also make sure you actually have a database with your hosting provider (either your host sent you the info or you need to create it yourself using their control panel).
Make sure you also uploaded all .htaccess files (the one under the root directory and /app and /app/webroot), some FTP programs don't show this "hidden" file by default.
If all else fails, contact your hosting provider for further support as they usually have access to more verbose server logs that can also hold clues.
The real problem was only the coding I used in notepad++. All my files were encoded with UTF-8, but they should have been UTF-8 without BOM. After I changed it to UTF-8 withot BOM, everything started to work perfectly.

cakephp database table not found error after copied to local

i am using cakephp 1.3 ...it was working like charm in server ,i copied it to local and executed it....after that it shows a wierd error .It says "Missing Database Table
Error: Database table inboxes for model Inbox was not found.
Notice: If you want to customize this error message, create app/views/errors/missing_table.ctp
"
things i did after copying to local:
i used same DB with different name (yes..i changed in database.php too)
But there exist table "inbox"
I tried these ways:
1.removed inbox model and controller--nothing hapened
2.removed cache file from app/tmp/cache/models ---nothing happened
3.disabled caching from core.php
when i used another table with same name as in server its working
But nothing seems to be working after i used another database name as i am using that db name for another app ....can anyone help me on this...whats really happening with this.,its urgent..thanks in advance...
As Joseph mentioned in the comment, it may be a spelling mistake. But there could be one more reason:
On the web servers sometimes (mostly on shared hosting) you have the database name prefix. So it is possible that the real name of the database on your server is different from the database on your localhost. You can configure this in your app folder config/database.php
Best regards,
Tony.
After days of headache i sorted it out.
Even if i was using same DB with different name,it was using different encoding .I created new db with uttf_genereal_ci encoding and imported old one into it.Now its working like charm.Thanks guys for helping me on this

Resources