Links

Use of Zend Cache

Zend Cache will help you to prevent the time taken for heavy sql query.




Lines to be added in bootstrap file:

Zend_Loader::loadClass('Cache');
$backend= 'File';$frontend = 'Core';
$frontendOptions= array('lifetime' => 7200);
$backendOptions= array('cache_dir' => 'public/temp');
$cache = Zend_Cache::factory($frontend, $backend,$frontendOptions,$backendOptions);
Zend_Registry::Set('cache',$cache);




Lines to be added in init function of your controller file:


$this->cache = Zend_Registry::get('cache');


Lines to use the Zend Cache:

$data = $this->cache->load('TempVar');
if($data === FALSE)
{
$query=$this->db->query("SELECT * FROM table_name");
$data = $query->fetchAll();
$this->cache->save($data,'UserCompair');
}
$this->view->users = $data

Using JSON with PHP : an example

__________________________________________
index.php
______________________________________________

$array = array
(
["books"] => array(
["0"] => array
(
["book"] => array
(
["title"] => "JavaScript, the Definitive Guide"
["publisher"] => "O Reilly"
["author"] => "David Flanagan"
["cover"] => "/images/cover_defguide.jpg"
["blurb"] => "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
)

)

["1"] => array
(
["book"] => array
(
["title"] => "DOM Scripting"
["publisher"] => "Friends of Ed"
["author"] => "Jeremy Keith"
["cover"] => "/images/cover_domscripting.jpg"
["blurb"] => "Praesent et diam a ligula facilisis venenatis."
)

)

["2"] => array
(
["book"] => array
(
["title"] => "DHTML Utopia: Modern Web Design using JavaScript & DOM"
["publisher"] => "Sitepoint"
["author"] => "Stuart Langridge"
["cover"] => "/images/cover_utopia.jpg"
["blurb"] => "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."
)

)

)

)
die(json_encode($array));

______________________________________
index.js
______________________________________
window.onload = xmlHttp;

function xmlHttp()
{
if (window.XMLHttpRequest){xmlhttp = new XMLHttpRequest();}
else if (window.ActiveXObject){xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
else alert("XMLHttpRequest & ActiveXObject not active");
xmlhttp.open('POST', "index.php", true);
xmlhttp.onreadystatechange = function(){if(xmlhttp.readyState == 4 && xmlhttp.status == 200)setDataJSON(eval('(' + xmlhttp.responseText + ')'));}
xmlhttp.send(r);
}

function setDataJSON(req)
{
var data = eval('(' + req.responseText + ')');
for (var i=0;i {
var x = document.createElement('div');
x.className = 'book';
var y = document.createElement('h3');
y.appendChild(document.createTextNode(data.books[i].book.title));
x.appendChild(y);
var z = document.createElement('p');
z.className = 'moreInfo';
z.appendChild(document.createTextNode('By ' + data.books[i].book.author + ', ' + data.books[i].book.publisher));
x.appendChild(z);
var a = document.createElement('img');
a.src = data.books[i].book.cover;
x.appendChild(a);
var b = document.createElement('p');
b.appendChild(document.createTextNode(data.books[i].book.blurb));
x.appendChild(b);
document.getElementById('DivIdWhereChangeWillShown').appendChild(x);
}
}



Javascript function for getting page elements by their attribute

function getElementsByAttribute(TagName,Attribute,Value)
{
var oElm = document.body;var oCurrent;var oAttribute;var arrReturnElements = new Array();
var arrElements = (TagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(TagName);
var oAttributeValue = (typeof Value != "undefined")? new RegExp("(^|\\s)" + Value + "(\\s|$)") : null;
for(var i=0; i 0)if(typeof Value == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute)))arrReturnElements.push(oCurrent);}
return arrReturnElements;
}