This is an interesting way to hide/show an AJAX loading gif image. Once an ajax request starts, the div containing the loading image shows up, once the request is done, the div is hidden again. I saw this on Stack Overflow and found it pretty:
-
$('#ajax_loading_div')
-
.hide() // hide it initially
-
.ajaxStart(function() {
-
$(this).show(); // show it when an AJAX request starts
-
})
-
.ajaxStop(function() {
-
$(this).hide(); // hide it when an AJAX request ends
-
});
Merging two or more PDF files with Zend_Pdf component of the Zend Framework is really simple. You just need to load the documents into Zend_Pdf instances and then iterate over their pages:
-
$pdf1 = Zend_Pdf::load('first.pdf');
-
$pdf2 = Zend_Pdf::load('second.pdf');
-
// we will merge our two PDF files into a new Zend_Pdf object
-
$pdfMerged = new Zend_Pdf();
-
-
// add all pages from the first PDF to our new document
-
foreach($pdf1->pages as $page){
-
$clonedPage = clone $page;
-
$pdfMerged->pages[] = $clonedPage;
-
}
-
// add all pages from the second PDF to our new document
-
foreach($pdf2->pages as $page){
-
$clonedPage = clone $page;
-
$pdfMerged->pages[] = $clonedPage;
-
}
-
unset($clonedPage);
-
-
// send the merged PDF document to browser
-
header('Content-type: application/pdf');
-
echo $pdfMerged->render();
A little bonus, if you need to load archived PDF documents (as I needed to recently) and merge them, you can use ZipArchive:
-
$zip = new ZipArchive;
-
$res = $zip->open('zipped_PDF_File.zip');
-
$pdf = Zend_Pdf::parse($zip->getFromIndex(0));
Hope somebody finds it useful
Many times PL/SQL won’t tell you what is wrong with your procedure and it will just print this cryptic message:
Warning: Procedure created with compilation errors.
If you don’t see any error in your code, use the following command:
SHOW ERRORS PROCEDURE <procedure_name>;
It will output something like which makes it much easier to debug the procedure:
SQL> SHOW ERRORS PROCEDURE add_book
Errors for PROCEDURE ADD_BOOK:
LINE/COL ERROR
-------- -----------------------------------------------------------------
28/3 PL/SQL: SQL Statement ignored
29/20 PL/SQL: ORA-00984: column not allowed here
You can use similar command not only with procedures:
SHOW ERRORS FUNCTION
SHOW ERRORS PACKAGE
SHOW ERRORS PACKAGE BODY
SHOW ERRORS TRIGGER
SHOW ERRORS VIEW
etc
UPDATE: I wrote a new more complete post explaining Zend Framework and IIS 7 configuration steb by step: Making Zend Framework run under IIS
If you are developing on a Windows PC you might want to use the native Windows web server IIS7 to run PHP. I do it that way. Since IIS neither accepts nor understands .htaccess files you will have to use a different approach to set up a Zend Framework project.
You will need to install the URL Rewrite module for IIS. Then just create a file called web.config in the public directory and put the following XML inside:
-
<?xml version="1.0" encoding="UTF-8"?>
-
<configuration>
-
<system.webServer>
-
<rewrite>
-
<rules>
-
<rule name="Imported Rule 1" stopProcessing="true">
-
<match url="^.*$" />
-
<conditions logicalGrouping="MatchAny">
-
<add input="{REQUEST_FILENAME}" matchType="IsFile" pattern="" ignoreCase="false" />
-
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" pattern="" ignoreCase="false" />
-
</conditions>
-
<action type="None" />
-
</rule>
-
<rule name="Imported Rule 2" stopProcessing="true">
-
<match url="^.*$" />
-
<action type="Rewrite" url="index.php" />
-
</rule>
-
</rules>
-
</rewrite>
-
</system.webServer>
-
</configuration>
Instead of manually creating the file you can also use the IIS Manager and import the rewrite rules through its interface.
If you are getting a warning like this when you’re trying to write something to a log file with Zend_Logger:
Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '1.0/no DST' instead in C:\inetpub\wwwroot\zend\library\Zend\Log.php on line 308
The solution is simple. I f you have access to your php.ini configuration file, just look for a line starting with:
date.timezone =
And put your timezone there, for example I used:
date.timezone = "Europe/Paris"
If you cannot edit the php.ini file, use this inside your PHP script:
-
date_default_timezone_set("Europe/Paris");
It’s good to be back online. This blog has been down for few weeks because I had some problems with my previous host. I lost some files so it took me a while to restore all data from the backup. Fortunatelly, I haven’t lost any written data (posts, pages etc). The only files missing were media files like images. I have uploaded back those pictures I had in the backup, I will try to replace the rest of them with new similar images soon.
I have already drawn new pictures for Adjacency list model and Nested set model posts. They don’t look quite as good as the previous ones. That’s because I have used GIMP to draw them this time and I have put only a little effort into it because I’m kinda busy right now
It is often useful to highlight an active navigation menu link so users are clear about where they are. It is usually done by adding a class (for instance: “active”) to a link which points to a current request URI. When using Zend_Navigation it is a bit more complicated. I am using a controller plugin to add the class to the active link during the routeShutdown event:
-
<?php
-
class My_Controller_Plugin_PrepareNavigation extends Zend_Controller_Plugin_Abstract
-
{
-
public function routeShutdown(Zend_Controller_Request_Abstract $request)
-
{
-
$viewRenderer = Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer');
-
$viewRenderer->initView();
-
$view = $viewRenderer->view;
-
-
$container = new Zend_Navigation(Zend_Registry::get('configuration')->navigation);
-
foreach ($container->getPages() as $page) {
-
$uri = $page->getHref();
-
if ($uri === $request->getRequestUri()) {
-
$page->setClass('active');
-
}
-
}
-
$view->navigation($container);
-
}
-
}
Here is a simple Zend Framework controller action helper that converts SQL result to XML. The SQL result should be fetched as an object or an array of objects:
-
<?php
-
class My_Controller_Action_Helper_SqlToXml extends Zend_Controller_Action_Helper_Abstract
-
{
-
public function direct($sqlResult, $rootElementName, $childElementName, $singleRow, $encoding = 'UTF-8')
-
{
-
// create XML documnt
-
$doc = new DomDocument('1.0', $encoding);
-
-
// insert a root element
-
$root = $doc->createElement($rootElementName);
-
$root = $doc->appendChild($root);
-
-
// if the SQL result set contains only a singler row
-
if (true === $singleRow) {
-
$xmlData .= $this->rowToXml($doc, $root, $sqlResult, $childElementName);
-
}
-
// if the SQL result set is an object array
-
else if (false === $singleRow) {
-
foreach ($sqlResult as $row) {
-
$xmlData .= $this->rowToXml($doc, $root, $row, $childElementName);
-
}
-
}
-
-
// return XML string
-
return $doc->saveXML();
-
}
-
-
private function rowToXml($doc, $root, $row, $childElementName)
-
{
-
// insert a child element
-
$occ = $doc->createElement($childElementName);
-
$occ = $root->appendChild($occ);
-
-
// iterate through each public object property and insert a shild element
-
foreach ($row as $property => $value) {
-
$child = $doc->createElement($property);
-
$child = $occ->appendChild($child);
-
-
$childValue = $doc->createTextNode($value);
-
$childValue = $child->appendChild($childValue);
-
}
-
}
-
}
Hope some of you will find it useful.
If you are using the imagettfbbox() PHP function and come across this error:
imagettfbbox() [function.imagettfbbox]: Could not find/open font
The solution is to use neither relative nor absolute path to the font but to use a path like this:
$font = './arial.ttf';