Finally, I completed the basic implementation of Ext.Direct server-side stack for CakePHP.
You can clone a working copy from http://github.com/eabay/directcakephp.
It is not that good but it works!
Combine is still my favorite javascript/css combine and compress script.
I posted a solution how to use it in a CakePHP application and here is a little helper to make it more useful:
<?php
//app/views/helpers/combine.php
class CombineHelper extends AppHelper
{
public $helpers = array('Html', 'Javascript');
private $_pattern = '../combine.php?type=:type&files=:files';
public function js($files)
{
echo $this->Javascript->link($this->_format($files));
}
public function css($files)
{
echo $this->Html->css($this->_format($files, 'css'));
}
private function _format($files = array(), $type = 'javascript')
{
return String::insert($this->_pattern, array('type' => $type, 'files' => implode(',', $files)));
}
}
Add it to controller’s helpers property:
<?php
class MyController extends AppController
{
public $helpers = array('Combine');
And call it by passing an array of file names in your view:
$combine->js(array( 'javascript1.js', 'javascript2.js', 'javascript3.js' )); $combine->css(array( 'stylesheet1.css', 'stylesheet2.css', 'stylesheet3.css' ));
Don’t forget to add file extensions!
If you want to add only one file, you don’t have to use combine helper. Directives added to .htaccess file let combine script to compress the file(See related post). Just use $javascript->link(‘filename’).
I need to make the first character of the string lowercase. I know ucfirst exists and I supposed that there is a “lcfirst” one as well.
When I started to type “lcfirst”, Zend Studio didn’t suggest me a function with this name and it was interesting. PHP documentation says that it is available but it throws an exception. What the hack goes wrong?
Here is the answer: It was too late and too hard to keep my eyes open
lcfirst function is available in newly released version of PHP, 5.3. I am still using 5.2.9. Here is a code snippet:
if (!function_exists('lcfirst')) {
function lcfirst($string) {
return substr_replace($string, strtolower(substr($string, 0, 1)), 0, 1);
}
}
It is unbelivable that I don’t ever need the function lcfirst before.