<?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>El Blog del Antonio</title>
	<atom:link href="http://www.ramirezcobos.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ramirezcobos.com</link>
	<description>Programming Web with PHP, CSS, Javascript and ∞</description>
	<lastBuildDate>Sat, 05 May 2012 06:45:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ENexmo Yii Extension Library</title>
		<link>http://www.ramirezcobos.com/2012/03/21/enexmo-yii-extension-library/</link>
		<comments>http://www.ramirezcobos.com/2012/03/21/enexmo-yii-extension-library/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 11:25:18 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Yii]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=1037</guid>
		<description><![CDATA[Introduction
ENexmo Library allows Yii programmers to use the Restful API offered by Mobile Messaging provider Nexmo.
ENexmo is a cloud-based SMS API that lets you send and receive high volume of messages at wholesale rates.
Requires
Nexmo API credentials
EHttpClient Extension
Yii Framework
Quick  [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="http://www.ramirezcobos.com/2012/03/21/enexmo-yii-extension-library/screen-shot-2012-03-21-at-12-22-41-pm/" rel="attachment wp-att-1038"><img src="http://www.ramirezcobos.com/wp-content/uploads/2012/03/Screen-Shot-2012-03-21-at-12.22.41-PM.png" alt="" title="Nexmo" width="300" height="243" class="alignright size-full wp-image-1038" /></a><a title="Nexmo" href="http://www.nexmo.com">ENexmo</a> Library allows Yii programmers to use the Restful API offered by Mobile Messaging provider Nexmo.</p>
<p><a title="Nexmo" href="http://www.nexmo.com">ENexmo</a> is a cloud-based SMS API that lets you send and receive high volume of messages at wholesale rates.</p>
<h2>Requires</h2>
<ul>
<li><a title="Nexmo Documentation" href="http://nexmo.com/documentation/index.html">Nexmo API credentials</a></li>
<li><a title="EHttpClient" href="http://www.yiiframework.com/extension/ehttpclient/">EHttpClient Extension</a></li>
<li>Yii Framework</li>
</ul>
<h2>Quick Start</h2>
<p>Once you have created your Nexmo account and include ENexmo library and EHttpClient on the extension folder is as easy as this:</p>
<p>&nbsp;</p>
<pre class="brush: php; title: ; notranslate">
/* import extensions before any call */
Yii::import('ext.httpclient.*');
Yii::import('ext.nexmo.*');
/* to send a message */
$nexmo_sms = new ENexmoSms('YOURAPIKEY','YOURAPISECRET');
$response = $nexmo_sms-&gt;sendTextMessage('RECIPIENTSNUMBER','SENDERID','Howdy testing! Please, search on http://www.google.com.');
/* responses are on JSON or XML. Defaults to JSON, but you can change that */
/* we use CHtml::encode for demo purposes only, to check for responses */
echo CHtml::encode($response);
/* to make requests for account */
$nexmo_account = new ENexmoAccount('key','secret');
$nexmo_account-&gt;format = ENexmoBase::FORMAT_JSON;
/* to search for a message */
echo CHtml::encode($nexmo_account-&gt;searchMessage('09AFDA98'));
//echo CHtml::encode($nexmo_account-&gt;searchMessagesByIds(array('09AFCC5B','09AFDA98')));
//echo CHtml::encode($nexmo_account-&gt;searchMessagesByDateAndRecipient('2012-03-20','34607040932'));
//echo CHtml::encode($nexmo_account-&gt;balance);
//echo CHtml::encode($nexmo_account-&gt;ownNumbers);
//echo CHtml::encode($nexmo_account-&gt;getSmsPricing('ES'));
</pre>
<p>Please check Nexmo API Documentation Nexmo API Documentation</p>
<a href="http://twitter.com/?status=RT%20%40%3A%20ENexmo%20Yii%20Extension%20Library%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2012%2F03%2F21%2Fenexmo-yii-extension-library%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2012/03/21/enexmo-yii-extension-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ei18n Translation Module</title>
		<link>http://www.ramirezcobos.com/2012/03/16/ei18n-translation-module/</link>
		<comments>http://www.ramirezcobos.com/2012/03/16/ei18n-translation-module/#comments</comments>
		<pubDate>Sat, 17 Mar 2012 00:15:12 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Yii]]></category>
		<category><![CDATA[Module]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=1023</guid>
		<description><![CDATA[Introduction
Ei18 is a translation module to allow Yii&#8217;ers to easily manage missing translations on application pages. It is heavily inspired by yii.translatedeveloped by Gustavo Salomé Silva gusnips.
The reason I developed a new one is because Gustavo&#8217;s approach wasn&#8217;t suitable for my needs, I  [...]]]></description>
			<content:encoded><![CDATA[<h2 id="hh0">Introduction</h2>
<p>Ei18 is a translation module to allow Yii&#8217;ers to easily manage missing translations on application pages. It is heavily inspired by <a href="https://github.com/gusnips/yii.translate">yii.translate</a>developed by Gustavo Salomé Silva <a href="http://www.yiiframework.com/user/6112/">gusnips</a>.</p>
<p>The reason I developed a new one is because Gustavo&#8217;s approach wasn&#8217;t suitable for my needs, I wanted the translation to be specific to the languages I was editing and not to edit them all at once. Also, the theme was not rendering right and I couldn&#8217;t make it work properly as my design was not developed with the one Yii comes by default.</p>
<p>I wanted to make it as a component only but then I realized that to be a module was the right way to go as I could automate language edition without making the user tweak far too many things.</p>
<p>The following is a snapshot of the editor:</p>
<p><a href="http://www.ramirezcobos.com/2012/03/16/ei18n-translation-module/ei18n-editor/" rel="attachment wp-att-1025"><img class="aligncenter size-full wp-image-1025" title="Ei18n-editor" src="http://www.ramirezcobos.com/wp-content/uploads/2012/03/Ei18n-editor.png" alt="" width="550" height="295" /></a></p>
<p>&nbsp;</p>
<h3 id="hh1">Features</h3>
<ul>
<li>Automatically creates the message translation tables on your database.</li>
<li>The module allows the edition of translations specified by categories. Its utility widget WTranslate handles that very smoothly.</li>
<li>All is <strong>AJAX</strong> based at the frontend. I thought that would be better to leave to developers the creation of a backend in order to edit translation on a regular basis.</li>
<li>Its Ei18 component has a couple of helper functions to also manage language setting automation. Check also its Set CAction class to be included on the controller that will handle language setting.</li>
</ul>
<h2 id="hh2">Requirements</h2>
<ul>
<li>jQuery v1.7 or higher (tested with jQuery v1.7)</li>
<li><a href="http://fancyapps.com/fancybox/">fancybox 2.0.5</a></li>
<li><a href="https://github.com/akzhan/jwysiwyg">jwysiwyg 0.97.2</a></li>
<li>jbar Jquery plugin -<strong>Modified version</strong></li>
<li>Yii 1.9</li>
<li>Translations handled by CDbMessageSource</li>
</ul>
<h2 id="hh3">Tested With</h2>
<ul>
<li>Chrome 17.0.963.56 on Macosx Lion</li>
<li>Safari Version 5.1.3 (7534.53.10) on Macosx Lion</li>
<li>Firefox 8.0.1 Macosx Lion</li>
<li>Firefox 9.0.1 Macosx Lion</li>
</ul>
<h2 id="hh4">Quick Start</h2>
<p>The configuration is a bit troublesome, but once you get it up and running editing your missing translations will be peanuts.</p>
<p>In order to make it run we need to:</p>
<ul>
<li>Configure Ei18n on your main.php configuration file</li>
<li>Render the widget on your base layout file</li>
</ul>
<h3 id="hh5">Configuring Ei18n</h3>
<p>On you main.php configuration file do the following:</p>
<div>
<div>
<pre class="brush: php; title: ; notranslate">
/* import the module */
   'import'=&gt;array(
   /* ... */
       'application.modules.translate.TranslateModule'
   /* ... */
/* setup your default language */
    'language'=&gt; 'en',
/* setup message translation method */
    'components'=&gt;array(
       'messages' =&gt; array(
           'class' =&gt; 'CDbMessageSource',
           'onMissingTranslation' =&gt; array('Ei18n', 'missingTranslation'),
           'sourceMessageTable' =&gt; 'tbl_source_message',
           'translatedMessageTable' =&gt; 'tbl_message'
           ),
/* setup global translate application component */
       'translate' =&gt; array(
           'class' =&gt; 'translate.components.Ei18n',
           'createTranslationTables' =&gt; true,
           'connectionID' =&gt; 'db',
           'languages' =&gt; array(
                    'en' =&gt; 'English',
                    'es' =&gt; 'Español',
                    'it' =&gt; 'Italiano'
                    )
            ),
        ),
/* setup the module */
       'modules' =&gt; array(
            'translate'
        ),
/* preload the global translate application component */
       'preload'=&gt; array(
            'translate'
        )
        /* ... */
</pre>
</div>
</div>
<h3 id="hh6">Displaying the editor</h3>
<p>Once the module and the translation component have been set. You just use any of the following helper functions:</p>
<div>
<div>
<pre class="brush: php; title: ; notranslate">
Yii::app()-&gt;translate-&gt;renderMissingTranslationsEditor();
    /* or only certain categories*/
/* Yii::app()-&gt;translate-&gt;renderTranslationsEditor(array('index','menu')); */
</pre>
</div>
</div>
<p>The first method and due to the view rendering nature of Yii, I highly recommend the display of those functions at the bottom of your <strong>main</strong> or <strong>base</strong> layout, as it will collect all missing ones throughout the rendering processes.</p>
<p>Remember the translations are automatically collected when Yii goes through all those<strong>Yii::t(&#8216;category&#8217;,'translation text&#8217;);</strong> statements throughout your code and fires the onMissingTranslation event.</p>
<h2 id="hh7">Yes, is on Github</h2>
<p>Anybody willing to help improving E1i8n is highly welcome. Check the <a href="https://github.com/tonydspaniard/Yii-Ei18n">github repository</a> on the resources section.</p>
<h2 id="hh8">Changelog</h2>
<ul>
<li>version 1.0.0 Initial version release</li>
</ul>
<h2 id="hh9">Resources</h2>
<ul>
<li><a href="https://github.com/tonydspaniard/Yii-Ei18n">Github</a></li>
<li><a href="http://www.yiiframework.com/extension/ei18n/">Project Home</a></li>
<li><a href="http://www.yiiframework.com/forum">Forum Post</a></li>
</ul>
<p><center><br />
<br />
</center></p>
<a href="http://twitter.com/?status=RT%20%40%3A%20Ei18n%20Translation%20Module%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2012%2F03%2F16%2Fei18n-translation-module%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2012/03/16/ei18n-translation-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EScriptBoost Extension for Yii</title>
		<link>http://www.ramirezcobos.com/2011/12/07/escriptboost-extension-for-yii/</link>
		<comments>http://www.ramirezcobos.com/2011/12/07/escriptboost-extension-for-yii/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 16:07:10 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Yii]]></category>
		<category><![CDATA[Extension]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=996</guid>
		<description><![CDATA[Introduction
Probably a lot of you would wonder why, having so many good extensions related to minifying/compressing/packing your javascript code and your css files at the Yii Extensions Repository, here comes this guy offering us another solution.
I did check out all the extension in our  [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="http://www.ramirezcobos.com/2010/10/28/how-to-use-jqueryslidemenu-with-yii%e2%80%99s-cmenu/yii/" rel="attachment wp-att-612"><img src="http://www.ramirezcobos.com/wp-content/uploads/2010/10/Yii.png" alt="Yii Framework" title="Yii Framework" width="160" height="160" class="alignright size-full wp-image-612" /></a>Probably a lot of you would wonder why, having so many good extensions related to minifying/compressing/packing your javascript code and your css files at the <a href="http://www.yiiframework.com/extensions/" title="Yii Extensions Repository" target="_blank">Yii Extensions Repository</a>, here comes this guy offering us another solution.</p>
<p>I did check out all the extension in our repository, just to name some of them:</p>
<ul>
<li><a href="http://www.yiiframework.com/extension/clientscriptpacker">clientscriptpacker</a></li>
<li><a href="http://www.yiiframework.com/extension/dynamicres/">dynamicres</a></li>
<li><a href="http://www.yiiframework.com/extension/minscript/">minscript</a></li>
</ul>
<p>All of them are great, but none were filling the requirements we had. I did not have any issue compressing all our files as our team, will use the YUI compressor jar file to create our compressed javascript versions and then use the wonderful mapping features of CClientScript. The issue was with the assets of external, or own developed, extensions and the javascript code that, even Yii own widgets, were writing to the POS_BEGIN, POS_END, POS_HEAD, POS_LOAD, POS_READY positions. Thats exactly what this library is doing: allowing Yii coders to minify those scripts.</p>
<div>I have created a GitHub repository for those willing to contribute on any of the extensions I created. Please, check the link at the bottom of this wiki.</p>
</div>
<h2>Library</h2>
<p>The library comes with three flavors:</p>
<ul>
<li>EScriptBoost Component</li>
<li>EClientScriptBoost Extension</li>
<li>AssetManagerBoost Extension</li>
</ul>
<h3>EScriptBoost Component</h3>
<p>This is a very easy to use component to compress your Javascript or CSS code at your will. The minifiers used are:</p>
<ul>
<li>For CSS- <a title="CssMin" href="http://code.google.com/p/cssmin/">CssMin</a> and <a title="CssMinify" href="http://code.google.com/p/minify/">CssMinify</a> (with CssCompressor and CssUriRewriter classes that you can also use independently)</li>
<li>For JS- <a title="JsMin" href="http://code.google.com/p/jsmin-php/">JsMin</a>, <a title="JsMinPlus" href="http://crisp.tweakblogs.net/blog/cat/716">JsMinPlus</a> and <a title="JavaScriptPacker" href="http://dean.edwards.name/packer/usage/">JavaScriptPacker</a></li>
</ul>
<p><strong><em>Usage</em></strong></p>
<div>
<div>
<pre class="brush: php; title: ; notranslate">
// this is a very simple example <img src='http://www.ramirezcobos.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
// we use cache as we do not want to
// compress/minify all the time our
// script
$js = Yii::app()-&gt;cache-&gt;get('scriptID');
if(!$js)
{
     $cacheDuration = 30;
     $js = &lt;&lt;&lt;EOD
     // my long and uncompressed code here
EOD;
     // $js = EScriptBoost::packJs($js);
     // $js = EScriptBoost::minifyJs($js, EScriptBoost::JS_MIN_PLUS);
     $js = EScriptBoost::minifyJs($js, EScriptBoost::JS_MIN);
     // see Cache guide for more options | dependencies
     Yii::app()-&gt;cache-&gt;set('scriptID', $cacheDuration);
}
Yii::app()-&gt;clientScript-&gt;registerScript('scriptID', $js);
</pre>
</div>
</div>
<p>That was troublesome right? No worries, if you don&#8217;t really care about using JS_MIN, or JS_MIN_PLUS, you can use its helper function <strong>registerScript</strong>, it will handle all of the above automatically:</p>
<div>
<div>
<pre class="brush: php; title: ; notranslate">
$js = &lt;&lt;&lt;EOD
    // my long and uncompressed code here
EOD;
EScriptBoost::registerScript('scriptID', $js);
</pre>
</div>
</div>
<h3>EClientScriptBoost Extension</h3>
<p><strong>EScriptBoost</strong> was good for the javascript code written by me but what about the ones written by Yii widgets?<strong>EClientScriptBoost</strong> was developed to solve that:</p>
<p><strong><em>Usage</em></strong></p>
<p>On your main.php config file:</p>
<div>
<div>
<pre class="brush: php; title: ; notranslate">
'import' =&gt; array(
// ... other configuration settings on main.php
// ... importing the folder where scriptboost is
    'application.extensions.scriptboost.*',
// ... more configuration settings
    ),
// ... other configuration settings on main.php
'components' =&gt; array(
     'clientScript' =&gt; array(
// ... assuming you have previously imported the folder
//     where EClientScriptBoost is
         'class'=&gt;'EClientScriptBoost',
         'cacheDuration'=&gt;30,
// ... more configuration settings
</pre>
</div>
</div>
<p>Done! now, every time you or other component on your application will be minified and cached as you specify on your cache settings. Easy right?</p>
<h3 id="hh4">EAssetManagerBoost Extension</h3>
<p>But there was one more challenge to solve. Some extensions, widgets, etc, do publish a whole bunch of files in our assets that are not minified. This is where <strong>EAssetManagerBoost</strong> comes handy.</p>
<p>This extension does only minify javascript/css files, and also makes sure that the, about to be compressed, file do not match any of its $minifiedExtensionFlags so minified/compressed files are not processed at all.</p>
<p><strong><em>Usage</em></strong></p>
<p>Make sure you have deleted your previous assets folder contents.</p>
<div>
<div>
<pre class="brush: php; title: ; notranslate">
'import' =&gt; array(
// ... other configuration settings on main.php
// ... importing the folder where scriptboost is
    'application.extensions.scriptboost.*',
// ... more configuration settings
    ),
// ... other configuration settings on main.php
'components' =&gt; array(
    'assetManager' =&gt; array(
// ... assuming you have previously imported the folder
      'class' =&gt; 'EAssetManagerBoost',
      'minifiedExtensionFlags'=&gt;array('min.js','minified.js','packed.js')
        ),
// ... more configuration settings
</pre>
</div>
</div>
<p><strong><em>Important Note</em></strong> There is a small drawback to use EAssetManagerBoost and is that, the first time your application is requested, it will take a bit of time as it will go throughout all your asset files to be published and minify them.</p>
<h2>Resources</h2>
<ul>
<li><a href="https://github.com/tonydspaniard/Yii-extensions">GitHub repository</a></li>
<li><a href="http://www.ramirezcobos.com/">Project page</a></li>
<li><a href="http://code.google.com/p/minify/">Minify Google Code Project</a></li>
<li><a title="JsMinPlus" href="http://crisp.tweakblogs.net/blog/cat/716">JsMinPlus page</a></li>
<li><a title="CssMin" href="http://code.google.com/p/cssmin/">CssMin</a></li>
<li><a href="http://www.yiiframework.com/forum/index.php?/topic/26550-extension-escriptboost/page__pid__127736#entry127736">Forum Post</a></li>
</ul>
<p><center><br />
<br />
</center></p>
<a href="http://twitter.com/?status=RT%20%40%3A%20EScriptBoost%20Extension%20for%20Yii%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2011%2F12%2F07%2Fescriptboost-extension-for-yii%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2011/12/07/escriptboost-extension-for-yii/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using events with CAction classes</title>
		<link>http://www.ramirezcobos.com/2011/10/13/using-events-with-caction-classes/</link>
		<comments>http://www.ramirezcobos.com/2011/10/13/using-events-with-caction-classes/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 13:26:35 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Yii]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=982</guid>
		<description><![CDATA[
Introduction
There are some good guides out there explaining how to work with events and the ways to attach them to your components, but none (that I know) explain the following way to configure your events with CAction classes on your controllers.
As you know, events are used by:
Declaring an  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ramirezcobos.com/2010/10/28/how-to-use-jqueryslidemenu-with-yii%e2%80%99s-cmenu/yii/" rel="attachment wp-att-612"><img class="alignright size-full wp-image-612" title="Yii Framework" src="http://www.ramirezcobos.com/wp-content/uploads/2010/10/Yii.png" alt="Yii Framework" width="160" height="160" /></a></p>
<h2>Introduction</h2>
<p>There are some good guides out there explaining how to work with events and the ways to attach them to your components, but none (that I know) explain the following way to configure your events with CAction classes on your controllers.</p>
<p>As you know, events are used by:</p>
<ul>
<li>Declaring an event in your component adding its method (ie. function onClick($event))</li>
<li>Attach it to event handlers (ie. $object-&gt;onClick=array($handlerObject,&#8217;staticmethod&#8217;);)</li>
<li>Raising it from your component to call all subscribed handlers (ie. $this-&gt;raiseEvent(&#8216;onClick&#8217;,$event)). Remember, that for a handler, you can write an object with static methods, an object with a method, create a function (create_function) and even attach a function directly (since PHP 5.3)</li>
</ul>
<h3>Tip</h3>
<p>If we look at the magic method __set of CComponent, we will see that event handlers are actually set like properties.<br />
Having that into account, the following is my quick tip to set your event handlers when working with CAction classes, which I think is far much better to organize your code in your controllers.</p>
<h4>The CAction class</h4>
<p>Lets write a simple CAction class for the example and save it as EMyAction.php:</p>
<pre class="brush: php; title: ; notranslate">
class EMyAction extends CAction{
	public function onTest($event){
		$this-&gt;raiseEvent('onTest', $event);
	}
	public function run() {
		$event = new CEvent($this);
		$this-&gt;onTest($event);
	}
}
</pre>
<h4>The Controller</h4>
<p>Now in our controller, for the sake of the example, lets write a method handler and configure the action (assumed to be on actions folder under, which is in controllers folder).</p>
<pre class="brush: php; title: ; notranslate">
// our event handler method, that, for simplicity,
// we set it in our controller
public function eventHandlerMethod($event)
{
	echo 'TESTING Handler';
}
// declaring actions and its event handlers
public function actions()
{
	return array(
		// test is the action name &lt;controller/action&gt;
		'test'=&gt;array(
			'class'=&gt;'actions.EMyAction',
			'onTest'=&gt;array($this,'eventHandlerMethod')
		)
    );
}
</pre>
<p>And that&#8217;s it, call the controller&#8217;s action as you would with any other in your preferred browser to test the results.</p>
<a href="http://twitter.com/?status=RT%20%40%3A%20Using%20events%20with%20CAction%20classes%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2011%2F10%2F13%2Fusing-events-with-caction-classes%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2011/10/13/using-events-with-caction-classes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Yii 1.1 Application Development Cookbook -by Alexander Makarov</title>
		<link>http://www.ramirezcobos.com/2011/09/26/yii-1-1-application-development-cookbook-by-alexander-makarov/</link>
		<comments>http://www.ramirezcobos.com/2011/09/26/yii-1-1-application-development-cookbook-by-alexander-makarov/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 13:08:05 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Yii]]></category>
		<category><![CDATA[Book]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=971</guid>
		<description><![CDATA[As most of you know, I am a heavy user of the Yii&#8217;s forum. Lots of times, people keep asking what is the best way to learn Yii, what should be the steps? Where are good resources to look for their answers&#8230; I once wrote an article: Yii Learning Guide, that should be now updated with a new great  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ramirezcobos.com/?attachment_id=954" rel="attachment wp-att-954"><img src="http://www.ramirezcobos.com/wp-content/uploads/2011/09/yii-cookbook-300x239.png" style="border:2px #eee solid" alt="" title="yii-cookbook" width="300" height="239" class="alignright size-medium wp-image-954" /></a>As most of you know, I am a heavy user of the <a href="http://www.yiiframework.com/forum" title="Yii's Forum">Yii&#8217;s forum</a>. Lots of times, people keep asking what is the best way to learn Yii, what should be the steps? Where are good resources to look for their answers&#8230; I once wrote an article: <a href="http://www.ramirezcobos.com/2010/12/10/yii-learning-guide/" title="Yii Learning Guide">Yii Learning Guide</a>, that should be now updated with a new great resource, the new book written by Alexander Makarov (<a href="http://www.yiiframework.com/user/415/" title="samdark">samdark</a>), Yii 1.1 Application Development Cookbook. </p>
<p>I had the pleasure to be one of the reviewers of the book, and I must admit that I felt more like a student than a reviewer <img src='http://www.ramirezcobos.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . The book is an excellent guide to solve, through practical examples, some of the challenges a Yii programmer would face during its Yii application development:</p>
<p>- How events work<br />
- Using Exceptions<br />
- Components, Widgets, Collections<br />
- Deep on Router, Controllers and Views<br />
- AJAX and JQuery with Yii<br />
- Forms, ActiveRecord, Models and Database<br />
- Zii Components<br />
- Extensions<br />
- Error Handling, debugging and Logging<br />
- Security and performance tuning<br />
- Using external libraries<br />
- Deployment</p>
<p>In addition, the book is not only a good practical reference to the points above, but also directs to external references on the web for further reading. It is a perfect companion for our online Yii site, class reference, wiki, and forum&#8230;  I have mine already, when are you going to get yours? </p>
<p><center></p>
<div class="wdgt_tl" style="height:68px;width:287px">
<div class="asin_img"><a style="float:left;border-bottom: none; text-decoration:none;" target="_blank"  href="http://www.amazon.com/Yii-1-1-Application-Development-Cookbook/dp/1849515484/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=yiian-20"><img src="http://ecx.images-amazon.com/images/I/51J8DQQZdlL._SL75_.jpg" width="40" height="49" style="border: none;margin:0;border-bottom: none; text-decoration:none;"></a></div>
<div style="color: #000000 !important;;" class="asin_h1"><a target="_blank" style="border-bottom: none; text-decoration:none;color: #000000 !important;text-decoration :underline;" href="http://www.amazon.com/Yii-1-1-Application-Development-Cookbook/dp/1849515484/ref=as_li_tf_mfw?&amp;linkCode=wey&amp;tag=yiian-20">&nbsp;Yii 1.1 Application Development Cookbook</a></div>
</div>
<p></center></p>
<p><center><br />
<br />
</center></p>
<a href="http://twitter.com/?status=RT%20%40%3A%20Yii%201.1%20Application%20Development%20Cookbook%20-by%20Alexander%20Makarov%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2011%2F09%2F26%2Fyii-1-1-application-development-cookbook-by-alexander-makarov%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2011/09/26/yii-1-1-application-development-cookbook-by-alexander-makarov/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Yiianswers, a new site for yii lovers</title>
		<link>http://www.ramirezcobos.com/2011/09/13/yiianswers-a-new-site-for-yii-lovers/</link>
		<comments>http://www.ramirezcobos.com/2011/09/13/yiianswers-a-new-site-for-yii-lovers/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 20:56:55 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[On The Web]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Yii]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=938</guid>
		<description><![CDATA[ I would like to introduce a new site that a good friend of mine and work colleague Maurizio Domba (mdomba) and I have setup in order to solve an issue that actually occurs at the Yii forum and help the Yii community with what we think could be a great tool for their learning or development  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ramirezcobos.com/2011/09/13/yiianswers-a-new-site-for-yii-lovers/yiia-twitter-logo/" rel="attachment wp-att-939"><img src="http://www.ramirezcobos.com/wp-content/uploads/2011/09/yiia-twitter-logo.png" alt="" title="yiia-twitter-logo" width="173" height="157" class="alignright size-full wp-image-939" /></a> I would like to introduce a new site that a good friend of mine and work colleague Maurizio Domba (<a href="http://www.yiiframework.com/forum/index.php?/user/2650-mdomba/">mdomba</a>) and I have setup in order to solve an issue that actually occurs at the <a href="http://www.yiiframework.com/forum/" title="Yii Forum">Yii forum</a> and help the Yii community with what we think could be a great tool for their learning or development processes: <a href="http://yiianswers.com">Yiianswers.com</a></p>
<p>Don&#8217;t get us wrong, the forum is amazing, highly addictive (you can check our profiles -<a href="http://www.yiiframework.com/forum/index.php?/user/2650-mdomba/" title="mdomba">mdomba</a> an <a href="http://www.yiiframework.com/forum/index.php?/user/7106-antonio-ramirez/" title="tonydspaniard">tonydspaniard</a> to find out how we love that forum) and very useful thanks to the support of a lot of good programmers that freely give aways their time to help others get the right answers, in order to push <a href="http://www.yiiframework.com">Yii</a> to the level where it supposed to be in terms of PHP community acceptance. </p>
<p>Nevertheless, one of the things that we face as the forum grows is that the same questions are repeated again and again, and we believe that this is not because users do not know how to search for a solution but for the structure and functionality of a forum itself. We always thought that could be great to have a site to keep questions and its solutions in a categorized tree where people could easily browse, search, and/or find what they are looking for, and this is why <a href="http://yiianswers.com">Yiianswers.com</a> is here.</p>
<p><a href="http://yiianswers.com">Yiianswers.com</a> is an instant Questions and Answers site, so popular nowadays. We really hope that will help you out and will easy the task of finding the right answers to your <a href="http://www.yiiframework.com">Yii</a> questions.</p>
<p><center><br />
<br />
</center></p>
<a href="http://twitter.com/?status=RT%20%40%3A%20Yiianswers%2C%20a%20new%20site%20for%20yii%20lovers%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2011%2F09%2F13%2Fyiianswers-a-new-site-for-yii-lovers%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2011/09/13/yiianswers-a-new-site-for-yii-lovers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avoiding duplicate script download when using CActiveForm on Ajax calls</title>
		<link>http://www.ramirezcobos.com/2011/09/11/avoiding-duplicate-script-download-when-using-cactiveform-on-ajax-calls/</link>
		<comments>http://www.ramirezcobos.com/2011/09/11/avoiding-duplicate-script-download-when-using-cactiveform-on-ajax-calls/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 08:23:49 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Yii]]></category>
		<category><![CDATA[CActiveForm]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=895</guid>
		<description><![CDATA[
Introduction
Sometimes the active form we wish to use to edit/add a new element on our database is too small and we believe that is much better to use an AJAX&#8217;ed dialog/slide form rather than reloading the page to just display one or two fields.
The only thing required is simple, we just need to  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ramirezcobos.com/2010/10/28/how-to-use-jqueryslidemenu-with-yii%e2%80%99s-cmenu/yii/" rel="attachment wp-att-612"><img src="http://www.ramirezcobos.com/wp-content/uploads/2010/10/Yii.png" alt="Yii Framework" title="Yii Framework" width="160" height="160" class="alignright size-full wp-image-612" /></a><br />
<h3>Introduction</h3>
<p>Sometimes the active form we wish to use to edit/add a new element on our database is too small and we believe that is much better to use an AJAX&#8217;ed dialog/slide form rather than reloading the page to just display one or two fields.</p>
<p>The only thing required is simple, we just need to create a view that will be partially rendered by a call to a controller (using renderPartial) and make sure that we process output -setting to true the parameter on the function. Everything will work as expected but&#8230;</p>
<h3>The issue</h3>
<p>If we open firebug (firefox), or developer tools (chrome), or whatever the tool you use in order to see the XmlHttpRequest object calls and resources downloaded, you will see that every time we do call the controller to display the active form, different Yii &#8220;core JS&#8221; files keeps being downloaded to the client. The JS files downloaded depends on your code but there are at least jquery.js, jquery-ui.js and jquery.yiiactiveform.js.</p>
<h3>The solution</h3>
<p>The solution is a bit tricky but simple. We need to pre-render the jquery.yiiactiveform.js on the view where we are going to place the AJAX functionality (the button that opens the modal dialog or slides/shows a layer with AJAX&#8217;ed form contents). For example, on index.php view file:</p>
<pre class="brush: php; title: ; notranslate">
cs()-&gt;registerCoreScript('yiiactiveform');
</pre>
<p>Now, I assume that you have created your function to display the AJAX&#8217;ed active form and its contents are returned by a call to a controller&#8217;s action that will partially render a view. This is what we have to do in our action:</p>
<pre class="brush: php; title: ; notranslate">
// Just before rendering the view that
// has our activeform
Yii::app()-&gt;clientScript-&gt;corePackages = array();
</pre>
<p>It is very important that we set corePackages to array() instead of null, as setting it to null will make CClientScript to reload the packages.php file (located in framework/web/js/) and we won&#8217;t stop the duplication of the script.</p>
<p>And that&#8217;s it, everything is working as it should.</p>
<p><center><br />
<br />
</center></p>
<a href="http://twitter.com/?status=RT%20%40%3A%20Avoiding%20duplicate%20script%20download%20when%20using%20CActiveForm%20on%20Ajax%20calls%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2011%2F09%2F11%2Favoiding-duplicate-script-download-when-using-cactiveform-on-ajax-calls%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2011/09/11/avoiding-duplicate-script-download-when-using-cactiveform-on-ajax-calls/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Offertutti</title>
		<link>http://www.ramirezcobos.com/2011/07/28/offertutti/</link>
		<comments>http://www.ramirezcobos.com/2011/07/28/offertutti/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 11:56:37 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Portfolio]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=886</guid>
		<description><![CDATA[Coupon aggregator site I worked for. Duties I had for the company:
Consulting
CSS redesign
XML feeds development -Automation with PHP
RSS development and automatic marketing integration with Twitter and Facebook
&#160;
Even though was not a Yii-job, I am more than happy to promote www.offertutti.com  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ramirezcobos.com/2011/07/28/offertutti/screen-shot-2011-07-28-at-1-40-13-pm/" rel="attachment wp-att-887"><img class="alignright size-medium wp-image-887" title="Offertutti" src="http://www.ramirezcobos.com/wp-content/uploads/2011/07/Screen-Shot-2011-07-28-at-1.40.13-PM-300x223.png" alt="" width="300" height="223" /></a>Coupon aggregator site I worked for. Duties I had for the company:</p>
<ul>
<li>Consulting</li>
<li>CSS redesign</li>
<li>XML feeds development -Automation with PHP</li>
<li>RSS development and automatic marketing integration with Twitter and Facebook</li>
</ul>
<p>&nbsp;</p>
<p>Even though was not a Yii-job, I am more than happy to promote <a title="Offertutti" href="http://www.offertutti.com">www.offertutti.com</a> here as one of the most pleasant jobs I have ever had in my, already long -gosh how time pass, coding career.</p>
<p>The job was quite challenging, as any site developed by companies from certain countries, but managed to fulfill most of their expectations. Even though I am currently in the middle of a dream project, it continues to be a pleasure to help them out every now and then.</p>
<p>New design is coming&#8230;</p>
<a href="http://twitter.com/?status=RT%20%40%3A%20Offertutti%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2011%2F07%2F28%2Foffertutti%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2011/07/28/offertutti/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom Autocomplete Display and Value Submission</title>
		<link>http://www.ramirezcobos.com/2011/07/14/custom-autocomplete-display-and-value-submission/</link>
		<comments>http://www.ramirezcobos.com/2011/07/14/custom-autocomplete-display-and-value-submission/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 22:03:23 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Yii]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=879</guid>
		<description><![CDATA[
Introduction
How many of us has wondered how to create an autocomplete that will display the names of a related models but do require the id of that selected name to be submitted for model creation/update?
I was looking around wiki and found that was no approach as the one I did so I guessed this  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ramirezcobos.com/2010/10/28/how-to-use-jqueryslidemenu-with-yii%e2%80%99s-cmenu/yii/" rel="attachment wp-att-612"><img src="http://www.ramirezcobos.com/wp-content/uploads/2010/10/Yii.png" alt="Yii Framework" title="Yii Framework" width="160" height="160" class="alignright size-full wp-image-612" /></a><br />
<h2>Introduction</h2>
<p>How many of us has wondered how to create an autocomplete that will display the names of a related models but do require the id of that selected name to be submitted for model creation/update?</p>
<p>I was looking around wiki and found that was no approach as the one I did so I guessed this is worth to write.</p>
<h2>Requirements</h2>
<p>For our example, I want to be able to:</p>
<ul>
<li>Have an autocomplete field in our form</li>
<li>Once user selects an item in the dropdown list and fill a hidden box with the id of the selected item for submission</li>
</ul>
<h2>Making the right choice</h2>
<p>To setup the autocomplete was a very straight forward operation, but I couldn&#8217;t figure out how to get values from a custom JSON response and then fill the correspondent hidden fields.</p>
<p><a title="CAutoComplete" href="http://www.yiiframework.com/doc/api/1.1/CAutoComplete" target="_blank">CAutoComplete</a> does has a way to do it, but I wanted to use <a title="CJuiAutoComplete" href="http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete" target="_blank">CJuiAutoComplete</a> to get all the cool features of its JQuery Ui and by looking at his code there was no method chain, something that is required to work with custom JSON responses as we need to override some methods.</p>
<h2>My Solution</h2>
<p>After doing some research I decided to:</p>
<ol>
<li>extend from <a title="CJuiAutocomplete" href="http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete" target="_blank">CJuiAutoComplete</a></li>
<li>include the required property for method chain and modify its &#8216;run&#8217; function</li>
<li>then initialize the newly created property with the javascript functions that handle my custom JSON</li>
</ol>
<h3>Extending from CJuiAutoComplete and make required modifications</h3>
<p>Very simple, we are going to add a methodChain property and modify the run function to include it (zii is not a major concern to Yii, but main developers should think about this minor change).</p>
<pre class="brush: php; title: ; notranslate">
class myAutoComplete extends CJuiAutoComplete
{
    /**
     * @var string the chain of method calls that would be appended at the end of the autocomplete constructor.
     * For example, &quot;.result(function(...){})&quot; would cause the specified js function to execute
     * when the user selects an option.
     */
    public $methodChain;
    /**
     * Run this widget.
     * This method registers necessary javascript and renders the needed HTML code.
     */
    public function run()
    {
        list($name,$id)=$this-&gt;resolveNameID();
        if(isset($this-&gt;htmlOptions['id']))
            $id=$this-&gt;htmlOptions['id'];
        else
            $this-&gt;htmlOptions['id']=$id;
        if(isset($this-&gt;htmlOptions['name']))
            $name=$this-&gt;htmlOptions['name'];
        if($this-&gt;hasModel())
            echo CHtml::activeTextField($this-&gt;model,$this-&gt;attribute,$this-&gt;htmlOptions);
        else
            echo CHtml::textField($name,$this-&gt;value,$this-&gt;htmlOptions);
        if($this-&gt;sourceUrl!==null)
            $this-&gt;options['source']=CHtml::normalizeUrl($this-&gt;sourceUrl);
        else
            $this-&gt;options['source']=$this-&gt;source;
        $options=CJavaScript::encode($this-&gt;options);
        $js = &quot;jQuery('#{$id}').autocomplete($options){$this-&gt;methodChain};&quot;;
        $cs = Yii::app()-&gt;getClientScript();
        $cs-&gt;registerScript(__CLASS__.'#'.$id, $js);
    }
}
</pre>
<h2>Using our widget</h2>
<p>Now that we have our beautiful widget that handles method chain in our Autocomplete, let&#8217;s assume a couple of things:</p>
<ul>
<li>We saved our class onto a folder in our application -ie protected/extensions</li>
<li>We have a hidden INPUT HTML element with model&#8217;s attribute_id</li>
<li>We have created an action on our testController named autocomplete that returns a JSON object on the following format:</li>
</ul>
<pre class="brush: php; title: ; notranslate">
// This function will echo a JSON object
// on this format:
// [{id:id, name: 'name'}]
public function actionAutocomplete(){
      $res = array();
      $term = Yii::app()-&gt;getRequest()-&gt;getParam('term', false);
      if ($term)
      {
         // test table is for the sake of this example
         $sql = 'SELECT id, name FROM {{test}} where LCASE(name) LIKE :name';
         $cmd = Yii::app()-&gt;db-&gt;createCommand($sql);
         $cmd-&gt;bindValue(&quot;:name&quot;,&quot;%&quot;.strtolower($term).&quot;%&quot;, PDO::PARAM_STR);
         $res = $cmd-&gt;queryAll();
      }
      echo CJSON::encode($res);
      Yii::app()-&gt;end();
}
</pre>
<p>We have everything, let&#8217;s use our widget in our view:</p>
<pre class="brush: php; title: ; notranslate">
// REMEMBER, we have a hidden
// input HTML element with model's attribute_id
&lt;?php echo $form-&gt;hiddenField($model, 'attribute_id'); ?&gt;
&lt;?php
// ext is a shortcut for application.extensions
$this-&gt;widget('ext.myAutoComplete', array(
    'name' =&gt; 'test_autocomplete',
    'source' =&gt; $this-&gt;createUrl('test/autocomplete'),
// attribute_value is a custom property that returns the
// name of our related object -ie return $model-&gt;related_model-&gt;name
    'value' =&gt; $model-&gt;isNewRecord ? '': $model-&gt;attribute_value,
    'options' =&gt; array(
        'minChars'=&gt;3,
        'autoFill'=&gt;false,
        'focus'=&gt; 'js:function( event, ui ) {
            $( &quot;#test_autocomplete&quot; ).val( ui.item.name );
            return false;
        }',
        'select'=&gt;'js:function( event, ui ) {
            $(&quot;#'.CHtml::activeId($model,'attribute_id').'&quot;)
            .val(ui.item.id);
            return false;
        }'
     ),
    'htmlOptions'=&gt;array('class'=&gt;'input-1', 'autocomplete'=&gt;'off'),
    'methodChain'=&gt;'.data( &quot;autocomplete&quot; )._renderItem = function( ul, item ) {
        return $( &quot;&lt;li&gt;&lt;/li&gt;&quot; )
            .data( &quot;item.autocomplete&quot;, item )
            .append( &quot;&lt;a&gt;&quot; + item.name +  &quot;&lt;/a&gt;&quot; )
            .appendTo( ul );
    };'
));
?&gt;
</pre>
<p>Done! Just make sure that when you do submit your form, you get the value from the hidden field instead of the autocomplete element <img src='http://www.ramirezcobos.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Final Notes</h2>
<p>I do not know if there are other ways of doing the same thing (apart from pure Javascript) to have the same results. If you know, with CJuiAutoComplete widget, let us know here.</p>
<p>Hope you find this useful.</p>
<p>Cheers</p>
<a href="http://twitter.com/?status=RT%20%40%3A%20Custom%20Autocomplete%20Display%20and%20Value%20Submission%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2011%2F07%2F14%2Fcustom-autocomplete-display-and-value-submission%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2011/07/14/custom-autocomplete-display-and-value-submission/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Implementing a User Level Access System</title>
		<link>http://www.ramirezcobos.com/2011/04/20/implementing-a-user-level-access-system/</link>
		<comments>http://www.ramirezcobos.com/2011/04/20/implementing-a-user-level-access-system/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 19:23:35 +0000</pubDate>
		<dc:creator>Antonio Ramirez</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Yii]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">http://www.ramirezcobos.com/?p=853</guid>
		<description><![CDATA[
I would like to explain this time how easy is to implement a level access system with Yii framework.
Please note that this article is a simple example and good security should be taken into account when we play with authentication systems.
Step 1: Setting Up
a. Include a field on your user&#8217;s table  [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ramirezcobos.com/2010/10/28/how-to-use-jqueryslidemenu-with-yii%e2%80%99s-cmenu/yii/" rel="attachment wp-att-612"><img src="http://www.ramirezcobos.com/wp-content/uploads/2010/10/Yii.png" alt="Yii Framework" title="Yii Framework" width="160" height="160" class="alignright size-full wp-image-612" /></a></p>
<p>I would like to explain this time how easy is to implement a level access system with Yii framework.</p>
<p>Please note that this article is a simple example and good security should be taken into account when we play with authentication systems.</p>
<h3>Step 1: Setting Up</h3>
<p>a. <strong>Include a field on your user&#8217;s table named, </strong>yep you guessed<strong>, level</strong><br />
b. <strong>Create an object &#8216;LevelLookUp&#8217; </strong>that will tell us who is who on this system</p>
<pre class="brush: php; title: ; notranslate">
class LevelLookUp{
      const MEMBER = 0;
      const ADMIN  = 2;
      // For CGridView, CListView Purposes
      public static function getLabel( $level ){
          if($level == self::MEMBER)
             return 'Member';
          if($level == self::ADMIN)
             return 'Administrator';
          return false;
      }
      // for dropdown lists purposes
      public static function getLevelList(){
          return array(
                 self::MEMBER=&gt;'Member',
                 self::ADMIN=&gt;'Administrator');
	}
}
</pre>
<p>c.<strong>Modifying UserIdentity</strong> so we can store the user Model id on authentication, as CWebUser&#8217;s default id is set to the user Model&#8217;s username:</p>
<pre class="brush: php; title: ; notranslate">
class UserIdentity extends CUserIdentity
{
	private $_id;
	/**
	 * Authenticates a user.
	 * @return boolean whether authentication succeeds.
	 */
	public function authenticate()
	{
		$username = strtolower($this-&gt;username);
                // from database... change to suite your authentication criteria
		$user = User::model()-&gt;find('LOWER(username)=?', array($username));
		if($user===null)
			$this-&gt;errorCode=self::ERROR_USERNAME_INVALID;
		else if(!$user-&gt;validatePassword($this-&gt;password))
			$this-&gt;errorCode = self::ERROR_PASSWORD_INVALID;
		else{
			$this-&gt;_id = $user-&gt;id;
			$this-&gt;username = $user-&gt;username;
			$this-&gt;errorCode = self::ERROR_NONE;
		}
		return $this-&gt;errorCode == self::ERROR_NONE;
	}
	public function getId()
	{
		return $this-&gt;_id;
	}
}
</pre>
<p>d. <strong>Modify CWebUser&#8217;s application</strong> in order to hold the &#8216;level&#8217; property. We are going to call it EWebUser and will extend from CWebUser, and save it on protected/components to be loaded automatically by our default&#8217;s configuration file.</p>
<pre class="brush: php; title: ; notranslate">
class EWebUser extends CWebUser{
    protected $_model;
    function isAdmin(){
        $user = $this-&gt;loadUser();
        if ($user)
           return $user-&gt;level==LevelLookUp::ADMIN;
        return false;
    }
    // Load user model.
    protected function loadUser()
    {
        if ( $this-&gt;_model === null ) {
                $this-&gt;_model = User::model()-&gt;findByPk( $this-&gt;id );
        }
        return $this-&gt;_model;
    }
}
</pre>
<p>e. <strong>Modify our main.php</strong> config file (this file is in protected/config folder)</p>
<pre class="brush: php; title: ; notranslate">
// go to the 'user' section
// application components
	'components'=&gt;array(
		'user'=&gt;array(
                        // There you go, use our 'extended' version
			'class'=&gt;'application.components.EWebUser',
			// enable cookie-based authentication
			'allowAutoLogin'=&gt;true,
		),
</pre>
<h3>Step 2: Putting everything together</h3>
<p>Now that we know, who logged, we could easily find out if it is just a member or an administrator and render the elements by checking the level as simple as this:</p>
<pre class="brush: php; title: ; notranslate">
// for normal content
if(Yii::app()-&gt;user-&gt;isAdmin())
     echo 'Is administrator';
// for CMenus
$this-&gt;widget('zii.widgets.CMenu',array(
    array('label'=&gt;'Categories',
           'url'=&gt;array('/category/index'),
           'visible'=&gt;(Yii::app()-&gt;user-&gt;isAdmin()),
     //... More stuff
     //...
// for data chuncks
&lt;?php if(Yii::app()-&gt;user-&gt;isAdmin():?&gt;
&lt;b&gt;My HTML&lt;/b&gt;
&lt;?php endif;?&gt;
// for access rules
return array(
      array('allow',
        'actions'=&gt;array('create','delete','update'),
        'expression'=&gt;'$user-&gt;isAdmin()'
      ),
// ...
</pre>
<p><center><br />
<br />
</center></p>
<a href="http://twitter.com/?status=RT%20%40%3A%20Implementing%20a%20User%20Level%20Access%20System%20-%20El%20Blog%20del%20Antonio%20http%3A%2F%2Fwww.ramirezcobos.com%2F2011%2F04%2F20%2Fimplementing-a-user-level-access-system%2F" class="tweet-this" ><img src="http://www.ramirezcobos.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="Tweet this!" alt="Tweet this!" />Tweet this!</a>]]></content:encoded>
			<wfw:commentRss>http://www.ramirezcobos.com/2011/04/20/implementing-a-user-level-access-system/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: www.ramirezcobos.com @ 2012-05-18 21:28:32 by W3 Total Cache -->
