Archive for the ‘Zend Framework’ Category
Zend Framework – Howto Autoload a model inside your module!
I have lost about an hour today battling this. I have a normal ZF directory structure:
/Application
/modules
/default
/controllers
/moduls
/views
/admin
/controllers
/moduls
/views
But for some reasone file located in /admin/moduls was not loaded authomaticly.
The problem was in missing Bootstrap.php located in the module root directory. It looks like this extention from Zend_Application_Module_Bootstrap makes the trick.
So all you have to do is to add a class:
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap {}
And it will work!
jQGrid with Zend Framework Updated
Recently I had some time to update the fork I have of the jQGrid encapsulation for Zend Framework.
Among the things updated is:
* Support for jQGrid 4.1.
* Support for methods in options.
* 2 new decorators
* New special decorator, a multi select element on grid search.
* Support for advanced search
And many more…
You can locate the code at my GitHub:
If you dont use jQGrid it is an Ajax-enabled JavaScript control that provides solutions for representing and manipulating tabular data on the web.
How to use Zend-Framework-PDF-Table-Helper
Here is the example of how to user ZendFramework PDF-Table-Helper.
You can get the code from GitHub here:
One of the prerequisites is that you mast have the zf_autoloader on and configured since I am relaying on it to auto load files.
first you have to in instantiate the class:
$pdf = new SirShurf_Pdf_TableSet ();
You can instantiate it with a Zend_PDF object and without it, in which case it will be created for you, but if you are instantating with Zend_PDF you have to tell the system on what page you are working (Default is page 0).
Now what you need it to initialise a Table you are going to work with:
$objTableRow = $table->addRow ();
Each table can have his own number of columns and settings.
Each table can have a different number of rows a row can be added using this method:
And as with HTML a row has a number of cells (or columns):
$objTableRow->addCol ( $strCourseId, array (
'bold' => false, 'colspan' => 1, 'align' => 'center'
) );
$objTableRow->addCol ( Labadmin_Models_Static::convertHebrew ( $this->view->translate ( 'LBL_GRADE_FORM_COURSE_ID' ) ), array (
'bold' => false, 'colspan' => 1, 'align' => 'center', 'font' => 'arial.ttf', 'fontBold' => 'arialbd.ttf'
) );
The Cell can have each own definitions as the example here shows, and you can iterate over the data to create it.
And finally you can call render(); in order to render the changes to PDF, or build(‘fileName’) to save the finale PDF to a file.
$pdf->build ( $strGradeFileLocation . $intTimeStamp . ".grade.pdf" );
Library to create a tables in Zend Framework PDF
I had to create a PDF with a tables in a Zend Framework project I am making.
I have searched the web and have not found any library that can be used for this from the box, but I have found on GitHub a start of the library I was needed:
https://github.com/btm6084/Zend_PDF_Helper
Unfortunately the library was incomplete and not maintained, so I contacted the owner and he gave me the permission to take the code and do what I like with it.
So here is my version (working one) of the library that can create tables in PDF using Zend Framework PDF library.
Zend Framework PDF Table Helper
I will write a working example soon and post it here and on GitHub.
Grouping orWhere elements in Zend Framework Zend_Db_select
Practicly each time I am working with Zend_Db_Select (with Table or without it) I am searching for how easy to group orWhere elements.
After lot’s of searching and try and error’s I have come to this code:
if (false !== $this->_customSearchKeyword) {
$searchFields = array(‘p.photo_name’, ‘p.photo_desc’);
$keywordWhere = array();
if (!empty($searchFields)) {
foreach ($searchFields as $searchField) {
$searchField = $db0->quoteIdentifier($searchField);
$keywordWhere[] = ‘(‘ . $db0->quoteInto(“$searchField = ?”,
$this->_customSearchKeyword) . ‘)’;
}
$select->where( implode(‘ OR ‘, $keywordWhere) );
}
}
I hope that would be of some help to somebody 🙂 more then me I mean