<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Aaron Thies</title>
	
	<link>http://www.aaronthies.com/wp</link>
	<description>Front-End Engineer</description>
	<lastBuildDate>Sun, 02 Oct 2011 03:16:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/athies" /><feedburner:info uri="athies" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Pagination and a Few More Items</title>
		<link>http://feedproxy.google.com/~r/athies/~3/rWQrivYHmmM/</link>
		<comments>http://www.aaronthies.com/wp/2008/12/28/pagination-and-a-few-more-items/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 08:46:51 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://aaronthies.com/wp/?p=59</guid>
		<description><![CDATA[Pagination is quite easy in CakePHP, until you need some WHERE clause filtering, then it is almost as easy. Notice the second parameter to the paginate() function. This is actually documented in the Cake Cookbook (http://book.cakephp.org/view/165/Controller-Setup @ the very bottom of the page), but I missed it the first read through. /app/controllers/adopt_controller.php class AdoptController extends [...]]]></description>
			<content:encoded><![CDATA[<p>Pagination is quite easy in CakePHP, until you need some WHERE clause filtering, then it is almost as easy.  Notice the second parameter to the paginate() function.  This is actually documented in the Cake Cookbook (<a href="http://book.cakephp.org/view/165/Controller-Setup">http://book.cakephp.org/view/165/Controller-Setup</a> @ the very bottom of the page), but I missed it the first read through.</p>
<h3>/app/controllers/adopt_controller.php</h3>
<pre>
class AdoptController extends AppController {

...

public $paginate = array(
                                   'limit' => 20,
                                   'order' => array('Adopt.date_added' => 'DESC'),
                                   'fields' => array(
                                                         'id',
                                                         'type',
                                                         'interest',
                                                         'your_name',
                                                         'UNIX_TIMESTAMP(date_added)
                                                             AS date_added'));

...

function index() {
    $search = array();

    if (!empty($this->data['Adopt']['interest'])) {
        $search['interest LIKE'] = '%' . $this->data['Adopt']['interest'] . '%';
    }

    if (!empty($this->data['Adopt']['your_name'])) {
        $search['your_name LIKE'] = '%' . $this->data['Adopt']['your_name'] . '%';
    }

    $this->set('apps', $this->paginate('Adopt', $search));
}
}
</pre>
<hr />
<p>I was installing WordPress 2.7 on the same site as a CakePHP app.  I installed WordPress to /app/webroot/blog/.  I expected this to work just fine.  The problem was using http://www.mydomain.com/blog/ (trailing slash) worked just fine, but http://www.mydomain.com/blog (no trailing slash) redirected me to http://www.mydomain/com/app/webroot/blog/.  After quite some time of aggravation I finally fixed it by changing my /public_html/.htaccess files to this:</p>
<pre>
<ifmodule mod_rewrite.c>
   RewriteEngine on

   RedirectMatch temp ^/blog/wp-admin$ http://www.mywebsite.org/blog/wp-admin/

   RewriteRule blog$ /blog/ [L]
   RewriteRule blog/wp-admin$ /blog/wp-admin/ [L]
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</ifmodule>
</pre>
<p>This is the standard CakePHP root .htaccess file, but with the RewriteRule for &#8220;blog&#8221; and &#8220;blog/wp-admin&#8221; added.  I later found out I needed to add the RedirectMatch to have WP admin left nav work.  <a href="http://jeff.loiselles.com/wordpress/?p=22">Thanks to Jeff Loiselle&#8217;s post</a>.</p>
<hr />
<p>So as not to end on a negative note, I wanted to mention a cool FireFox Add-on I learned of.  It is called <a href="http://www.smush.it">smush.it</a>.  This add-on will analyze all the images on the page, running each through a series of compression algorithms.  Then it lists each image, and the optimal format for each.  You are given a complete report of each image and how much space is saved, along with a link to download a zip with all the new images.</p>
<img src="http://feeds.feedburner.com/~r/athies/~4/rWQrivYHmmM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.aaronthies.com/wp/2008/12/28/pagination-and-a-few-more-items/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.aaronthies.com/wp/2008/12/28/pagination-and-a-few-more-items/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=pagination-and-a-few-more-items</feedburner:origLink></item>
		<item>
		<title>Auth… Finally!</title>
		<link>http://feedproxy.google.com/~r/athies/~3/yfac_TSPnKQ/</link>
		<comments>http://www.aaronthies.com/wp/2008/08/06/auth-finally/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 06:11:27 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://aaronthies.com/wp/?p=36</guid>
		<description><![CDATA[Finally, after several attempts, I have Auth working.  Now I&#8217;ll attempt to explain in a simple manner, like most of the sources I found.  I will also attempt to include all caveats, unlike any of the sources I found. app/config/core.php Place a salt value in Security.salt. You may want to increase Session.timeout beyond the default [...]]]></description>
			<content:encoded><![CDATA[<p>Finally, after several attempts, I have Auth working.  Now I&#8217;ll attempt to explain in a simple manner, like most of the sources I found.  I will also attempt to include all caveats, unlike any of the sources I found.</p>
<h3>app/config/core.php</h3>
<p>Place a salt value in Security.salt.</p>
<p>You may want to increase Session.timeout beyond the default 2 minutes.</p>
<h3>app/controller/users_controller.php</h3>
<pre>uses('sanitize');
class UsersController extends AppController {

    public $name = 'Users';
    public $components = array('Auth');

    function beforeFilter() {
        Security::setHash('sha1');
    }

    // The AuthComponent provides the needed functionality
    // or login, so you can leave this function blank.
    function login() {
    }

    function logout() {
        $this-&gt;redirect($this-&gt;Auth-&gt;logout());
    }

}</pre>
<p>Make sure you add Auth to the components array of any controller you plan to have any authentication on:</p>
<pre>public $components = array('Auth');</pre>
<p>Also you can specify which controller methods do not need authentication like this:</p>
<pre>function beforeFilter() {
    $this-&gt;Auth-&gt;allow('index', 'results', 'animal',
        'spotlight', 'breed');
}</pre>
<h3>app/model/</h3>
<p>No model file is needed, but you need to create a database table with id, username, and password fields.  Any other fields will be paced in the Auth object (inside session), like this:</p>
<pre>[Auth] =&gt; Array
        (
            [User] =&gt; Array
                (
                    [id] =&gt; 53
                    [first_name] =&gt; Aaron
                    [last_name] =&gt; Thies
                    [email] =&gt; athies@gmail.com
                    [username] =&gt; athies
                )

        )</pre>
<p>You can find out what to set the password value in the users db table by using $this-&gt;Auth-&gt;password(&#8216;password&#8217;).  This caused me a lot of aggravation as I was just using SHA1(&#8216;password&#8217;).</p>
<p>You can tweak Auth using the various Auth methods outlined here: <a href="http://book.cakephp.org/view/172/authentication">http://book.cakephp.org/view/172/authentication</a>. These methods can be placed inside controller::beforeFilter().</p>
<h3>app/views/users/login.ctp</h3>
<pre>if  ($session-&gt;check('Message.auth')) $session-&gt;flash('auth');

if ($session-&gt;check('Message.flash')) {
    $session-&gt;flash();
}

if ($session-&gt;check('Message.auth')) {
    $session-&gt;flash('auth');
}

echo $form-&gt;create('User', array('action' =&gt; 'login'));
echo $form-&gt;input('username');
echo $form-&gt;input('password');
echo $form-&gt;end('Login');</pre>
<h3>A Little Something More</h3>
<p>During the course of getting Auth to work I learned this helpful hint.</p>
<p>If you ever produced this error, &#8220;Database table users for model User was not found.&#8221;, you can fix this by deleting everything in this folder: /app/tmp/cache/models</p>
<img src="http://feeds.feedburner.com/~r/athies/~4/yfac_TSPnKQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.aaronthies.com/wp/2008/08/06/auth-finally/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.aaronthies.com/wp/2008/08/06/auth-finally/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=auth-finally</feedburner:origLink></item>
		<item>
		<title>YUI AutoComplete with CakePHP</title>
		<link>http://feedproxy.google.com/~r/athies/~3/0zWErLLppnc/</link>
		<comments>http://www.aaronthies.com/wp/2008/07/29/yui-autocomplete-with-cakephp/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 18:59:09 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://aaronthies.com/wp/?p=22</guid>
		<description><![CDATA[YUI Autocomplete Usually I find the YUI components fairly easy to understand and implement. Not so with Autocomplete. After a lot of aggrivation I have it implemented. Hopefully my work here will save you the same time and hassel I experienced. The resource best resource I found was James Gardner&#8217;s YUI Autocomplete AJAX Select Dropdown [...]]]></description>
			<content:encoded><![CDATA[<h3>YUI Autocomplete</h3>
<p>Usually I find the YUI components fairly easy to understand and implement.  Not so with Autocomplete.  After a lot of aggrivation I have it implemented.  Hopefully my work here will save you the same time and hassel I experienced. The resource best resource I found was <a href="http://jimmyg.org/2007/10/19/yui-autocomplete-ajax-select-drowdown-with-id/">James Gardner&#8217;s YUI Autocomplete AJAX Select Dropdown with ID</a> post.</p>
<h3>Model</h3>
<pre>
public function getBreed($query) {

    $sql = "SELECT id, name FROM breed
                     WHERE name LIKE '" . Sanitize::escape($query) . "%'
                     ORDER BY name";
    $model = $this->query($sql);

    // do this immediately after the query
    $totalResultsReturned = $this->getAffectedRows();

    $sql = "SELECT COUNT(*) AS count FROM breed";
    $result = $this->query($sql);
    $totalResultsAvailable = $result[0][0]['count'];

    $json = '';

    $breed = array();
    foreach ($model as $entry) {
        $breed['Name'] = $entry['breed']['name'];
        $breed['ID'] = $entry['breed']['id'];
        $json .= json_encode($breed) . ",";
    }
    $json = substr($json, 0, strlen($json)-1);

    $json = '{"ResultSet": {"totalResultsAvailable":"' . $totalResultsAvailable .
                                    '","totalResultsReturned":' . $totalResultsReturned .
                                     ',"firstResultPosition":1,"Result": [' . $json . ']}}';

    return $json;
}
</pre>
<h3>View Header</h3>
<p>Include these css/js files:</p>
<pre>

http://yui.yahooapis.com/2.5.2/build/autocomplete/assets/skins/sam/autocomplete.css

http://yui.yahooapis.com/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js

http://yui.yahooapis.com/2.5.2/build/get/get-min.js

http://yui.yahooapis.com/2.5.2/build/connection/connection-min.js

http://yui.yahooapis.com/2.5.2/build/animation/animation-min.js

http://yui.yahooapis.com/2.5.2/build/json/json-min.js

http://yui.yahooapis.com/2.5.2/build/autocomplete/autocomplete-min.js
</pre>
<h3>View</h3>
<pre>
    label for="breed">Breed
        input id="breed_id" type="hidden" name="breed_id" />
        input id="breed" type="text" name="item" maxlength="50"/>
        div id="breedContainer">

    script type="text/javascript">
        var mySchema = ["ResultSet.Result","Name","ID"];
        var myDataSource = new YAHOO.widget.DS_XHR("/find_a_pet/breed", mySchema);
        myDataSource.responseType = YAHOO.widget.DS_XHR.TYPE_JSON;
        var myAutoComp = new YAHOO.widget.AutoComplete("breed", "breedContainer", myDataSource);

        // populate hidden field (id)
        function fnCallback(e, args) {
            YAHOO.util.Dom.get("breed_id").value = args[2][1];
         }
        myAutoComp.itemSelectEvent.subscribe(fnCallback);

        //myAutoComp.forceSelection = true;
        //myAutoComp.useIFrame = true;
</pre>
<h3>Controller</h3>
<pre>
// directly execute... /find_a_pet/breed?query=labr
function breed() {
    $this->layout = null;
    $query = (ctype_print($_GET['query'])) ? $query = $_GET['query'] : $query = '';
    $this->set('breed', $this->FindAPet->getBreed($query));
}
</pre>
<h3>Missing data in beforeValidate()</h3>
<p>If you are submitting a form and the data is not visible in model::beforevalidate(), then you can solve this by adding $this->Model->data = $this->data in the controller before validates().  Once you do this you can use $this->data in beforevalidate().</p>
<pre>
function admin_add() {
    if (!empty($this->data)) {
        $this->FindAPet->data = $this->data;
        if ($this->FindAPet->validates()) {
          $this->FindAPet->save();
</pre>
<img src="http://feeds.feedburner.com/~r/athies/~4/0zWErLLppnc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.aaronthies.com/wp/2008/07/29/yui-autocomplete-with-cakephp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.aaronthies.com/wp/2008/07/29/yui-autocomplete-with-cakephp/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=yui-autocomplete-with-cakephp</feedburner:origLink></item>
		<item>
		<title>Remove ‘Pages’ from Static Pages</title>
		<link>http://feedproxy.google.com/~r/athies/~3/OZMPKpPXp0g/</link>
		<comments>http://www.aaronthies.com/wp/2008/07/27/remove-pages-from-static-pages/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 03:21:30 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://aaronthies.com/wp/?p=24</guid>
		<description><![CDATA[I can&#8217;t take credit for this tip, but it works great. Routing for Static Pages]]></description>
			<content:encoded><![CDATA[<p>I can&#8217;t take credit for this tip, but it works great.</p>
<p><a href="http://richardathome.wordpress.com/2007/08/13/cakephp-tip-routing-for-static-pages/">Routing for Static Pages</a></p>
<img src="http://feeds.feedburner.com/~r/athies/~4/OZMPKpPXp0g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.aaronthies.com/wp/2008/07/27/remove-pages-from-static-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.aaronthies.com/wp/2008/07/27/remove-pages-from-static-pages/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=remove-pages-from-static-pages</feedburner:origLink></item>
		<item>
		<title>Simple Form to Email</title>
		<link>http://feedproxy.google.com/~r/athies/~3/-cejZSKOkfQ/</link>
		<comments>http://www.aaronthies.com/wp/2008/02/06/simple-form-to-email/#comments</comments>
		<pubDate>Wed, 06 Feb 2008 22:38:09 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://aaronthies.com/wp/2008/02/06/simple-form-to-email/</guid>
		<description><![CDATA[I have constructed a simple contact (to email) form in CakePHP 1.2 Beta. Rather than try to explain it all I have included the code for the model, controller, and view here. One note is I had to add a minLength validation check to the textarea as fields defined as &#8216;text&#8217; in the model schema [...]]]></description>
			<content:encoded><![CDATA[<p>I have constructed a simple contact (to email) form in CakePHP 1.2 Beta.  Rather than try to explain it all I have included the code for the model, controller, and view here.  One note is I had to add a minLength validation check to the textarea as fields defined as &#8216;text&#8217; in the model schema do not echo errors by default, as string fields do.</p>
<h3>Model</h3>
<pre>
class Contact extends AppModel {
    var $name = 'Contact';
    var $useTable = false;

    var $_schema = array(
        'firstName' => array('type' => 'string', 'length' => 30),
        'lastName' => array('type' => 'string', 'length' => 30),
        'email' => array('type' => 'string', 'length' => 30),
        'msg' => array('type' => 'text')
    );

    var $validate = array(
        'firstName' => array(
            'alphaNumeric' => array(
                'rule' => 'alphaNumeric',
                'required' => true,
                'message' => 'firstNameAlphaNumeric'
            ),
            'between' => array(
                'rule' => array('between', 1, 30),
                'message' => 'firstNameBetween'
            )
        ),
        'lastName' => array(
            'alphaNumeric' => array(
                'rule' => 'alphaNumeric',
                'required' => true,
                'message' => 'lastNameAlphaNumeric'
            ),
            'between' => array(
                'rule' => array('between', 1, 30),
                'message' => 'lastNameBetween'
            )
        ),
        'email' => array(
            'email' => array(
                'rule' => array('email', true),
                'required' => true,
                'message' => 'emailEmail'
            ),
            'between' => array(
                'rule' => array('between', 6, 30),
                    'message' => 'emailBetween'
                )
            ),
            'msg' => array(
                'rule' => array('minLength', 1),
                'message' => 'msgMinLength'
            )
        );
}
</pre>
<h3>View</h3>
<pre>
<div>
    < ?= $form->create('Contact', array('url' => '/contact')) ?>
    < ?php
    /*
    <?= $form->input('firstName', array('maxlength' => 30)) ?>
    < ?= $form->input('lastName', array('maxlength' => 30)) ?>
    < ?= $form->input('email', array('maxlength' => 30)) ?>
    < ?= $form->input('msg', array('type' => 'textarea')) ?>
    */
    echo $form->inputs(array('firstName', 'lastName', 'email', 'msg'));
    ?>
    < ?= $form->end(__('submit', true)) ?>
</div>
</pre>
<h3>Controller</h3>
<pre>
class ContactController extends AppController {
    var $name = 'Contact';
    var $uses = 'Contact';
    var $components = array('Email');

    function index() {
        if (isset($this->data)) {
          if ($this->Contact->create($this->data) &#038;&#038; $this->Contact->validates()) {
              $name = $this->data['Contact']['firstName'] . ' ' . $this->data['Contact']['lastName'];
              $from = $this->data['Contact']['email'];
              $subject = 'Contact Us';
              $msg = $this->data['Contact']['msg'];

              $this->Email->sendAs = 'both'; // html, text, both
              $this->Email->layout = 'contact'; // views/layouts/email/html/contact.ctp
              $this->Email->template = 'contact';

              // set view variables as normal
              $this->set('from', $name);
              $this->set('msg', $msg);

              $this->Email->to = 'athies@gmail.com';
              $this->Email->from = $from;
              $this->Email->subject = $subject;

              if ($this->Email->send($msg)) {
                  $this->Session->setFlash(__('contactUsSent', true));
              }

          }
      }

  }

}
</pre>
<img src="http://feeds.feedburner.com/~r/athies/~4/-cejZSKOkfQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.aaronthies.com/wp/2008/02/06/simple-form-to-email/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.aaronthies.com/wp/2008/02/06/simple-form-to-email/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=simple-form-to-email</feedburner:origLink></item>
		<item>
		<title>CakePHP 1.2 Flash Usage</title>
		<link>http://feedproxy.google.com/~r/athies/~3/9aWBBMwfP70/</link>
		<comments>http://www.aaronthies.com/wp/2008/02/01/cakephp-12-flash-usage/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 18:31:04 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://aaronthies.com/wp/2008/02/01/cakephp-12-flash-usage/</guid>
		<description><![CDATA[Another short article today on something that took me some digging (but not as much as usual!) to learn. You see mention of setFlash() all the time when looking for CakePHP info. Until now I never knew how to implement the view side of this properly. He is the simple example (the kind I like [...]]]></description>
			<content:encoded><![CDATA[<p>Another short article today on something that took me some digging (but not as much as usual!) to learn.  You see mention of setFlash() all the time when<br />
looking for CakePHP info.  Until now I never knew how to implement the view side of this properly.  He is the simple example (the kind I like the best) for using flash.</p>
<h3>Controller</h3>
<pre>$this-&gt;Session-&gt;setFlash('your email is coming');</pre>
<p>view:</p>
<pre>if ($session-&gt;check('Message.flash')) {
    $session-&gt;flash();
}</pre>
<p>Note: You do not have to include Session in your component list in your controller for this to work.  Also, you may want to place the $session-&gt;flash() code in your layout instead of in various views.</p>
<p>Happy Cake&#8217;n</p>
<h3>Update</h3>
<p>It was not clear to me how to use the flash method, but here it is:</p>
<p>$this-&gt;flash(&#8216;The animal has been modified.&#8217;, &#8216;/find_a_pet/search&#8217;, 3);</p>
<p>The first parameter is the message.</p>
<p>The second parameter is the url to redirect the user.</p>
<p>The third parameter is the number of seconds before redirecting.</p>
<img src="http://feeds.feedburner.com/~r/athies/~4/9aWBBMwfP70" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.aaronthies.com/wp/2008/02/01/cakephp-12-flash-usage/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.aaronthies.com/wp/2008/02/01/cakephp-12-flash-usage/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cakephp-12-flash-usage</feedburner:origLink></item>
		<item>
		<title>CakePHP Schema and Tableless Models</title>
		<link>http://feedproxy.google.com/~r/athies/~3/uwm9jaIau_8/</link>
		<comments>http://www.aaronthies.com/wp/2008/01/31/cakephp-schema-and-tableless-models/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 18:35:58 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://aaronthies.com/wp/2008/01/31/cakephp-schema-and-tableless-models/</guid>
		<description><![CDATA[I have upgraded to the recent CakePHP 1.2 Beta release, and using a model without a real database table has changed. You need to defined the schema in the model. Schemas exist for models with tables also, so you can this in your model (with a table) to see an example. pr($this-&#62;Model-&#62;schema()); exit(); Now, in [...]]]></description>
			<content:encoded><![CDATA[<p>I have upgraded to the recent CakePHP 1.2 Beta release, and using a model without a real database table has changed.  You need to defined the schema in the model.  Schemas exist for models with tables also, so you can this in your model (with a table) to see an example.</p>
<pre>
pr($this-&gt;Model-&gt;schema());
exit();</pre>
<p>Now, in your model without a real database table you defined the schema like this:</p>
<pre>
var $_schema = array(
    'firstName' =&gt; array('type' =&gt; 'string', 'length' =&gt; 30),
    'lastName' =&gt; array('type' =&gt; 'string', 'length' =&gt; 30),
    'email' =&gt; array('type' =&gt; 'string', 'length' =&gt; 30),
    'msg' =&gt; array('type' =&gt; 'text')
);</pre>
<p>Now you can create validation rules in your model as normal (future post on this once I am confident).</p>
<p>One other note before I defined a schema I was given an &#8220;excessive memory&#8221; error.</p>
<p><strong>Fatal error</strong>:  Allowed memory size of 41943040 bytes exhausted (tried to allocate 35 bytes) in <strong>XXX/cake/libs/debugger.php</strong> on line <strong>414</strong></p>
<p>&#8230; when adding $form-&gt;create() to my view.  This error reports the problem on some line of debugger.php.  Once you comment out this line (and maybe a few more it will report) you will see an error&#8230;</p>
<p>Warning (512): (FormHelper::create) Unable to use model field data. If you are using a model without a database table, try implementing schema() [CORE/cake/libs/view/helpers/form.php, line 124]<br />
Warning (512): (Model::getColumnType) Unable to locate model field data. If you are using a model without a database table, try implementing schema() [CORE/cake/libs/model/model.php, line 959]</p>
<p>I hope this saves someone the time it took me to solve this issue.  Happy Cake&#8217;n.</p>
<img src="http://feeds.feedburner.com/~r/athies/~4/uwm9jaIau_8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.aaronthies.com/wp/2008/01/31/cakephp-schema-and-tableless-models/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://www.aaronthies.com/wp/2008/01/31/cakephp-schema-and-tableless-models/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cakephp-schema-and-tableless-models</feedburner:origLink></item>
		<item>
		<title>CakePHP 1.2 i18n/l10n</title>
		<link>http://feedproxy.google.com/~r/athies/~3/9LzbuFdSvX0/</link>
		<comments>http://www.aaronthies.com/wp/2007/08/03/cakephp-12-i18nl10n/#comments</comments>
		<pubDate>Sat, 04 Aug 2007 00:59:48 +0000</pubDate>
		<dc:creator>Aaron</dc:creator>
				<category><![CDATA[CakePHP]]></category>

		<guid isPermaLink="false">http://aaronthies.com/wp/2007/08/03/cakephp-12-i18nl10n/</guid>
		<description><![CDATA[A few month ago I started working with the CakePHP framework. I needed the i18n functionality that was in version 1.2 (late alpha). After a lot of research I was able to get what I needed. I wrote up my findings and submitted this to the CakePHP developers. They have accepted my submission on using [...]]]></description>
			<content:encoded><![CDATA[<p>A few month ago I started working with the <a href="http://www.cakephp.org">CakePHP</a> framework.  I needed the i18n functionality that was in version 1.2 (late alpha).  After a lot of research I was able to get what I needed.  I wrote up my findings and submitted this to the CakePHP developers.  They have accepted my submission on using i18n in 1.2 and it will appear in the <a href="http://tempdocs.cakephp.org/">CakePHP 1.2 Manual</a>.  This is my first contribution back to the open source community and while it is just a small bit, I am quite proud to have made even a small contribution back to what has given me so much.  Since the 1.2 manual is not yet available I thought I&#8217;d post my contribution here:</p>
<h3>Localization and Internationalization</h3>
<p><strong>What is the difference? </strong>Localization refers to the ADAPTATION of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a &#8220;locale&#8221;).  Internationalization is the DESIGN AND DEVELOPMENT of a product, application or document content that ENABLES easy localization for target audiences that vary in culture, region, or language.</p>
<ul>
<li><a href="http://www.w3.org/International/questions/qa-i18n">http://www.w3.org/International/questions/qa-i18n</a></li>
<li>&#8220;internationalization&#8221; and &#8220;localization&#8221; are often abbreviated as i18n and l10n respectively; 18 and 10 are the number of characters between the first and last character.</li>
</ul>
<h3>How to Use Localization</h3>
<ol>
<li><strong>Include l10n Class</strong>
<pre>uses('L10n');

class OrderController extends AppController {
    ...
}</pre>
</li>
<li><strong>Create Language File</strong> Specific language translations are placed here:
<pre>locale/eng/LC_MESSAGES/default.po (English)
locale/fre/LC_MESSAGES/default.po (French)</pre>
<p>Language directories must be named with the official three-digit language code; you can find these here: <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php">http://www.loc.gov/standards/iso639-2/php/code_list.php</a></li>
<li><strong>Populate Language file</strong> Create entries in the appropriate default.po file in this form:
<pre>msgid  "close_window"
msgstr "Close"

msgid  "where_pin"
msgstr "Where is my PIN?"</pre>
<p>There is a limit of 1014 characters in a single msgstr.</li>
<li><strong>Using</strong> Use the underscore-underscore method, providing the msgid as the first parameter.
<pre>__("closeWindow");
__("closeWindow", true);</pre>
<p>If the msgid provided is not found, then the provided value id used, hence some people like to use the default text as the msgid:</p>
<pre>__("Close Window");</pre>
<p>With the second parameter as true the value is returns, without the second parameter is echo&#8217;d.  If you see your msgid on your page instead of cooresponding msgstr, and the msgid/msgstr pair exists in the relevant default.po file, then you probably are missing dbouel quotes around the msgid or msgstr entry.</li>
<li><strong>Selecting Language</strong> To select the language you want:
<pre>$this-&gt;L10n = new L10n();$this-&gt;L10n-&gt;get("en");
$_SESSION['Config']['language'] = "en";</pre>
<p>Use the first two-digits of the language code (yes, I know it is weird to use two-digits here and three-digits as the language directory name).  Configure::write(&#8216;Config.language&#8217;, &#8220;en&#8221;) will work in place of $_SESSION['Config']['language'] = &#8220;en&#8221; in the future, but it does not work as of 1.2.0.4798alpha.</li>
</ol>
<h3>Real-Life Implementation Example</h3>
<p>I created a language helper method:</p>
<pre>public function setLang($language = 'en') {
    $this-&gt;L10n = new L10n();
    $this-&gt;L10n-&gt;get($language);
    //Configure::write('Config.language', $language);
    $_SESSION['Config']['language'] = $language;
}</pre>
<p>Then I use it in my controller methods as needed.</p>
<pre>function balance() {
    Utility::setLang(LOCALE);
    ...
}</pre>
<p>And LOCALE is a constant = &#8220;en&#8221;.</p>
<h3>Special Characters</h3>
<p>Save the default.po files with an encoding of ISO-8859-1 htmlentities will not render correctly if when used in $form-&gt;error() unless you turn off the espcae option:</p>
<pre>echo $form-&gt;error('Card.cardNumber', __("errorCardNumber", true), array('escape' =&gt; false));</pre>
<img src="http://feeds.feedburner.com/~r/athies/~4/9LzbuFdSvX0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.aaronthies.com/wp/2007/08/03/cakephp-12-i18nl10n/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		<feedburner:origLink>http://www.aaronthies.com/wp/2007/08/03/cakephp-12-i18nl10n/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cakephp-12-i18nl10n</feedburner:origLink></item>
	</channel>
</rss>

