Posts Tagged ‘PHP’

Error on increasing unix timestamp date – date remains unchanged

November 22nd, 2010

Description:

This errors occurs when you keep your dates in unix timestamp format (represented as number of seconds from 1970/01/01). When we want to change a date to the next day, we can simply add as many second as there are in one day, which is 24 * 60 * 60 = 86400 seconds.

However when we try to do this for date: 2010-10-31, it is not working.

$time = strtotime('2010-10-31');
echo date("Y-m-d", $time) . "\n"; // 2010-10-31
$time += 86400;
echo date("Y-m-d", $time) . "\n"; // still 2010-10-31

Solution:

Stop adding seconds to dates represented by unix timestamp. Instead, use:

$time = strtotime('2010-10-31');
echo date("Y-m-d", $time) . "\n"; // 2010-10-31
$time = strtotime('+1 day', $time);
echo date("Y-m-d", $time) . "\n"; // 2010-11-01

Helpful debug function in Symfony

September 29th, 2010

When I debug my code I often use echo-like function together with  <pre></pre> to include white spaces in output. Hence, I create d function:

function d($var = 'test') {

    echo '<pre>';
    var_dump($var);
    echo '</pre>'
}

and  place it in the beggining  of ProjectConfiguration.php file. Then I can use it in any place of project – in command line tasks as well. [Earlier I placed it in frontend_dev.php file, but then I could not use it in tasks.]

[Zend_Amf + Symfony + Flex] Server with Logger

July 18th, 2010

After integrating Symfony with Flex through Zend_Amf, I had to debug it and I needed some logs on server side.
Below I present my LoggedAmfServer extending Zend_Amf_Server, which logs all methods called by Flex and its’ responses. You need to pass instance of sfLogger (ie. sfFileLogger) in the constructor.

» Read more: [Zend_Amf + Symfony + Flex] Server with Logger

Pagination + DataGrid + Service = PaginatedDataGrid v0.1 [english]

February 19th, 2010

Lately I was building an backend (admin-side) application in Flex. Most of the data was presented in data grids.

However, when working with services (PHP in my case) it is risky to load all data  to the DataGrid. It may lead to an application crash, ie. when we work on 1000′s of items.

Therefore I decided to create the component that handles pagination itself – it is similar to ExtJS’ data grid (however much simpler :) ).

» Read more: Pagination + DataGrid + Service = PaginatedDataGrid v0.1 [english]

Przesyłanie danych z Flexa do PHP za pomocą XMLa

October 25th, 2009

Nie samym Flexem i ActionScriptem programista żyje dlatego czasem musi zwrócić się do innych technologii. W komunikacji na linii Flex – PHP z pomocą przychodzą nam XML, JSON i AMFPHP. W tym wpisie zajmiemy się pierwszym z trójcy czyli XMLem.
» Read more: Przesyłanie danych z Flexa do PHP za pomocą XMLa

Flexmaniaks on Facebook