Cake PHP timezone wrong - cakephp

I got a strange problem with Cake. I live in Germany. When I add posts the time in the "created" database-field is 6 hours back. E.g. a post created 6pm shows up in the database as created 12am.
I use a managed server and I contacted the company which set the php.ini to the correct timezone Europe/Berlin. When I request the servers php.ini, it shows the timezone "Europe/Berlin" correctly. But when I run the code
$timezone = date_default_timezone_get();
echo "The current server timezone is: " . $timezone;
in CakePHP it shows
The current server timezone is: America/New_York
I already tried to set in the core.php:
date_default_timezone_set('Europe/Berlin');
But that has no effect at all.
Hopefully someone knows what to do.
EDIT 1:
After asking the support to run "locale -a", following was spit out:
# locale -a
C
de_DE
de_DE#euro
de_DE.iso88591
de_DE.iso885915#euro
de_DE.utf8
deutsch
en_US.utf8
german
POSIX
I assume that serverside everything is fine and the error is cake-wise.
But I donĀ“t have a clue what to do next? Maybe someone can help. Thanks in advance.
** EDIT 2: **
After looking around what it could be I found the error in the bootstrap.php of the Usermanagement-plugin, which set the timezone there to UTC. So everything works fine now. Thanks for your help anyway.

Edit:
If doing the answer below has no effect (per OP), it could be this issue:
Is is quite likely that the German locale is not installed on the
server your running the script on - do you have shell access to the
server? Then try
locale -a
to see which locales are installed. Also have a look here Is
it feasible to rely on setlocale, and rely on locales being installed?
TLDR:
You had the right idea - just put it in your Config/bootstrap.php. instead of your Config/core.php.
More Detail:
This is likely the same as this question. It's answer:
Put this in your Config/bootstrap.php:
date_default_timezone_set('UTC'); //or whatever your timezone is
It's just based on the server time and really has nothing to do with
CakePHP - so just change the default timezone with PHP, and you should
be good to go. 'created' and 'modified' will be based on the specified
timezone.
To reiterate, the "created" and "modified" fields ARE based on the server and really don't have much to do with CakePHP (which it sounds like you already assumed correctly).
A related item (just fyi to read up on) is CakeTime::convert(), but in this case, is not what you'd want.

Set in app_controller not in code.php

Problem solved. The problem was in a plugin which also had a config.php. There the Cake-config was overwritten. Now everything is fine.

Related

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

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);

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 cake back console -app not doing what I expect

So so so sorry if this is mentioned somewhere but I've tried searching high and low and can't find it anywhere. :(
Firstly, I'm a right newbie to cake. I purchased a book, beginning cakephp, apress, David Golding, which in here it makes use of the cake bake (really wish it didnt as it really isnt making sense!). I couldn't get this set up with cygwin but have it installed with the windows console.
In the book it tells me to enter:
cake bake -app ~/Sites/blog/app
and next the screen which it shows is the what would like to bake. Views, controllers etc etc.
However I have no idea what the Sites is as its the first time its mentioned this!!
So i'm trying:
cake bake -app ~C:/wamp/www/blog/app
and I'm getting the next screen as:
what is the path to the project you would like to bake?
Please please please help, where am I going wrong why aren't I seeing the what would like to bake. Views, controllers etc etc screen?? I'm really stuck now on this as the next chapter needs the bits the console creates.
I'm using wamp and the latest cakephp.
my cake folder is ~C:/wamp/www/blog/ (blog is the cake renamed).
my console environment setting is set up as: ;C:\wamp\bin\php\php5.3.10;C:\wamp\www\blog\app\Console
I really appreciate anyones/everyones help. I'm probably being a right spanner but can't get my head round understanding what I should enter.
Many Thanks in advance,
Alan
you should always navigate to your app dir and execute cake from there (relatively):
/path/to/test/>../lib/Cake/Console/cake
or - if you have a Config folder - probably also with (although I never used that one before)
/path/to/test/>Console/cake
that's how it works in 2.x. foolproof.
#see http://cakephp.lighthouseapp.com/projects/42648/tickets/2761
also see http://www.dereuromark.de/2011/10/31/freshly-baked-cake2-0-tips/

Missing Model in Returned Results from CakePHP 2.1 on new server

Our site worked fine on the old server, but we've recently moved it to a new server, and immediately, everything on the site looked messed up (ie can't find the data it's looking for in the views).
Upon further investigation, what was previously returned like this:
$articles[0]['Article']['title']
Is now returning:
$articles[0][0]['title']
At first, we were told it was that PDO wasn't installed (or was corrupted or something), but we rerebuilt Apache with PDO over and over and it's showing PDO on for both PHP and MySQL.
I've tried searching, but either I'm searching for the wrong thing, or there's no good info out there. Any ideas what could be causing this and/or how we can fix it?
Edit:
It also worked on this server prior to an update, which updated it to 5.3 (not sure what the prev version was)
Edit 2
Per suggestion, I changed the datasource to HpMysql This makes it work. It doesn't answer my question though, as I see it as a temporary fix - I'd still like to know what the issue is, and how to fix it without having to use this workaround.
Answer by Original Poster (me):
According to our server guy, "There are two ways to load PDO. The first is by using easyapache to install the PDO php extension. The second is by installing the PDO via PECL. It appears that the modules in question are different."
Apparently, this server had PECL on it instead of the normal easyapache PDO. When he removed that, and restarted/reset it with the easyapache PDO, everything worked great.
So - sounds like CakePHP requires the "normal" PDO.
Mystery solved.
If you have PECL instead, you can use this workaround:
Create a file "HpMysql.php" in your Datasource folder and add this code/class: https://github.com/lorenzo/HipHop/blob/master/Model/Datasource/Database/HpMysql.php
Change your database.php 'datasource' to 'HpMysql'
Different problem: (turned out to be the same answer):
$this->Auth->login() creates correct query that returns 1 row, but fails IF check (server specific issue)

how to change timezone setting in Lucid Work Enterprises

I have installed Lucid Work Enterprises and notice that its displaying time of UTC zone. But my system timezone is UTC+05:30. so there is always a difference in my database last_modified field value for delta query for indexing (as there is 5:30 Hrs difference in Lucid admin timezone and my database timezone).
I tried to change a setting in start.bat file from
"set MISC_OPTS2=-Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8"
to
"set MISC_OPTS2=-Duser.language=en -Duser.country=US -Duser.timezone=UTC+05:30 -Dfile.encoding=UTF-8"
But it doesn't make any difference.
I am unable to find a way to change timezone setting in Lucid admin area. Even there was no option to select timezone in installation wizard.
Please help me that how i can change this timezone setting for Lucid.
Thanks in advance
I had a similar issue using lucen/solr (without LWE). At solr ther is (also) no way to configure the timezone. Asking an Partner from "Lucid imagination" how to handle time-zones with lucene/solr, i get the answer: change timezone-settings at your J2EE servlet container options.
But as you said:
But it doesn't make any difference.
My workaround is realized by the application, which handles the "time-zone-difference" between lucene- and database timestamp. Not sure, which programming language you are using. PHP for example provides nice build-in functionality for handling dateTime objects and different timezones.

Resources