<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KAT CODE</title>
	<atom:link href="http://www.katcode.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.katcode.com</link>
	<description>Joomla, css, javascript, php etc... tutorials and reference</description>
	<lastBuildDate>Tue, 24 Apr 2012 19:16:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Custom Routes and Retrieving Keyless Parameters in Zend Framework 1.11</title>
		<link>http://www.katcode.com/custom-routes-and-retrieving-keyless-parameter/</link>
		<comments>http://www.katcode.com/custom-routes-and-retrieving-keyless-parameter/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 06:55:26 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=1153</guid>
		<description><![CDATA[You can specify what specific path fields should be mapped to. In this example will recognize a path without the parameter name and just the value. So you can have a path like /action/value/value instead of /action/key/value/key/value. Having a keyless path is a cleaner compact url. You will need to create a custom route in [...]]]></description>
			<content:encoded><![CDATA[<p>You can specify what specific path fields should be mapped to. In this example will recognize a path without the parameter name and just the value. So you can have a path like /action/value/value instead of /action/key/value/key/value. Having a keyless path is a cleaner compact url.</p>
<p>You will need to create a custom route in /appliation/Bootstrap.php. The following will route any path that looks like /portfolio/edit/xx to the portfolio edit action passing the record id in the xx position. You will be able to use this kind of path /portfolio/edit/1001 instead of /portfolio/edit/id/1001.</p>
<pre class="prettyprint">
<code>
 public function _initRoutes()
    {
        $frontController = Zend_Controller_Front::getInstance();

        $router = $frontController-&gt;getRouter();

        $router-&gt;addRoute(
           'portfolioedit',
           new Zend_Controller_Router_Route(
                '/portfolio/edit/:id',
                array('controller' =&gt; 'portfolio', 'action' =&gt; 'edit')
           )
        );
    }
</code>
</pre>
<p>You can now retrieve the url value by using getParam() looking for the &#8216;id&#8217; field In the portfolio controller editAction() method.</p>
<pre class="prettyprint">
<code>
$id = $this-&gt;getRequest()-&gt;getParam('id');
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/custom-routes-and-retrieving-keyless-parameter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple Module Setup in Zend Framework</title>
		<link>http://www.katcode.com/multiple-module-setup-in-zend-framework/</link>
		<comments>http://www.katcode.com/multiple-module-setup-in-zend-framework/#comments</comments>
		<pubDate>Thu, 19 Apr 2012 06:55:56 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=1158</guid>
		<description><![CDATA[This will describe how to setup multiple a module environment in Zend Framwork. Will be creating a project with default and gallery modules. First create the modules using the zf tool. Go to the root of your zend project and execute this on the command line: //This will create a modules directory and base directory [...]]]></description>
			<content:encoded><![CDATA[<p>This will describe how to setup multiple a module environment in Zend Framwork.</p>
<p>Will be creating a project with default and gallery modules.</p>
<p>First create the modules using the zf tool. Go to the root of your zend project and execute this on the command line:</p>
<pre class="prettyprint">
<code>

//This will create a modules directory and base directory structure
//for each module
zf create module Default
zf create module Gallery

//This will create controller index action and view
//script file for each module.
zf create controller Index 1 Default
zf create controller Index 1 Gallery
</code>
</pre>
<p>You must comment out this line in /application/configs/application.ini. ZF will look in each modules own controllers directory. We will define the module controller paths in the bootstrap.</p>
<pre class="prettyprint">
<code>
;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
</code>
</pre>
<p>Specify path to the modules folder in application.ini. This line should already exist after executing zf create module.</p>
<pre class="prettyprint">
<code>
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
</code>
</pre>
<p>Also set which module is the default module in application.ini. Will use &#8216;Default&#8217; as prefix for the class names in the Default module. </p>
<pre class="prettyprint">
<code>
resources.frontController.params.prefixDefaultModule = "1"
resources.frontController.defaultModule = "Default"
</code>
</pre>
<p>In /application/bootstrap.php need to initialize the front controller with the new module controller paths.</p>
<pre class="prettyprint">
<code>
 protected function _initFrontController ( )
    {
        $front = Zend_Controller_Front::getInstance();
        $front-&gt;setControllerDirectory( array (
        'default' =&gt; APPLICATION_PATH . '/modules/Default/controllers',
        'gallery' =&gt; APPLICATION_PATH . '/modules/Gallery/controllers'
        ));

        return $front;

    }
</code>
</pre>
<p>Each module can have its own Bootstrap.php. This is useful when creating routing specific to each module. Create this Bootstrap.php file in /modules/Gallery</p>
<pre class="prettyprint">
<code>
class Gallery_Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

    public function _initRoutes()
    {

    }

}
</code>
</pre>
<p>You can test your module by going to yourdomain.com/gallery. You will see the output below. The gallery module is displaying the index action view you just created.</p>
<pre class="prettyprint">
<code>

View script for controller Index and script/action name index

</code>
</pre>
<p>When you go to the root yourdomain.com/ the default module controller will be used. </p>
<p>So now you have two working modules that are encapsulated and portable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/multiple-module-setup-in-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Code Execution Timing Script</title>
		<link>http://www.katcode.com/php-code-execution-timing-script/</link>
		<comments>http://www.katcode.com/php-code-execution-timing-script/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 22:30:44 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=1097</guid>
		<description><![CDATA[Place call to getCurTime() at beginning where timing is to start. At end of script to time call execTime() passing the start time and this will calculate elapsed time of execution to six decimal places. function getCurTime() { $mtime = microtime(); $mtime = explode(' ', $mtime); $secs = $mtime[1] + $mtime[0]; return $secs; } function [...]]]></description>
			<content:encoded><![CDATA[<p>Place call to getCurTime() at beginning where timing is to start.  At end of script to time call execTime() passing the start time and this will calculate elapsed time of execution to six decimal places.</p>
<pre class="prettyprint">
<code>
function getCurTime() {
    $mtime = microtime();
    $mtime = explode(' ', $mtime);
    $secs = $mtime[1] + $mtime[0];
    return $secs;
}

function execTime($start) {
    $end = getCurTime();
    $total = $end - $start;
    return '&lt;Br&gt;'.sprintf('Executed in %.6f seconds.', $total);
}

//Usage

$start = getCurTime();

//the code to time.....

echo execTime($start);

</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/php-code-execution-timing-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Parse Out Url Querystring Into an Array</title>
		<link>http://www.katcode.com/parse-out-url-querystring-into-an-array/</link>
		<comments>http://www.katcode.com/parse-out-url-querystring-into-an-array/#comments</comments>
		<pubDate>Wed, 14 Mar 2012 17:26:58 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=1047</guid>
		<description><![CDATA[This function will extract the querystring portion of any url and parse out the key/value pairs into an array with querystring key as key of the array. /** * Parse out url query string into an associative array * * $qry can be any valid url or just the query string portion. * Will return [...]]]></description>
			<content:encoded><![CDATA[<p>This function will extract the querystring portion of any url and parse out the key/value pairs into an array with querystring key as key of the array.</p>
<pre class="prettyprint">
<code>

	/**
	* Parse out url query string into an associative array
	*
	* $qry can be any valid url or just the query string portion.
        * Will return false if no valid querystring found
	*
	* @param $qry String
	* @return Array
	*/
	function queryToArray($qry)
	{
		$result = array();
		//string must contain at least one = and cannot be in first position
		if(strpos($qry,'=')) {

		 if(strpos($qry,'?')!==false) {
		   $q = parse_url($qry);
		   $qry = $q['query'];
		  }
		}else {
			return false;
		}

		foreach (explode('&amp;', $qry) as $couple) {
			list ($key, $val) = explode('=', $couple);
			$result[$key] = $val;
		}

		return empty($result) ? false : $result;

	}

</code>
</pre>
<p>If you pass in something like &#8216;http://wwww.domain.com/index.html?param1=val1&#038;param2=val2&#8242;. This function will output this array.</p>
<pre class="prettyprint">
<code>
    Array
   (
      [param1] =&gt; val1
      [param2] =&gt; val2
   )
</code>
</pre>
<p>You can also just pass in the querystring &#8216;param1=val1&#038;param2=val2&#8242; and will output the same thing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/parse-out-url-querystring-into-an-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>In Search of the Original Joomla 1.5 API Doc</title>
		<link>http://www.katcode.com/in-search-of-the-original-joomla-1-5-api-doc/</link>
		<comments>http://www.katcode.com/in-search-of-the-original-joomla-1-5-api-doc/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 20:19:24 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[Joomla 1.5]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=1024</guid>
		<description><![CDATA[Somewhat recently the the Joomla team has decided to disable completely the original Joomla 1.5 API doc which I used regularly and loved. They had disabled the main api page a long time ago but I was able to access it through one of the api&#8217;s sub-pages. Now the entire orignal api pages are gone. [...]]]></description>
			<content:encoded><![CDATA[<p>Somewhat recently the the Joomla team has decided to disable completely the original Joomla 1.5 API doc which I used regularly and loved. They had disabled the main api page a long time ago but I was able to access it through one of the api&#8217;s sub-pages. Now the entire orignal api pages are gone. </p>
<p>Yes there is the <a href="http://docs.joomla.org/Framework/1.5">new</a> api which is in my opinion clunky and slower to dig into what you need. It is even missing documentation that the original already had.</p>
<p>My solution is to find it stored at the wayback machine at archive.org. <a href="http://web.archive.org/web/20100207193516/http://api.joomla.org/li_Joomla-Framework.html">Here</a> is the link to the archived api doc that works just like the original but is little slower. </p>
<p>UPDATE: Looks like they have the original 1.5 API doc up and running on api.joomla.org. Thank you to the !Joomla team from the two people still developing in 1.5!. I only noticed this because even the api doc stored at archive.org was not working. Some javascript file sitting on joomla server that it was using was disabled.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/in-search-of-the-original-joomla-1-5-api-doc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modifying the Default Login Path in Joomla 1.5</title>
		<link>http://www.katcode.com/modifying-the-default-login-path/</link>
		<comments>http://www.katcode.com/modifying-the-default-login-path/#comments</comments>
		<pubDate>Wed, 25 Jan 2012 18:21:46 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[Joomla 1.5]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=987</guid>
		<description><![CDATA[If you select a menu item that is registered or special access and you are not logged in, Joomla will redirect to a default login page. This is the default login redirect route: index.php?option=com_user&#38;view=login&#38;return= What if you want a different login path or go to a custom login page based on some condition. You can [...]]]></description>
			<content:encoded><![CDATA[<p>If you select a menu item that is registered or special access and you are not logged in, Joomla will redirect to a default login page.</p>
<p>This is the default login redirect route:</p>
<pre class="prettyprint">
<code>
index.php?option=com_user&amp;view=login&amp;return=
</code>
</pre>
<p>What if you want a different login path or go to a custom login page based on some condition. You can accomplish this by modifying the default redirect code in JSite::authorize(). JSite is located in /includes/application.php. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/modifying-the-default-login-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firefox 7 Better Memory Management</title>
		<link>http://www.katcode.com/firefox-7-better-memory-management/</link>
		<comments>http://www.katcode.com/firefox-7-better-memory-management/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 20:08:59 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=960</guid>
		<description><![CDATA[Seems that all these rapid releases Mozilla has made has finally paid off. There are reported substantially improved memory usage and no reports of massive memory leaks. Mozilla has been taking great efforts in reducing the memory usage problems. They have a project named MemShrink just to focus on this. Here is a good article [...]]]></description>
			<content:encoded><![CDATA[<p>Seems that all these rapid releases Mozilla has made has finally paid off. There are reported  substantially improved memory usage and no reports of massive memory leaks.<br />
Mozilla has been taking great efforts in reducing the memory usage problems. They have a project named <a href="https://wiki.mozilla.org/Performance/MemShrink">MemShrink</a> just to focus on this.</p>
<p><a href="http://www.zdnet.com/blog/networking/firefox-7-better-memory-management-meh-performance-review/1521">Here</a> is a good article about Firefox 7 memory and javascript performance.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/firefox-7-better-memory-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memoization In PHP: Caching Method Results</title>
		<link>http://www.katcode.com/memoization-in-php-caching-method-results/</link>
		<comments>http://www.katcode.com/memoization-in-php-caching-method-results/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 23:04:32 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=912</guid>
		<description><![CDATA[Memoization is an optimization pattern, which involves caching results that a function returns. Any subsequent calls to function to calculate same computation will instead retrieve from the result cache. This avoids wasting valuable computer resources by not repeating the same calculation. This first method caches single parameter method calls. class Util { function expCalc($param) { [...]]]></description>
			<content:encoded><![CDATA[<p>Memoization is an optimization pattern, which involves caching results that a function returns. Any subsequent calls to function to calculate same computation will instead retrieve from the result cache. This avoids wasting valuable computer resources by not repeating the same calculation. </p>
<p>This first method caches single parameter method calls.</p>
<pre class="prettyprint">
<code>
class Util {

	function expCalc($param) {

                static $cache;

		if(!$cache[$param]) {

			$result = 'expensive calculation';

                        $cache[$param] = $result;
		}

		return $cache[$param];

	}

}</code>
</pre>
<p>This method will add the result to cache as an array hash value for each different parameter value passed to it. The cache variable is static so it maintains its value for each method call. </p>
<p>You can call the method statically or as an instance method.</p>
<pre class="prettyprint">
<code>
$val = Util::expCalc(1);
</code>
</pre>
<p>This second method shows how to handle multiple parameters in the method call.</p>
<pre class="prettyprint">
<code>
class Util {

	function expCalc($param1,$param2,$param3) {
		static $cache;

                //turn all arguments into a single hash value
		$key = md5(serialize(func_get_args()));

		if(!$cache[$key]) {

			$result = 'expensive calculation';

			$cache[$key] = $result;
		}

		return $cache[$key];

	}

}
</code>
</pre>
<p>The only difference in this method and previous is the way the cache array key is generated. This will combine all the arguments into a single hash value. Arguments can be any combination of strings, integers, arrays and objects. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/memoization-in-php-caching-method-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Passing a Value from PHP to Javascript Variable</title>
		<link>http://www.katcode.com/passing-a-value-from-php-to-javascript-variable/</link>
		<comments>http://www.katcode.com/passing-a-value-from-php-to-javascript-variable/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 20:36:28 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=907</guid>
		<description><![CDATA[When inserting a value from PHP script into javascript code you should be careful to properly format the text so it will not break your javascript. These are two ways of properly formatting the text to be inserted into a javascript variable. You can first url encode the value in php then decode it in [...]]]></description>
			<content:encoded><![CDATA[<p>When inserting a value from PHP script into javascript code you should be careful to properly format the text so it will not break your javascript. These are two ways of properly formatting the text to be inserted into a javascript variable.</p>
<p>You can first url encode the value in php then decode it in javascript. Try something like this from your php script.</p>
<pre class="prettyprint">
<code>
&lt;script type="text/javascript"&gt;
    var list = decodeURIComponent("&lt;?php echo rawurlencode($mySelectList) ?&gt;");
&lt;/script&gt;
</code>
</pre>
<p>If you have PHP 5.2 + you can use json_encode to properly escape the text. It will also put in the outer quotes for the value for you. </p>
<pre class="prettyprint">
<code>
&lt;script type="text/javascript"&gt;
    var list = &lt;?php echo json_encode($mySelectList) ?&gt;;
&lt;/script&gt;
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/passing-a-value-from-php-to-javascript-variable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enhanced Browser Experience: Prerendering the page in Chrome</title>
		<link>http://www.katcode.com/877/</link>
		<comments>http://www.katcode.com/877/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 04:33:02 +0000</pubDate>
		<dc:creator>Andy Nagai</dc:creator>
				<category><![CDATA[Browser]]></category>
		<category><![CDATA[Google Chrome]]></category>

		<guid isPermaLink="false">http://www.katcode.com/?p=877</guid>
		<description><![CDATA[In the future release of Chrome you will be able to pre-render the page before it is displayed. Prerendering a page is when you tell the browser ahead of time what page the user is most likely to visit next and the browser will pre-load and pre-render the page in the background. This would be [...]]]></description>
			<content:encoded><![CDATA[<p>In the future release of Chrome you will be able to pre-render the page before it is displayed.</p>
<p>Prerendering a page is when you tell the browser ahead of time what page the user is most likely to visit next and the browser will pre-load and pre-render the page in the background. This would be useful in articles that consist of multiple pages where user is very likely to click to the second page of the article. The second page will just pop open instantly because its already completely rendered. </p>
<p>This is accomplished by adding a special link tag with rel=prerender and a url that tells the browser what page to prerender. Currently it is a experimental feature in Chrome 13. </p>
<p><a href="http://code.google.com/chrome/whitepapers/prerender.html">Here</a> is more information from Google labs. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.katcode.com/877/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

