Spiga

Minify css in ZendFramework

March 11, 09 by Gabi Solomon

After coming across Matthew Turland Minify Filter for Zend Framework i decided to implement the minify app to also minify the css and javascript external files.

But i only did the implementation for the stylesheets for now, and i wanted to share it :) .
Read the rest of this entry »

Zend Framework View partial without reseting variables

January 18, 09 by Gabi Solomon

Important

Ignore this solution, there is already a solution in ZF implemented in View as Jani Hartikainen pointed out in the comment below.
Its $this->render('...');

Zend Framework has a view helper called partial that you can use to render other views in your view file.
This is very useful for reusing the html code.

The problem i sometimes faced with that partial helper is that it resets all the variables and you need to specify them as an array parameter if you want them to be available in the partial view rendered.

The solution

To overcome this all you need to do is make a new view helper ... i called mine GSD_View_Helper_Render witch extends the Zend_View_Helper_Partial and overwrites the methods that clones the view and resets the variables.

PHP:
  1. class GSD_View_Helper_Render extends Zend_View_Helper_Partial {
  2.  
  3.     public function cloneView()
  4.     {
  5.         $view = clone $this->view;
  6.         // $view->clearVars(); ... this was the line that resets all the variables.
  7.         return $view;
  8.     }
  9. }

Thats it. Hope this is of help to you.
Cheers

Zend Framework View Helper for Smarty Cycle

December 09, 08 by Gabi Solomon

As i stated in a recent post i am now starting to learn Zend Framework. And with all new things that you learn, you try to find the old ways ( at least i do :D ).

So today i was trying to find a method of creating a zebra table. The old way i used to this back when i was using smarty is by using the cycle custom function. Basically it will just alternate through a set of values to create the effect.

PHP:
  1. {section name=rows loop=$data}
  2. <tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
  3.    <td>{$data[rows]}</td>
  4. </tr>
  5. {/section}

Then when i moved on and stop using smarty, i wrote a similar function for my template engine.

So now i am looking for a similar solution on Zend Framework. Luckily for me some bright fellows have already thought of me :D .
In the zend wiki there is a Zend_View_Helper_Cycle Component Proposal that does exacly what i was wishing for :D .

Heres an example of how you can use it:

PHP:
  1. <?php $cycle=$this->cycle(array("#F0F0F0","#FFFFFF"));?>
  2. <?php foreach ($this->books as $book):?>
  3.   <tr  style="background-color:<?=$cycle->next()?>">
  4.   <td><?=$this->escape($book['author']) ?></td>
  5. </tr>
  6. <?php endforeach;?>

The proposal has been approved for development in standard/incubator.
You can download it from here.

Cheers.