Zend_Date::setOptions and format_type in Zend Framework 1.10.3

I recently upgraded from the old Zend Framework 1.9.5 to the latest – 1.10.3. Everything just looked to be working quite fine, except the date formatting. Although I had the same date formatting and options in the old version it seems to be not working.

I had the format_type set to PHP and even though I formatted the dates with a Zend Framework specific format: “d MMM yyyy”.

Zend_Date::setOptions(array('format_type' => 'php'));
// ...
$date = new Zend_Date($somedate);
echo $date->get('d MMM yyyy');

Now as it appears format_type php in 1.10.3 is giving completely different result, and the correct format is date() like format in PHP.

Zend_Date::setOptions(array('format_type' => 'php'));
// ...
$date = new Zend_Date($somedate);
echo $date->get('d M yy');
Posted in micro tutorial, PHP, zend framework | Tagged , , , , , , | Leave a comment

New Name for AJAX

Should it be called AJAJ since there’s more JSON instead of XML?!

Posted in web development | Tagged , | 2 Comments

Inline Scripts with Zend_View_Helper_InlineScript

Once I’ve posted about Zend Framework and script injections into the view of the app. However back than I didn’t mentioned the way the scripts can be injected on whatever place into the markup. This job’s done by Zend_View_Helper_InlineScript and that’s only an abstraction over the HeadScript.

However thus the PHP code goes quite clean and maintainable.

$scripts = $this->view->inlineScript();
$scripts->appendFile('/scripts/production.js');

This is quite interesting because in the case of multiple scripts you can chain them into this:

$scripts = $this->view->inlineScript();
$scripts->appendFile('/scripts/production.js')
            ->appendFile('/scripts/development.js')

But that’s not everything. Although it looks very pretty and clean, PHP gives you the correct syntax of something like this:

$scripts = $this->view->inlineScript();
$scripts
            ->appendFile('/scripts/production.js')
            ->appendFile('/scripts/development.js')

And that’s particularly good when it comes to fast switching between production and development scripts includes.

$scripts = $this->view->inlineScript();
$scripts
 //        ->appendFile('/scripts/production.js')
            ->appendFile('/scripts/development.js')

You’d ask why I’d to comment my script includes. Because as it appears to be fashionable the JavaScripts are concatenated and compressed. This gives you performance benefits on the client side when downloading and executing the script. So it’s usual to have one compressed/minified and several development scripts. That’s why this commenting strategy is very useful.

Posted in javascript, micro tutorial, PHP, zend framework | Tagged , , , , , , , , | Leave a comment

Accessing the layout() in Zend Framework

Actually there are two syntactic valid ways to access the layout() helper of the Zend_View.

First one is the more clean way:

$this->view->layout()

While the second calls the _helper member variable

$this->_helper->layout()
Posted in micro tutorial, PHP, zend framework | Tagged , , , , , | Leave a comment

MySQL Expressions in Zend Framework

If you’re a Zend Framework developer, you’d know the built-in Zend_Db_Table methods insert(), update(), etc.

However the general approach there is like is said:

$data = array();
$data['key'] = $value;
$model = new ModelName();
$model->insert($data);
 
// that's very basic example, but in general this is 
// the way it works.

What happens if one of the column have to be an MySQL expression!? In example you’ve a date field and you’d like to insert something like the MySQL’s method NOW().

The solution is simply call a Zend_Db_Expr.

$data = array();
$data['key'] = $value;
$data['date'] = new Zend_Db_Expr('NOW()');
$model = new ModelName();
$model->insert($data);
 
// now the date column will be NOWed :)
Posted in micro tutorial, PHP, zend framework | Tagged , , , , , , , , | Leave a comment