<?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/"
xmlns:series="http://unfoldingneurons.com/"
><channel><title>Larry Ullman &#187; yii</title> <atom:link href="http://www.larryullman.com/tag/yii/feed/" rel="self" type="application/rss+xml" /><link>http://www.larryullman.com</link> <description>Translating Geek Into English</description> <lastBuildDate>Mon, 21 May 2012 11:03:07 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Working with Layouts in Yii</title><link>http://www.larryullman.com/2012/05/16/working-with-layouts-in-yii/</link> <comments>http://www.larryullman.com/2012/05/16/working-with-layouts-in-yii/#comments</comments> <pubDate>Wed, 16 May 2012 11:00:20 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[mvc]]></category> <category><![CDATA[yii]]></category> <category><![CDATA[yiiframework]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3196</guid> <description><![CDATA[Using the Model-View-Controller (MVC) design pattern, the look of a Yii-based site is naturally controlled by the View files. These files are a combination of HTML and PHP that help to create the desired output. Specific pages in a site will use specific View files. In fact, the View files are designed to be broken [...]]]></description> <content:encoded><![CDATA[<p>Using the <a
href="http://en.wikipedia.org/wiki/Model–view–controller">Model-View-Controller (MVC)</a> design pattern, the look of a <a
href="http://www.yiiframework.com">Yii</a>-based site is naturally controlled by the View files. These files are a combination of HTML and PHP that help to create the desired output. Specific pages in a site will use specific View files. In fact, the View files are designed to be broken down quite atomically, such that, for example, the form used to both create and edit an employee record is its own file, and that file can be included by both <strong>create.php</strong> and <strong>update.php</strong>. As with most things in OOP, implementing atomic, <a
href="http://ezinearticles.com/?The-Importance-of-Decoupled-Objects-in-OOP&amp;id=4073112">decoupled</a> functionality goes a long way towards improving reusability. But the individual View files are only part of the equation for rendering a Web page. Individual view files get rendered within a <em>layout</em> file. And although I&#8217;ve mentioned layouts a time or two in my writings on Yii, it&#8217;s a subject that deserves its own post.<span
id="more-3196"></span></p><p>To be clear, layouts <em>are</em> a type of View file. Specifically, whereas other View files get placed within a directory for the corresponding Controller (i.e., the <strong>SiteController</strong> pulls from <strong>views/site</strong>), layout files go within <strong>views/layouts</strong>. But while the other View files are associated with individual Controllers (and therefore, individual pages), layouts are communal, shared by all the pages. Simply put, a layout file is the parent wrapper for the entire site&#8217;s templating system. I&#8217;ll explain&#8230;</p><h2>The Premise of Templates</h2><p>When you begin creating dynamic Web sites using PHP, you&#8217;ll quickly recognize that many parts of an HTML page will be repeated throughout the site. For example, the opening and closing HTML and BODY tags. Even the site you&#8217;re looking at now has repeating elements: the header, the navigation, the footer, etc. To create a template system, you would pull all of those common elements out and put them into one (or more) separate files. Then each specific page can include these files around the page-specific content:</p><pre class="brush: php; title: ; notranslate">include('header.html');
// Add page-specific content.
include('footer.html'); </pre><p>This is the approach I would use on non-framework-based sites. It&#8217;s easy to generate and maintain. If you need to change the header for the entire site, you only need to edit the one file.</p><h2>Templates in Yii</h2><p>When using a framework, you&#8217;ll probably end up with a &#8220;bootstrap&#8221; approach, where all of the pages are accessed through one file. In the case of Yii, that bootstrap file is <strong>index.php</strong>. Part of its job is to manufacture the necessary HTML for the requested resource. Whereas the non-framework approach pulls the template files into the page-specific file, Yii pulls all the files from includes and assembles them together. Of these files, the layout files constitute all the common elements; everything that&#8217;s not page-specific. If you look at a Yii-generated site, you&#8217;ll see that <strong>views/layouts/main.php</strong> begins with the DOCTYPE and opening HTML tag, then has the HTML HEAD and all its jazz, then starts the BODY, and finally has the footer material and the closing tags. In the middle of the body of the code, you&#8217;ll see this line:</p><pre class="brush: php; title: ; notranslate">&lt;!--?php echo $content; ?--&gt;</pre><p>This is a magic line as it pulls in the page-specific content. If the site you&#8217;re looking at now used Yii, the value of <strong>$content</strong> would be all the HTML that makes up this post you&#8217;re reading. For a Yii example, when the user is looking at <strong>site/login</strong>, the <strong>SiteController</strong>&#8216;s <strong>actionLogin()</strong> method will be called. That method will render the <strong>views/site/login.php</strong> View page, pulling that file&#8217;s contents into the main layout file at that <strong>echo $content</strong> location. That&#8217;s what&#8217;s going on behind the scenes.</p><p>So here, then, is the first key concept: if you want to change the general look of your Web site, edit the layout file (<strong>views/layouts/main.php</strong>). If you were to take your HTML mockup for your site, drop in the <strong>echo $content;</strong> line at the right place, and save it as <strong>views/layout/main.php</strong>, you will have created a custom look for your Web app. That is the basic principle and it&#8217;s essentially that simple.</p><p>To take layouts a step further, many sites will use variations on a theme. For example, the first Yii-based site I created used one header for the home page and another header for other pages, with all the remaining common elements being consistent. Or, I worked on an e-commerce project where one category of products used layout A and another category used layout B. If you have this need, there are a couple of ways of going about it.</p><h2>Creating a Second Layout</h2><p>The first and most obvious route is to create a second layout file. In the example where the site&#8217;s home page used a variation on the template, I created <strong>views/layouts/home.php</strong>. It was based upon <strong>main.php</strong>, with the necessary edits. To dynamically switch layouts, I changed the value assigned to the <strong>layout</strong> property within the proper Controller method:</p><pre class="brush: php; title: ; notranslate">// protected/controllers/SiteController.php
public function actionIndex() {
    $this-&gt;layout = 'home';</pre><p>And that&#8217;s all there is to it. When <strong>views/site/index.php</strong> would be rendered, it&#8217;d use the <strong>views/layouts/home.php</strong> template.</p><p>Although this approach is easy to understand and implement, it has a downside: a LOT of HTML is being repeated between the two layout files. If I needed to change the navigation, I had to edit both files in the same way. This leads us to option B.</p><h2>Hijacking the Content</h2><p>More recent versions of Yii will automatically create three layout files when you create a new Web app:</p><ul><li><strong>views/layouts/column1.php</strong></li><li><strong>views/layouts/column2.php</strong></li><li><strong>views/layouts/main.php</strong></li></ul><p>Although all three are layout files, you don&#8217;t have three different template files. The <strong>main.php</strong> file still creates the DOCTYPE and HTML and HEAD and so forth. The <strong>column1.php</strong> and <strong>column2.php</strong> files simply create variations on how the page-specific content gets rendered. These files do so by hijacking the layout process. For example, here is the entirety of <strong>column1.php</strong>:</p><pre class="brush: php; title: ; notranslate">&lt;!--?php $this---&gt;beginContent('//layouts/main'); ?&gt;&lt;/pre&gt;
&lt;div id=&quot;content&quot;&gt;&lt;/div&gt;
&lt;pre&gt;
&lt;!-- content --&gt;
&lt;!--?php $this---&gt;endContent(); ?&gt;</pre><p>Again, you have the magic <strong>echo $content </strong>line there, but all <strong>column1.php</strong> does is wrap the page-specific content in a DIV.</p><p>The <strong>column2.php</strong> file starts off the same, but adds another DIV (which includes some widgets) before <strong>$this-&gt;endContent()</strong>:</p><pre class="brush: php; title: ; notranslate">&lt;!--?php $this---&gt;beginContent('//layouts/main'); ?&gt;&lt;/pre&gt;
&lt;div class=&quot;span-19&quot;&gt;
&lt;div id=&quot;content&quot;&gt;&lt;/div&gt;
&lt;!-- content --&gt;&lt;/div&gt;
&lt;div class=&quot;span-5 last&quot;&gt;
&lt;div id=&quot;sidebar&quot;&gt;&lt;!--?php  $this---&gt;beginWidget('zii.widgets.CPortlet', array(
 'title'=&gt;'Operations',
 ));
 $this-&gt;widget('zii.widgets.CMenu', array(
 'items'=&gt;$this-&gt;menu,
 'htmlOptions'=&gt;array('class'=&gt;'operations'),
 ));
 $this-&gt;endWidget();
 ?&gt;&lt;/div&gt;
&lt;!-- sidebar --&gt;&lt;/div&gt;
&lt;pre&gt;
&lt;!--?php $this---&gt;endContent(); ?&gt;</pre><p>The trick here is the call to <strong>beginContent()</strong>. Remember how the layout file echoes the page-specific content in the correct place? Well, this call to <strong>beginContent()</strong> says that we&#8217;re about to start rendering the content. The method is provided with the primary layout file to use as the parent (i.e., the layout that encapsulates this content). All that&#8217;s happened here is that the content has been hijacked and replaced with slightly modified content. So the content in <strong>views/site/login.php</strong> gets pulled into <strong>column.php</strong>, where it&#8217;s wrapped within other content, and the combination of that content gets passed to <strong>main.php</strong>.</p><p>There are two tricks to this: first, <strong>beginContent()</strong> must point to <strong>//layouts/main.php</strong>. (The // just says to start in the Views directory.) Second, the layout that the Controller thinks it&#8217;s using is <strong>column1.php</strong>, not <strong>main.php</strong>. I personally think this approach is a bit complicated, particularly for the Yii newbie (yiibie?), but it is useful in situations where the content around the page-specific content needs to be adjusted dynamically.</p><p>If you were to open <strong>components/Controller.php</strong>, you would see this line:</p><pre class="brush: php; title: ; notranslate">public $layout='//layouts/column1';</pre><p>That one line says that all Controllers (which inherit from <strong>Controller</strong>) will use <strong>column1.php</strong> as its layout. If you were to change this one line to <em>column2</em>, then all Controllers would use that as the default layout. If you were to change this one line to <em>main</em>, then all Controllers would use <strong>main.php</strong> as the default layout, without the intermediary column layouts.</p><p>Again, this is a bit more convoluted than is healthy for newbies, but layouts are just wrappers to page-specific content, whether you use a single layout or intermediary layouts such as column1 and column2. If you&#8217;d like a visual representation, there&#8217;s a useful image provided among the <a
href="http://www.yiiframework.com/wiki/249/understanding-the-view-rendering-flow/#comments">comments in this article</a>.</p><h2>Quick Guide</h2><p>To summarize what&#8217;s been covered here&#8230;</p><p>To change the entire look for the entire site, edit <strong>layouts/main.php</strong>, but be sure to use the <strong>echo $content</strong> line where appropriate.</p><p>To change the default layout for every Controller, edit this line in <strong>components/Controller.php</strong>:</p><pre class="brush: php; title: ; notranslate">public $layout='//layouts/column1';</pre><p>To change the default layout for every View in an individual Controller, add this line to that Controller&#8217;s definition:</p><pre class="brush: php; title: ; notranslate">class SiteController extends Controller {
public $layout = 'column2';</pre><p>To change the layout used for a single action, add this line to the corresponding action:</p><pre class="brush: php; title: ; notranslate">// protected/controllers/SiteController.php
public function actionIndex() {
    $this-&gt;layout = 'home';</pre><p>And remember that <strong>column1.php</strong> and <strong>column2.php</strong> just hijack the page-specific content before it gets passed on to the <strong>main.php</strong> layout file.</p><p>I hope this post has been helpful and let me know if you have any questions or problems with layouts in Yii. (And by the way, if you like this post, I&#8217;m going to be writing a book on Yii later this summer. Subscribe to my newsletter or follow me on Twitter to stay tuned!)</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/05/16/working-with-layouts-in-yii/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>What Is Larry Thinking? #54 =&gt; Salt, Pepper, 99designs, and Ajax</title><link>http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/</link> <comments>http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#comments</comments> <pubDate>Mon, 30 Apr 2012 11:00:06 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Ruby]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[99designs]]></category> <category><![CDATA[ajax]]></category> <category><![CDATA[newsletter]]></category> <category><![CDATA[phpvqp3]]></category> <category><![CDATA[security]]></category> <category><![CDATA[travel]]></category> <category><![CDATA[yii]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3190</guid> <description><![CDATA[In this edition… About This Newsletter On the Web? =&#62; Properly Salting Passwords, The Case Against Pepper On the Road =&#62; Istanbul and Silicon Valley On the Blog =&#62; My New Logo and Business Card from 99designs On the Blog =&#62; Five Ways to Lose Work On the Blog =&#62; Yii and Me (aka, the [...]]]></description> <content:encoded><![CDATA[<p> In this edition…</p><ul><li><a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#about">About This Newsletter</a></li><li><a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#web">On the Web? =&gt; Properly Salting Passwords, The Case Against Pepper</a></li><li><a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#road">On the Road =&gt; Istanbul and Silicon Valley</a></li><li><a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#blog1">On the Blog =&gt; My New Logo and Business Card from 99designs</a></li><li><a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#blog2">On the Blog =&gt; Five Ways to Lose Work</a></li><li><a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#blog3">On the Blog =&gt; Yii and Me (aka, the Yii Book)</a></li><li><a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#qa1">Q&amp;A =&gt; How Do I Make Ajax Content Available to Search Engines</a></li><li><a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#qa2">Q&amp;A =&gt; Can You Use .html Instead of .php?</a></li><li><a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#news">Larry Ullman&#8217;s Book News => &#8220;PHP 5 Advanced: Visual QuickPro Guide&#8221; (3rd Edition)</a></li></ul><p> <span
id="more-3190"></span></p><h2 id="about">About This Newsletter</h2><p>To repeat what I&#8217;ve said in the past two newsletters, I am now officially on <a
href="http://twitter.com">Twitter</a>. Hopefully next month, I&#8217;ll get the Twitter &#8220;follow me&#8221; link on my main site and add it to this newsletter template. But in the meantime, you can follow me using <a
href="https://twitter.com/#!/LarryUllman">@LarryUllman</a>. I&#8217;m doing better about sending out tweets, and I do retweet things that I think are notable or useful. In fact, I sent out a tweet a couple of days ago asking for good newsletter questions, and I received a few, one of which I answer here. Even an old dog can learn a new trick, I guess.</p><p>Also, I would love to have more questions to answer in forthcoming newsletters. I tend to get the most questions when I do a book giveaway, and I haven&#8217;t had one of those in a while, so the well is running a bit dry.</p><p>As always, questions, comments, and all feedback are much appreciated. And thanks for your interest in what I have to say and do!</p><h2 id="web">On the Web => Properly Salting Passwords, The Case Against Pepper</h2><p>Anthony Ferrara, creator of the PHP <a
href="https://github.com/ircmaxell/PHP-PasswordLib">PasswordLib</a> library,&nbsp;just recently <a
href="http://blog.ircmaxell.com/2012/04/properly-salting-passwords-case-against.html">posted a discussion of using salts and pepper</a> to improve the security of a stored password. Mostly, the article is a discussion of why a pepper is unnecessary (and if you don&#8217;t know what a &#8220;pepper&#8221; is, just read the article), but the posting also does a good job of explaining the purpose of a salt, and why the salt does not need to be a secret. The posting is relatively short, and is something I think everyone can benefit from reading.</p><p>The posting ends with the most important security fact:</p><blockquote><p>Remember, the most dangerous kind of security is a false sense of it. Thinking you&#8217;ve made your application more secure, when in fact you&#8217;ve weakened it, is the worst thing you could possibly do.</p></blockquote><h2 id="road">On the Road => Istanbul and Silicon Valley</h2><p>For the first time in a long time, I&#8217;m going to do some work-related traveling. I used to travel somewhat regularly for conferences and training seminars and the like. But then I had kids and other personal issues came up, so I cut back. I <em>think</em> the last time I travelled for work was when I spoke at a Voices That Matter conference in Nashville, TN in 2008!</p><p>My first trip is to Istanbul, Turkey, at the end of May. I&#8217;ll be speaking at the <a
href="http://e-commerceexpo.com/">E-commerce Expo</a> on May 30th (the site is in Turkish, so you&#8217;ll want to use a browser like Chrome that will translate the page for you). I will have about two other days to see what I can of the city, so if anyone has any recommendations of what to see and do, or where to eat, please let me know. I&#8217;ve heard nothing but great things about Istanbul and am really looking forward to it. Oh, and my speech—<strong>Building a Successful E-commerce Venture, or Failing Gracefully</strong>—should be good, too.</p><p>At the end of June, I&#8217;ll be doing two days of training on JavaScript and jQuery at the Mid-Pacific ICT Center Summer 2012 Faculty Development Week in Fremont, California. I&#8217;m tentatively thinking about making myself available for drinks or dinner on Thursday, June 28th, although I haven&#8217;t thought it through, yet. If you&#8217;re in the area and think you&#8217;d like to meet, let me know and I&#8217;ll see what makes sense from there. Thanks!</p><h2 id="blog1">On the Blog => My New Logo and Business Card from 99designs</h2><p>In March, I finally got around to having a new logo and business card created, using <a
href="http://99designs.com">99designs</a>. It wasn&#8217;t a driving need for me, but it was about time. I wrote about <a
href="http://www.larryullman.com/2012/04/18/my-99designs-logo-and-business-card-contest/">the contest experience</a> in one blog post. In another blog post, I show <a
href="http://www.larryullman.com/2012/04/16/my-new-logo-and-business-card/">the end results</a>, and also some of the terrible logos and business cards I&#8217;ve had along the way (i.e., the ones I designed).</p><p>I&#8217;ve since hired a designer to modify my CSS to use the new logo and colors. This is going to go with a new WordPress theme, which I&#8217;m hoping to get online in May. Hoping. After that I&#8217;ll also update this newsletter template.</p><h2 id="blog2">On the Blog => Five Ways to Lose Work</h2><p>In <a
href="http://www.larryullman.com/2012/04/02/what-is-larry-thinking-53-writing-and-working/#thinking">the previous newsletter</a>, I wrote about competing for work. Getting work is a frequent topic of conversation I have with readers, and between that question, and my recent experiences with 99designs, I wrote a blog post titled &#8220;<a
href="http://www.larryullman.com/2012/04/11/five-ways-to-lose-work/">Five Ways to Lose Work</a>&#8221;. Although some of the examples in that post come from my 99designs experience, it&#8217;s not really about 99designs, but more about the common mistakes people make when trying to get a project. My intent is that by recognizing these mistakes, you&#8217;ll be less likely to make them, and therefore have a better chance of getting work.</p><h2 id="blog3">On the Blog => Yii and Me (aka, the Yii Book)</h2><p>Many people have appreciated my <a
href="http://www.larryullman.com/series/learning-the-yii-framework/">Learning the Yii Framework</a> series and are awaiting a formal Yii book written by me. This is something I have been hoping to do for sometime. It looks like that time will be the latter half of 2012. Almost definitely. In <a
href="http://www.larryullman.com/2012/04/23/yii-and-me-aka-the-yii-book/">a recent blog post</a>, I announced my current plans and thinking about the book. I was also very pleased to say that Qiang Xue, the creator of Yii, has generously agreed to act as the technical editor for the book. Now it&#8217;s just a matter of writing it!</p><h2 id="qa1">Q&amp;A => How Do I Make Ajax Content Available to Search Engines?</h2><p>I&#8217;m digging way through the archives to find questions to answer, and I came across this one sent in by Richard back in October of 2008. It&#8217;s probably way too late to help Richard, but perhaps my answer can be of use to others. Here&#8217;s the prompt (summarized by me):</p><blockquote><p>I have a discussion board that pulls posts via Ajax, which means that posts aren&#8217;t being indexed by search engines. I updated the system so that all posts are displayed by PHP, to make them search engine visible, and then use Ajax for new posts since the user got online, but are there other places where Ajax presents this sort of problem?</p></blockquote><p>This brings up a very good point that every Web developer ought to be aware of. It&#8217;s obvious that if someone disables JavaScript, they can&#8217;t see the JavaScript functionality on a site. Statistically, only around 1-3% of all <em>users</em> have JavaScript disabled. However, <en>all search engine bots</en> are unable to see JavaScript-derived content. This means that all content on your site that&#8217;s created by JavaScript will not appear in search engines. This is especially ironic as many sites use JavaScript for the most important content. So what&#8217;s the solution?</p><p>The solution is actually the same solution for all JavaScript-based sites. Unless the site absolutely has to require JavaScript, you should always start with a non-JavaScript version first. A non-JavaScript version will be accessible by all search engines and by, well, anyone. The non-JavaScript version may not be pretty or cool, but it will be functional, which is most important. Then you can add the JavaScript layer to implement the cool, or more interactive, version. This process is called &#8220;progressive enhancement&#8221; and is a cornerstone of modern JavaScript, as explained in my &#8220;<a
href="http://www.larryullman.com/books/modern-javascript-develop-and-design/">Modern JavaScript: Develop and Design</a>&#8221; book.</p><p>If, for whatever reason, you don&#8217;t want to take this approach, then simply create alternative versions of your content that would be available for search engines. This could be as simple as a site map that links to non-dynamic versions of the content.</p><h2 id="qa2">Q&amp;A => Can You Use .html Instead of .php?</h2><p>This question came in from @enxaneta_info via Twitter:</p><blockquote><p>Is it possible to replace the <strong>.php</strong> extension with <strong>.html</strong>?</p></blockquote><p>The short answer is yes. A file&#8217;s extension just tells the computer what application should be used to execute that file. With Web files, the extension tells the Web server how to treat that file. Normally, the <strong>.php</strong> extension indicates that the code therein should be run through the PHP module. If you wanted to use <strong>.html</strong>, you&#8217;d just need to tell the Web server to send all files with a <strong>.html</strong> extension through the PHP module. (This is done via an AddType directive in the Apache configuration file.)</p><p>One benefit of doing this is that it allows you to hide what type of server-side tool is being used. On the other hand, there is certain to be a performance hit as the Web server will send every page through the PHP module. But if you have a site that only contains PHP scripts and has no HTML files, this is a reasonable change to make.</p><h2 id="news">Larry Ullman&#8217;s Book News => &#8220;PHP 5 Advanced: Visual QuickPro Guide&#8221; (3rd Edition)</h2><p>I&#8217;ve formally started writing the third edition of my &#8220;<a
href="http://www.larryullman.com/books/php-5-advanced-visual-quickpro-guide-2nd-edition/">PHP 5 Advanced: Visual QuickPro Guide</a>&#8221; book. You can view the initial <a
href="http://www.larryullman.com/2012/04/09/php-5-advanced-visual-quickpro-guide-3rd-edition-table-of-contents/">Table of Contents</a> on my Web site, along with some discussion of my approach to this edition. The new edition is tentatively titled &#8220;Advanced PHP and Object-Oriented Programming: Visual QuickPro Guide&#8221;, to better reflect the book&#8217;s focus.</p><p>If you have any thoughts on the book&#8217;s table of contents, please share them on that blog posting page. As I said, I&#8217;m writing the book now, and it will be my primary focus for the next two months. Ideally the first submitted draft will be completed by the end of May (although that will be a stretch), and the book will come out by the end of summer.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>Yii and Me (aka, the Yii Book)</title><link>http://www.larryullman.com/2012/04/23/yii-and-me-aka-the-yii-book/</link> <comments>http://www.larryullman.com/2012/04/23/yii-and-me-aka-the-yii-book/#comments</comments> <pubDate>Mon, 23 Apr 2012 11:18:49 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[book]]></category> <category><![CDATA[yii]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3187</guid> <description><![CDATA[Thanks largely to the success of my Learning the Yii Framework series, people are often asking me about my plans to write a book on Yii. Writing a book on Yii is something that I&#8217;ve been meaning to do for some time, but have been way too busy for the past couple of years to [...]]]></description> <content:encoded><![CDATA[<p>Thanks largely to the success of my <a
href="http://www.larryullman.com/series/learning-the-yii-framework/">Learning the Yii Framework</a> series, people are often asking me about my plans to write a book on <a
href="http://www.yiiframework.com">Yii</a>. Writing a book on Yii is something that I&#8217;ve been meaning to do for some time, but have been way too busy for the past couple of years to make it happen. Every so often I post something about the phantom Yii book, and so here&#8217;s another. This time, it&#8217;s pretty good news&#8230;</p><p>As for my schedule, I&#8217;m now writing the third edition of my &#8220;<a
href="http://www.larryullman.com/2012/04/09/php-5-advanced-visual-quickpro-guide-3rd-edition-table-of-contents/">PHP 5 Advanced: Visual QuickPro Guide</a>&#8221; book. That project will take the next couple of months, through June. I&#8217;m hoping it will be entirely done (rewrites and all) in early July. I think I&#8217;ll have a decent-sized Web project to do in the fall, but other than that, I have no deadlines and obligations for the latter half of 2012. Little things will no doubt come along, but this kind of free time is unusual for me. (And, strangely, isn&#8217;t frightening at the moment, although free time come January could be a problem!) So, reasonably speaking, I will be able to work on the Yii book full time as of August 2012. This should coincide nicely with the hopeful release of Yii 2.0 over the summer. Speaking of which&#8230;</p><p>I&#8217;ve been chatting with Qiang Xue, the creator of Yii, and he has graciously offered to act as the personal tech editor for the book. This is a great honor to me, and will be a wonderful asset in making sure the book is as technically accurate as possible. In return, I&#8217;m going to help with some of the official Yii documentation (it&#8217;s the least I can do). And the good news keeps rolling in, as <a
href="http://rmcreative.ru/">Alex Makarov</a>, author of the popular <a
href="http://yiicookbook.org/">Yii 1.1 Application Development Cookbook</a> (Packt Publishing), has generously offered his assistance, too. These are invaluable pieces that are coming together nicely here.</p><p>In terms of publishing, my current plan is&#8230;</p><ul><li>To self-publish an ebook only. I will release it in mobi, epub, and PDF formats, without any annoying Digital Rights Management (DRM).</li><li>Possibly no DRM.</li><li>Probably no DRM.</li><li>The price would be about $15 (USD).</li><li>People would be able to buy the book in advance, and get each chapter as I write it. Revised chapters would be free updates.</li><li>People would be able to buy just a single chapter and get revisions of that chapter as free updates.</li></ul><p>I&#8217;m assuming that I&#8217;ll create a separate Web site for the book, as I&#8217;m also planning on making some of the book&#8217;s content freely available in HTML format. This does mean that along with writing the book, I&#8217;ll have to create the Web site and the above functionality, but such are the costs of doing things yourself. And I happen to know of a framework that makes Web development a lot faster&#8230;</p><p>I&#8217;ll continue posting updates here and on <a
href="http://www.twitter.com">Twitter</a> (by the way, I&#8217;m on Twitter <a
href="https://twitter.com/#!/LarryUllman">@LarryUllman</a>) as I have them. Yii postings may be sporadic for the next couple of months as I focus on the PHP Advanced book, but rest assured the Yii book is happening.</p><p>All thoughts, feedback, input, and offers of money are most welcome!</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/04/23/yii-and-me-aka-the-yii-book/feed/</wfw:commentRss> <slash:comments>40</slash:comments> </item> <item><title>Under the Hood of Yii&#8217;s Component Architecture</title><link>http://www.larryullman.com/2012/03/16/under-the-hood-of-yiis-component-architecture/</link> <comments>http://www.larryullman.com/2012/03/16/under-the-hood-of-yiis-component-architecture/#comments</comments> <pubDate>Fri, 16 Mar 2012 14:13:51 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[mvc]]></category> <category><![CDATA[yii]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3055</guid> <description><![CDATA[If you haven&#8217;t yet seen it, Steven O&#8217;Brien wrote an in-depth series of articles on the Yii framework&#8217;s component architecture, posted at phpmaster. In the series, O&#8217;Brien looks at the CComponent base class in detail. Every class in Yii is an extension of CComponent, so understanding what it brings to the table can be quite [...]]]></description> <content:encoded><![CDATA[<p>If you haven&#8217;t yet seen it, <a
href="http://steve-obrien.com/">Steven O&#8217;Brien</a> wrote an in-depth series of articles on the Yii framework&#8217;s component architecture, posted at <a
href="http://phpmaster.com">phpmaster</a>. In the series, O&#8217;Brien looks at the <a
href="http://www.yiiframework.com/doc/api/1.1/CComponent">CComponent</a> base class in detail. Every class in Yii is an extension of <strong>CComponent</strong>, so understanding what it brings to the table can be quite useful to the Yii developer. <a
href="http://phpmaster.com/yii-under-the-hood-1/">Part 1</a> looks at the classes key properties and methods. <a
href="http://phpmaster.com/yii-under-the-hood-2/">Part 2</a> discusses events. And <a
href="http://phpmaster.com/under-the-hood-of-yii’s-component-architecture-part-3/">part 3</a> explains the behaviors. If you&#8217;re using Yii, it&#8217;s worth reading these to better understand what&#8217;s going on at the fundamental level.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/03/16/under-the-hood-of-yiis-component-architecture/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>My January 2012 Non-Resolutions List</title><link>http://www.larryullman.com/2012/01/03/my-january-2012-non-resolutions-list/</link> <comments>http://www.larryullman.com/2012/01/03/my-january-2012-non-resolutions-list/#comments</comments> <pubDate>Wed, 04 Jan 2012 04:12:41 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[Uncategorized]]></category> <category><![CDATA[book]]></category> <category><![CDATA[phpvqp3]]></category> <category><![CDATA[textmate]]></category> <category><![CDATA[writing]]></category> <category><![CDATA[yii]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2947</guid> <description><![CDATA[I&#8217;ve never been much of a New Year&#8217;s Resolution person: if something is important enough to do, start today, not on some arbitrary date that happens to be the first day of the year. (Or, you know, January 2nd, because the first is a holiday and all.) But this year I happen to have quite [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve never been much of a New Year&#8217;s Resolution person: if something is important enough to do, start today, not on some arbitrary date that happens to be the first day of the year. (Or, you know, January 2nd, because the first is a holiday and all.) But this year I happen to have quite a long non-resolutions list. The timing is entirely coincidental: I just happen to be almost done with my <em>Modern JavaScript: Develop and Design</em> book, and I always have a long list of things to do between books. I only have two more chapters to write on this book, and the end is in site!</p><p>In a recent newsletter, I <a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#qa2">answered a question about how I spend my time between projects</a>. For me, the biggest projects I have, in terms of stress and time consumption, are the books I write. The client projects&#8211;Web development and such, no matter how big or complicated, never seem to be that much of a burden. Mostly this is because I find programming to be much easier than writing about programming, and because it&#8217;s fun to make things happen, to implement new concepts. Over the course of a year, I&#8217;ll work on any number of projects, ranging from consulting a couple of hours here or there (i.e., helping to steer the actual developers) to doing all of the development myself. When these bigger projects are done, I&#8217;m pleased to have them off of my list, but there&#8217;s never the huge sigh of relief that I have when I&#8217;ve finished a book. And that sigh says: now I can do these other 20 things that have been waiting for me!</p><p>With the completion of the JavaScript book on the horizon, I&#8217;ve been making my January to-do list, and salivating over all the things I&#8217;ll be getting done. Certainly, what I will actually do won&#8217;t be nearly as long as this list, but one can dream, no? My next deadline isn&#8217;t until this summer, which is when I have to turn in the third edition of my <em>PHP 5 Advanced: Visual QuickPro Guide</em> book. Although I&#8217;d like to, for a change, get that book done well in advance! Still, I have a bit of time to really put a dent in my &#8220;someday&#8221; to-do list.</p><p>First on my list is to exercise more often. I feel like I&#8217;ve gained five pounds for every book I&#8217;ve written (all that sitting), and while I&#8217;ve exercised more than never over the past few months, I&#8217;d like to do much, much better. We could all probably use more exercise!</p><p>After exercise, which is a daily and on-going goal, I&#8217;ve grouped my dream tasks into four categories:</p><ul><li>Things to work on</li><li>Books to read</li><li>Work things I really should get done</li><li>Personal things I really should get done</li></ul><p>The last category is of little interest to you, I imagine, or wouldn&#8217;t mean much regardless (mostly construction projects around the house). The work things I really should get done are those things that don&#8217;t get done during my books and big projects. For January, this primarily means creating an HTML5 version of this site&#8217;s design, plus a corresponding version for my forum. Before I redid this site in October of 2010, the site had become woefully outdated and I want to insure that doesn&#8217;t happen again. If time allows, I&#8217;ll do a mobile version, too, and make sure everything is performing as well as can be.</p><p>The books to read are both personal and work related. I want to read one or two parenting books, a novel, and some work-related books. I&#8217;m specifically looking to read <em><a
href="http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X/ref=sr_1_1?s=books&amp;ie=UTF8&amp;qid=1325649567&amp;sr=1-1">The Pragmatic Programmer</a></em> by Hunt and Thomas first. I&#8217;ve heard good things about it. Then, coincidentally, I have a couple of ebooks from <a
href="http://pragprog.com/">The Pragmatic Bookshelf</a> on my computer awaiting a few moments of time. As I read these, I&#8217;ll no doubt be posting my thoughts about them here.</p><p>Finally, there&#8217;s my &#8220;things to work on&#8221; category, which is a broad category of topics without definitive targets or concrete tasks. Normally these items are a matter of improving my skills in specific areas. Right now I&#8217;m thinking honing my abilities and knowledge with respect to <a
href="http://www.obdev.at/products/launchbar/index.html">Launchbar</a> and <a
href="http://macromates.com/">TextMate</a>, two Mac apps I use all the time. I know for a fact that I&#8217;m underutilizing both. The time I spend improving my skills with them now will pay dividends over the rest of the year. As time allows, I also plan on continuing to write my Yii book, although I&#8217;ll probably do that as blog posts, too.</p><p>So there are my January 2012 non-resolutions. Which will likely also be my February 2012 non-resolutions. Sadly, at least a quarter of them will end up on my September 2012 resolutions, too!</p><p><strong>UPDATE</strong>: I just literally finished all the work on the <em>Modern JavaScript: Develop and Design</em> book yesterday, so thus far, I&#8217;ve done pretty much none of the things on my list, including exercise more. Ugh. But how about that February list&#8230;</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/01/03/my-january-2012-non-resolutions-list/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>What Is Larry Thinking? #47 =&gt; Random Monkey Appearances</title><link>http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/</link> <comments>http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#comments</comments> <pubDate>Mon, 21 Nov 2011 04:21:41 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[Flex]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[jsdd]]></category> <category><![CDATA[mongodb]]></category> <category><![CDATA[newsletter]]></category> <category><![CDATA[nosql]]></category> <category><![CDATA[phpmysql4]]></category> <category><![CDATA[yii]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2869</guid> <description><![CDATA[In this edition… About This Newsletter What Were You Thinking? =&#62; Using JavaScript On the Web =&#62; Introduction to MongoDB On the Web =&#62; The Protocol-Relative URL On the Web =&#62; 10 Steps to Becoming a Great Web Developer On the Blog =&#62; My Yii Book Update On the Blog =&#62; Adobe&#8217;s Significant Flash and [...]]]></description> <content:encoded><![CDATA[<p>In this edition…</p><ul><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#about">About This Newsletter</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#you">What Were You Thinking? =&gt; Using JavaScript</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#web1">On the Web =&gt; Introduction to MongoDB</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#web2">On the Web =&gt; The Protocol-Relative URL</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#web3">On the Web =&gt; 10 Steps to Becoming a Great Web Developer</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#blog1">On the Blog =&gt; My Yii Book Update</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#blog2">On the Blog =&gt; Adobe&#8217;s Significant Flash and Flex Changes</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#qa1">Q&amp;A =&gt; How Do You Choose Between Competing Technologies?</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#qa2">Q&amp;A =&gt; How Do You Spend Time Between Projects?</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#thinking">What is Larry Thinking =&gt; Starting a New Project</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#giveaway">Book Giveaway =&gt; “PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide” (4th Edition)</a></li><li><a
href="http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/#news">Larry Ullman&#8217;s Book News =&gt; “Modern JavaScript: Develop and Design”</a></li></ul><p><span
id="more-2869"></span></p><h2 id="about">About This Newsletter</h2><p>Hello, hello. Not a very cohesive theme in this newsletter, but in it, I write about: Web development technologies, how to start new projects, and how to spend one’s downtime. Oh, and there’s one of those bookgiveawaythingies that y’all like so much!</p><p>As always, questions, comments, and all feedback are much appreciated. And thanks for your interest in what I have to say and do!</p><h2 id="you">What Were You Thinking? =&gt; Using JavaScript</h2><p>In <a
href="http://www.larryullman.com/2011/10/21/what-is-larry-thinking-46-javascript-sexism-and-bad-user-interface/#you">my previous newsletter</a>, I asked for input as to how <em>you</em> use JavaScript, what you know you’re confused by, what you’d like to learn more about, and so forth. I received oodles of replies, which were very much appreciated. I haven’t responded to quite everyone yet, but do plan to still. And all respondents are going into a pool of candidates for a free copy of the book when I have my copies to give away (that looks like February now, or thereabouts).</p><p>The bulk of the responses emphasized that I just need to do what I do normally, but this time for JavaScript. In other words, there’s a certain way that I go about presenting technical information that seems to work for many people, and I need to be true to those inclinations. That’s quite flattering and reassuring, as I often second-guess myself when writing new books. It’s also a good reminder not to over extend myself or the book, and as I do the rewrites I’ll be certain to adjust accordingly.</p><p>I remember that when I first started writing computer books, I looked at the books that were out there, and many writers seem to want to impress the reader with what she or he (i.e., the writer) knows. Maybe wasn’t the intent, and maybe other writers just have a broader sense of what readers need to know than I do. In any case, my belief has always been that <em>a technical book isn’t about what I know but about what you, the reader, needs to know</em>. Further, it’s not my aim to impress you with my knowledge, but for you to be impressed by what you’ve managed to learn and do. So, as I finish the JavaScript book and perform the rewrites, this is a good reminder for me to keep the content simple (-ish), straightforward, and, above all, useful. When I question if some tip or sidebar is too advanced or unnecessary, that’s probably an indicator that it is.</p><p>A good idea that came up a couple of times is to demonstrate and discuss key JavaScript libraries. The book will already introduce some frameworks, but I think libraries merit coverage, too. I’m also now debating doing a chapter on mobile JavaScript. I’m leaning towards doing one, but am pressed for time.</p><p>Finally, a couple of people have volunteered to act as proofreaders on the book. The offer is much appreciated, and something I would have definitely taken advantage of if I was self-publishing. However, as this book is going through a traditional publisher, there are already several proofreaders involved. Adding more proofreaders might help catch a thing or two, but would further overwhelm me (it takes a lot of work to assign chapters, read feedback, and so forth) and I’m already so very behind. But I thank everyone again for their offers to help.</p><p>And my thanks once again to everyone for their thoughts and feedback. If you have any more suggestions, please keep them coming!</p><h2 id="web1">On the Web =&gt; Introduction to MongoDB</h2><p><a
href="http://phpmaster.com/">phpmaster</a> recently posted an article titled <a
href="http://phpmaster.com/introduction-to-mongodb/">Introduction to MongoDB</a>. I’m not entirely sold on non-relational databases yet, in that while I can see how wonderfully beneficial they can be in many situations, they’re not as ubiquitously useful as all the hype would seem to suggest. But in any case, a good article like this one is worth the time to read. The article introduces <a
href="http://www.mongodb.org/">MongoDB</a>, shows how to install support for it in PHP (although the instructions are for Unix-like systems), and provides code for actually interacting with a MongoDB database.</p><h2 id="web2">On the Web =&gt; The Protocol-Relative URL</h2><p>Some time back, I came across this excellent nugget of information that <a
href="http://paulirish.com/">Paul Irish</a> has put forth about the <a
href="http://paulirish.com/2010/the-protocol-relative-url/">protocol-relative URL</a>. I don’t want to reveal the details here (it’s a short article, and you ought to read it), but the gist is that there’s a very simple way to link CSS, images, JavaScript, and whatever other resources so that they’ll be served over HTTP on HTTP pages and provided over HTTPS on HTTPS pages. I wish I had thought to use this when I wrote <a
href="http://www.larryullman.com/books/effortless-e-commerce-with-php-and-mysql/">my e-commerce book</a> (instead of using two different header files)! Sometimes the simple solution is the most brilliant one…</p><h2 id="web3">On the Web =&gt; 10 Steps to Becoming a Great Web Developer</h2><p>I just recently Stumbled Upon an article titled <a
href="http://komunitasweb.com/2009/10/10-steps-to-becoming-a-great-web-developer/">10 Steps to Becoming a Great Web Developer</a>. Even though the article is two years old, I think it does a great job of laying out the steps one would take to become a Web developer, starting with the basics of HTML, then moving into a server-side technology, and then getting into SQL, CSS, and JavaScript. On the higher end, there are regular expressions, Unix/Linux commands and administration, Web servers, version control, and frameworks. I would question some of the specific resources mentioned, but overall this is a nicely presented list and I can’t argue with the order. Two years later, perhaps the only thing I would add would be to start learning about mobile Web development, and a commenter on my original blog posting suggested XML and JSON, which would be good additions, too.</p><h2 id="blog1">On the Blog =&gt; My Yii Book Update</h2><p>In my blog and in these newsletters, I’ve informally mentioned my intent to write a book on the <a
href="http://www.yiiframework.com">Yii framework</a>. In theory, I would be writing it about now, but I’m very much behind on my JavaScript book so that’s not happening at the moment. I have been receiving more questions about this potential book, so I recently posted <a
href="http://www.larryullman.com/2011/11/03/my-yii-book-update/">a quick update</a> on the reasons for the book, how I plan on doing it, and when that might actually happen.</p><p>Thanks to anyone interested in that book!</p><h2 id="blog2">On the Blog =&gt; Adobe&#8217;s Significant Flash and Flex Changes</h2><p>I just <a
href="http://www.larryullman.com/2011/11/17/adobes-significant-flash-and-flex-changes/">posted the following on my blog today</a>, and thought I’d share it here since it’s so topical…</p><p>Last week, or thereabouts, Adobe announced that it was discontinuing support for Flash on mobile devices. This is, by all accounts, a wave of the white flag in Adobe’s battle against Apple and its iOS devices (if only Steve Jobs were alive today to celebrate). I didn’t think too much of that decision: it does make sense to use HTML5 or native apps for dynamic content to be run on mobile devices anyway. And Flash would still continue to run on desktops, where something like 99% of browsers have the plug-in and 90-some% of video is run through Flash. Flash is such a large component of Adobe’s various technologies that I can’t imagine Adobe leaving it behind.</p><p>And then Adobe announced today that it was offering Flex to the Apache Software Foundation (managers of the ubiquitous Apache Web server, among other projects).  Apache will need to vote on whether to accept Flex or not. This announcement does surprise me, as Flex is used not only for Flash creation, but also desktop and mobile application development via the AIR platform. Adobe says it will continue to support Flash and Flex, but clearly Adobe is moving more towards HTML5.<br
/> An interesting, and rather big, development. One does not normally think of a technology with such a large market share being outright dropped. We shall see how this plays out…</p><h2 id="qa1">Q&amp;A =&gt; How Do You Choose Between Competing Technologies?</h2><p>Richard emailed me recently, asking how I approach the situation where two competing technologies can be used for a given project. With his specific example, Richard was trying to decide between using HTML5 or Flash for an animated game. Assuming that both technologies were equally capable of performing the task, how does one make the choice? In simplest terms, Flash will provide the same experience for all users, so long as their browser supports Flash. This, unfortunately, rules out most (and as recently announce, all) mobile devices. Conversely, HTML5 will work equally well on all modern browsers, but will not work at all on older ones.</p><p>In response to Richard, I came up with two criteria for making any decision as to what technology to use for a project. First, one has to determine <em>what technologies can achieve the task</em>. Sometimes that alone makes the decision for you, when there’s only one possible solution. Considering the range of technologies and programming languages out there, this is rarely the case these days. For example, for a while, one could only develop iOS apps using Objective-C. But in most situations, there will be more than one option.</p><p>The next question is twofold then: <em>who is the target audience</em> and <em>what needs to be supported</em>? In this particular example, if the target audience is mobile users and outdated browsers don’t need to be supported, then HTML5 makes sense. If the target audience is all desktop users and mobile devices don’t need to be supported, then Flash. If everyone needs to be supported, then <em>both technologies</em> is the best solution.</p><p>With my own work, I normally aim for the broadest support over the newest thing, unless the point <em>is</em> the newest thing (e.g., you can’t make a site about HTML5 and have it be backwards compatible). I’m really not on the cutting edge of technologies, as many people are. I may be relatively on the cutting edge of <em>useful</em> technologies, but my goal is always to use the best tool, not the coolest one.</p><p>A third criteria that I failed to include in my reply to Richard, but is worth considering, is what technology you, the developer, are strongest with. Now, to be clear, this should not have a significant impact on the decision. I’ve seen people use technologies for the wrong tasks too many times, simply because that was the technology the person knew best (e.g. creating graphical desktop applications with PHP, which is possible, but not wise). My point with this criteria is that if you have two comparable choices and you’re stronger with one, then use that by all means. The project will go faster and the end result will be better.</p><h2 id="qa2">Q&amp;A =&gt; How Do You Spend Time Between Projects?</h2><p>David posed this question, asking me specifically, I believe (as opposed to asking for general advice towards this end). Being me, I’ll both answer for myself and give some advice.</p><p>When you work for yourself, the time between projects is especially important. For starters, this is time you’re not making money, so it needs to be used wisely. But if you treat the time between projects as an investment in yourself, and therefore your business, hopefully the period without money coming in will pay off in time. I don’t actually have much time off between projects, which is both a good thing (i.e., I’m busy making money) and a bad thing (I’m stressed and secondary things aren’t getting done). But when I do have downtime, at that moment, I look to the past and I look to the future.</p><p>In terms of the past, downtime between projects is when you should make sure that you’ve done everything that needs to be done but got put on the back burner while you were toiling away. This can be replying to emails, doing a little something for a client that wasn’t a priority, and updating your own Web site, LinkedIn profile, and so forth. When I overhauled my Web site a year ago, I was aghast by how out of date and unhelpful it had become. Having such public, poor representations of yourself out there is bad for business in the long run, even if only a little bit. You should have some sort of task management application, and in it you should keep a running list of “high priority someday” tasks, such as those I’ve just mentioned. Complete as many of these as you can as soon as your downtime begins, because if you don’t do it then, when will you?</p><p>In terms of the future, it’s largely a matter of improving one’s skills, whether that means learning something new or solidifying existing knowledge. In my task management application, I have a running list of topics that I’m interested in (these are non-high-priority-but-someday tasks). I take some time to investigate those during these little breaks.</p><p>Finally, I think it’s really important to recharge one’s batteries during these downtimes, whatever that may mean for you. To me, that primarily means getting away from my computer and doing something active. Part of the reason that I suspect I’m struggling in completing this JavaScript book is that I didn’t have enough (well, any) downtime between it and the previous book I wrote.</p><p>Time spent not working may seem like time spent not getting things done and not making money, but there’s a lot to be said for having some recovery time between projects. And I think, perhaps unmeasurably, such downtimes reap their own benefits in the long run.</p><h2 id="thinking">What is Larry Thinking? =&gt; Starting a New Project</h2><p>Last week, a friend came over to my house, hoping to learn about Web development. This friend has almost completed her PhD from Cornell in computer science, has taught college-level classes on programming languages, and worked at Google, too, so her technical knowledge is excellent, probably exceeding mine. She’s wanting to learn Web development, and while she has had no problems picking up the syntax and fundamentals of PHP, the big picture of Web development was eluding her. We went over a few things and, at one point, she asked how I had learned this or that. And, to be completely honest, I’ve been doing this long enough now, and my memory regarding my own development is sketchy at best, that I couldn’t answer her. But I can certainly recall that starting a big Web project, especially when you’re just beginning, is a daunting enough task as to be overwhelming, and perhaps you, too, don’t know where to begin.</p><p>Simply put, projects are a combination of <em>data</em>, <em>functionality</em>, and <em>presentation</em>. Games have a lot more of the latter two and many Web-based projects focus on the data, but those are the three elements, in varying percentages. When you go to begin a new project, it’s in one of these three areas that you must begin. And you should always start with the functionality, as that dictates everything else.</p><p>The functionality is what a Web site or application must be able to do, along with the corollary of what a user must be able to do with the Web site or application. The functionality needs to be defined in advance, and ought to be clearly stipulated in the contract (when there is one). Use a paper and pen (or note-taking application), and write down everything the project requires:</p><ul><li>Presentation of content</li><li>User registration, login, logout</li><li>Search</li><li>Rotating banner ads</li><li>Random monkey appearances</li><li>Et cetera</li></ul><p>Try your best to be exhaustive, and to perform this task without thinking of files and folders, let alone specific code. Be as detailed as you can about what the project has to be able to do, down to such things as:</p><ul><li>Show how many users are online</li><li>Cache dynamic pages for improved performance</li><li>Not use cookies or only use cookies</li><li>Have sortable tables of data</li></ul><p>The more complete and precise the list of requirements is, the better the design will be from the get-go, and you’ll need to make fewer big changes as the project progresses.</p><p>Once you’ve come up with the functionality (with the client, too, if one exists), it’s time to start coding and creating files and folders. You can start that process from one of two directions: the data or the presentation. I’m a data-first person, but let’s look at the presentation side to start.</p><p>If you’re a designer, or are working with clients that think in visual terms primarily, it makes sense to begin any new project in terms of how it will look. You may want to start with a wireframe representation, or actual HTML, but create a series of pages that provides a usable bases for how the site will appear from a user interface perspective. You don’t need to create every page, and in a dynamically-driven site you actually shouldn’t, but address the key and common components. The end goal is the HTML, CSS, and media, in a final or nearly-final state. Once you’ve done that, and the client has accepted it, you can work your way backwards through the functionality and data.</p><p>If you’re a developer, like me, incapable of thinking in graphical terms, it makes sense to begin any new project from the perspective of the data: what will be stored and how the stored information will be used. For this task, you’ll want to use a paper and pen, or a modeling tool such as the <a
href="http://www.mysql.com/products/workbench/">MySQL Workbench</a>, but the goal is to create a database schema. Always err on the side of storing too much information, and always err on the side of pure normalization (when using a relational database). Once you’ve done that, I normally populate the database with some sample data. This allows me to then create the functionality that ties the data into a sample presentation. By doing so, I, and the client, can confirm that it’s looking and working as it should. From there, you can implement more functionality, and then have the presentation finalized.</p><p>So that’s the process in a nutshell.</p><h2 id="giveaway">Book Giveaway =&gt; “PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide” (4th Edition)</h2><p><em>You must be subscribed to the newsletter to qualify for the book giveaway.</em></p><h2 id="news">Larry Ullman’s Book News =&gt; “Modern JavaScript: Develop and Design”</h2><p>I just submitted Chapter 8 of “Modern JavaScript: Develop and Design”, which means I’m about 50% done with the first draft (well, first submitted draft: there are multiple internal drafts prior to that). Progress is still going more slowly than I’d like, but… I always hope I’m about to turn a corner and speed up and one of these days, I will. In fact, I’ve got another deadline to shoot for (having blown past the original), so I will be doing everything I can to get this done ASAP. If anyone knows how to put more hours in the day, or days in the week, please let me know!</p><p>Since my last newsletter, I’ve written chapters on: arrays and objects (Chapter 6); functions (Chapter 7); and events (Chapter 8). Next is Chapter 9, on the browser (including CSS and DOM manipulation), Chapter 10, on forms, and Chapter 11, on Ajax. With the core concepts of JavaScript behind me (really, Chapters 4-7), these chapters are getting into more interesting and useful stuff. For example, two events have been used ever since Chapter 2, but now the examples can take advantage of other events. And although most of the chapters in the book thus far use an HTML form is some way, the forms chapter can now be more of a “cookbook” type chapter, explaining how to best work with specific form element types.</p><p>The third part of the book, beginning with Chapter 13, is still somewhat up in the air. There will be a chapter on frameworks, one on HTML5 and JavaScript, and another on advanced programming. Depending upon time and space, I’ll do a chapter on libraries (individual libraries, as opposed to frameworks), server-side JavaScript, and JavaScript for mobile apps.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2011/11/20/what-is-larry-thinking-47-random-monkey-appearances/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>My Yii Book Update</title><link>http://www.larryullman.com/2011/11/03/my-yii-book-update/</link> <comments>http://www.larryullman.com/2011/11/03/my-yii-book-update/#comments</comments> <pubDate>Fri, 04 Nov 2011 01:48:50 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[books]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[mvc]]></category> <category><![CDATA[yii]]></category> <category><![CDATA[yiibk]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2853</guid> <description><![CDATA[I&#8217;ve received a few comments and questions lately about my intentions to write a book on the Yii framework. I&#8217;ve never formally discussed the idea, and so it seems like it&#8217;s about time I do so. I first started using the Yii framework about two and half years ago. I&#8217;ve never been much of a framework [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve received a few comments and questions lately about my intentions to write a book on the <a
href="http://yiiframework.com/">Yii framework</a>. I&#8217;ve never formally discussed the idea, and so it seems like it&#8217;s about time I do so.</p><p>I first started using the Yii framework about two and half years ago. I&#8217;ve never been much of a framework person, but Yii really felt right to me, quite similar to <a
href="http://rubyonrails.com/">Ruby on Rails</a>, which I also always liked. Being a writer, after learning to use the framework, I wrote an <a
href="http://www.larryullman.com/series/learning-the-yii-framework/">introductory series on the subject</a>, which has been quite popular. In all modesty, many have suggested it&#8217;s the best documentation available. In fact, the creator of Yii liked my series so much that he listed it prominently on the official Yii documentation page (it&#8217;s now under <a
href="http://www.yiiframework.com/tutorials/">tutorials</a>). Some time after writing that series, I started thinking about writing a full book on Yii, because <a
href="http://www.larryullman.com/books/">that&#8217;s what I do</a>.</p><p>When I decided to write a book on Yii, I figured I&#8217;d self-publish it, for a couple of reasons. First, even though I have a wonderful relationship with <a
href="http://peachpit.com/">Peachpit Press</a>, I&#8217;m not sure they&#8217;d want to do a book on Yii, as the market is kind of small. Second, even if Peachpit would publish such a book, I doubt I&#8217;d make much money on the project, considering the small market. By comparison, if I self-publish, I can make 4-5 times per book what I&#8217;d make if I went through a publisher. The higher per copy amount could be enough to make up for the smaller sales, ending up with a project that&#8217;s financially worth my time to do (sorry to be crass about the money, but writing a book is a lot of work and I do have bills to pay!). Fourth, I&#8217;ve been intrigued about self-publishing for some time. And, fifth, self-publishing would give me the opportunity to distribute the book in unique formats and channels, such as a chapter at a time.</p><p>If I had my act together (which is to say, if my life were other than it is, in about ten ways), I would have been on the ball and published this book a year or more ago. Sadly, that has not been the case. I keep fairly busy work-wise, and I don&#8217;t actually have the time (due to personal constraints) to put in 40-hour weeks, so it&#8217;s really hard to add new projects, especially on the level of an entire book. Moreover, self-publishing means no guaranteed money, so I&#8217;d have to not do paying work while not making money working on the Yii book, which is a tough situation to be in.</p><p>All that being said, <em>it is still my intention to write and self-publish a book on Yii</em>. The only question is: when? This is the question I&#8217;m getting asked a lot lately. Before I do anything towards a book on Yii, I still have to:</p><ul><li>Finish my <em>Modern JavaScript: Develop and Design</em> book (which I&#8217;m weeks late on as is)</li><li>Write one more article in support of my <em>PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)</em> [I've written two out of three articles, but I'm weeks late on that, too.]</li><li>Come up with a list of videos to do in support of my <em>Modern JavaScript: Develop and Design</em> book</li><li>Actually do those videos</li><li>Continue doing the Web development and other work I have for my clients</li></ul><p>So&#8230;yikes. Don&#8217;t get my wrong: I&#8217;m quite fortunate to be busy, but yikes! I&#8217;ll be crying if I haven&#8217;t finished all of the above by the end of this year, which means in theory I can begin the Yii book at the beginning of 2012. However, I have the third edition of my <em>PHP 5 Advanced: Visual QuickPro Guide</em> due at the end of April. That does give me four months, but I&#8217;d like actually make that deadline for a change (my publisher is wonderfully understanding, but&#8230;).</p><p>Also, along with writing the Yii book, I&#8217;m going to have to come up with a site and an ecommerce system and so forth (I already have the software that can output PDFs, ePubs, and mobis). If I&#8217;m being optimistic, perhaps in 2012 I can do two Yii chapters per month, but the <em>PHP 5 Advanced</em> book will need to be my first priority. I also don&#8217;t want to start the Yii book, get some people paying for it (in part or in whole), and then have the project drag out. I don&#8217;t know. We shall see.</p><p>I very much thank everyone for their interest in my writing a book on Yii and I hope to make that happen. If you follow the blog and/or subscribe to my newsletter, you&#8217;ll get updates as to how this is progressing, when and if it does actually progress.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2011/11/03/my-yii-book-update/feed/</wfw:commentRss> <slash:comments>40</slash:comments> </item> <item><title>What is Larry Thinking? #42 =&gt; Doing What I Do, Part 3</title><link>http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/</link> <comments>http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/#comments</comments> <pubDate>Mon, 04 Jul 2011 21:02:19 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[Adobe AIR]]></category> <category><![CDATA[Flex]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[app]]></category> <category><![CDATA[book]]></category> <category><![CDATA[ecom]]></category> <category><![CDATA[flash builder]]></category> <category><![CDATA[mobile]]></category> <category><![CDATA[newsletter]]></category> <category><![CDATA[phpmsyql4]]></category> <category><![CDATA[phpvqs4]]></category> <category><![CDATA[stored procedures]]></category> <category><![CDATA[writing]]></category> <category><![CDATA[yii]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2674</guid> <description><![CDATA[In this edition… About This Newsletter What Were You Thinking? =&#62; The JavaScript Book On the Web =&#62; Flash Builder 4.5/Flex 4.5 for Mobile Apps On the Blog =&#62; Cookies and Sessions in Yii On the Forum =&#62; FALSE Comparisons in PHP Q&#38;A =&#62; Could You Say More About Stored Procedures? What is Larry Thinking [...]]]></description> <content:encoded><![CDATA[<p>In this edition…</p><ul><li><a
href="http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/#about">About This Newsletter</a></li><li><a
href="http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/#you">What Were You Thinking? =&gt; The JavaScript Book</a></li><li><a
href="http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/#web">On the Web =&gt; Flash Builder 4.5/Flex 4.5 for Mobile Apps</a></li><li><a
href="http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/#blog">On the Blog =&gt; Cookies and Sessions in Yii</a></li><li><a
href="http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/#forum">On the Forum =&gt; FALSE Comparisons in PHP</a></li><li><a
href="http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/#qa">Q&amp;A =&gt; Could You Say More About Stored Procedures?</a></li><li><a
href="http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/#thinking">What is Larry Thinking =&gt; Doing What I Do: Web Development</a></li><li><a
href="http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/#news">Larry Ullman&#8217;s Book News =&gt; &#8220;PHP and MySQL for Dynamic Web Sites&#8221; (4th Edition) and &#8220;Modern JavaScript: Develop and Design&#8221;</a></li></ul><p><span
id="more-2674"></span></p><h2 id="about">About This Newsletter</h2><p>Another three weeks(-ish), another newsletter! It may only matter to me, but I&#8217;m happy to say that since I started using <a
href="http://www.literatureandlatte.com/scrivener.php">Scrivener</a> to write this newsletter (in late 2010), I&#8217;ve done a much better job in getting these out regularly. Although, since they only go out once a month, or slightly better, it may always seem to you that the newsletters come from out of the blue. Anyway&#8230;in this newsletter I present a random collection of stuff, including the conclusion of my on-going series on building a career in IT. In my next newsletter, I plan on speaking, briefly, about quantum computing, having recently read a <em>fascinating</em> article on the subject.</p><p>As always, questions, comments, and all feedback are much appreciated. And thanks for your interest in what I have to say and do!</p><h2 id="you">What Were You Thinking? =&gt; The JavaScript Book</h2><p>In the previous newsletter, I <a
href="http://www.larryullman.com/2011/06/09/what-is-larry-thinking-41-doing-what-i-do-part-2/#you">posted a question</a> about whether it matters to you if I self-publish my intended JavaScript book or if I use a traditional publisher. I also asked the general question as to what readers look for in a book, beyond the content and perhaps writer. There was an excellent response and I thank everyone for their thoughts.</p><p>The bottom line was that most people don&#8217;t care about the publisher. Some people specifically like, say, O&#8217;Reilly books or the Visual Quick* Series, but many don&#8217;t pay much attention to the publisher (I&#8217;ve always suspected that many readers don&#8217;t pay much attention to who the writer is either). The strongest feedback was just for it being made available in specific formats—PDF, print, what-have-you, and that it be of good quality.</p><p>It was also nice, and quite flattering, to hear many people express their interest in purchasing the book, regardless of whether I self-publish or use a traditional publisher. I am, indeed, fortunate to have the readership that I do.</p><p>Thanks again to everyone that responded and to those of you interested in this book. The actual decision regarding this JavaScript book can be found in the &#8220;Larry Ullman&#8217;s Book News&#8221; section at the end of this newsletter (this is called &#8220;burying the lead&#8221;!).</p><h2 id="web">On the Web =&gt; Flash Builder 4.5/Flex 4.5 for Mobile Apps</h2><p>Version 4.5 of both the Flex framework and the Flash Builder IDE just came out and the outlook is very exciting. As announced some time ago, the focus in Flex 4.5 is on developing for mobile apps. This means a new wave of components optimized for mobile platforms. That alone might sound &#8220;kind of cool&#8221;, but this release is much, much bigger than that.</p><p>Instead of using Flex to write Flash content that runs in a Web browser in a mobile device (but not on Apple devices), thanks to <a
href="http://www.adobe.com/go/air/">Adobe AIR 2.6</a>, <em>you&#8217;ll be able to write true mobile apps in Flex</em>. With the initial release, you&#8217;re able to create apps for the Google Android platform (the largest platform, in terms of sales of mobile devices today). Version 4.5.1 was just released, which adds support for iOS (iPod Touch, iPhone, and iPad) devices and the Blackberry Tablet OS. To summarize:</p><blockquote><p>If you know Flex, you can create mobile applications that run on all major mobile platforms in no time at all!</p></blockquote><p>This could not come at a better time for me. I have a couple of mobile app ideas that I want to develop and was planning on learning how to do so later this year (yes, yes, I&#8217;m totally on the cutting edge of the mobile app craze, eh?). I was still hemming and hawing over whether to pursue the iOS route, which would be natural for me (I primarily use Macs and am comfortable with the C family of languages), or go the Google Android route, which would be harder (Java is the default language there), but technically has a broader market. And now, thanks to Flex 4.5 and Adobe AIR, I won&#8217;t have to choose between them.</p><p>To see the development process, and the output, in action, check out <a
href="http://tv.adobe.com/watch/adobe-technology-sneaks-2011/sneak-peek-of-mobile-application-development-with-flex-and-flash-builder/">this sneak peek video at Adobe</a>. There&#8217;s also <a
href="http://www.adobe.com/devnet/flex/articles/mobile-development-flex-flashbuilder.html">this pretty good article</a> on mobile development using Flex and Flash Builder. It&#8217;s a very impressive concept and, as far as I know, the only &#8220;write once, run everywhere&#8221; development solution for mobile apps. This, of course, is the promise of Adobe AIR itself, which allows you to write one application that can run on multiple operating systems (I still seem to be a bigger fan of AIR than the world at large).</p><h2 id="blog">On the Blog =&gt; Cookies and Sessions in Yii</h2><p>In my ever-ongoing series on the <a
href="http://www.yiiframework.com">Yii framework</a>, I&#8217;ve recently written two postings on managing state using the framework. The <a
href="http://www.larryullman.com/2011/05/03/using-sessions-with-the-yii-framework/">first is on sessions</a>; the <a
href="http://www.larryullman.com/2011/06/04/using-cookies-in-the-yii-framework/">second on cookies</a>. Neither is particularly difficult to do using Yii, once you know the right code, of course. With cookies, Yii has built-in extra security measures you can take, for example, to help prevent Cross-Site Request Forgery (CSRF) attacks.</p><h2 id="forum">On the Forum =&gt; FALSE Comparisons in PHP</h2><p>I&#8217;m hoping that you&#8217;ll take this as a comfort, but you should be aware that we all, no matter how long we&#8217;ve been programming, are capable of creating bugs when programming. Through the <a
href="http://www.larryullman.com/forums/index.php?/topic/301-problems-with-ecommerce-example-2-demo-site/">keen testing of a reader</a>, a bug was caught in the second example site from my &#8220;<a
href="http://www.larryullman.com/books/effortless-e-commerce-with-php-and-mysql/">Effortless E-Commerce with PHP and MySQL</a>&#8221; book. It&#8217;s a common enough mistake that I should have caught it myself and yet&#8230; You can read my formal explanation regarding the specific code <a
href="http://www.larryullman.com/forums/index.php?/topic/301-problems-with-ecommerce-example-2-demo-site/page__pid__2163#entry2163">in the forum</a>, but the premise is this:</p><p>Say you have the conditional <code>if ($var) {</code>. That conditional will be TRUE so long as <strong>$var</strong> has a TRUE value. But what is a TRUE value? It&#8217;s easiest to understand what a TRUE value is by knowing what a FALSE value is. These are all FALSE values:</p><ul><li>FALSE (case-insensitive)</li><li>NULL</li><li>(No actual value)</li><li>&#8220;&#8221; (An empty string)</li><li>0</li><li>0.0</li><li>‘0&#8242;</li></ul><p>There are a couple of other higher-end FALSEhoods, such as an empty array. It should be fairly obvious that FALSE, NULL, no actual value, and an empty string are all FALSE values; the bug arises when you forget that zero, in any form, is also FALSE. And here&#8217;s how it can manifest itself as a bug (this is a different example than the one in the book and referenced in the forum)…</p><p>The <strong>stripos()</strong> function is used to identify whether or not string Needle is found within another string Haystack. If the Needle is not found, <strong>stripos()</strong> returns FALSE. If the Needle is found, <strong>stripos()</strong> <em>does not return TRUE</em>, but rather <em>returns the indexed position where Needle begins in Haystack</em>. This code, therefore, could be a problem:</p><p><code>if (stripos($haystack, $needle)) {…</code></p><p>The intent is to see if <strong>$needle</strong> exists in <strong>$haystack</strong>. However, if <strong>$needle</strong> is the first part of <strong>$haystack</strong>, <strong>stripos()</strong> will return 0, which will be interpreted by that conditional as FALSE. The bug-free solution is to change the conditional to test if the value returned by <strong>stripos()</strong> is not identical to FALSE:</p><p><code>if (stripos($haystack, $needle) !== false) {…</code></p><p>Note that you have to explicitly use the <em>not identical</em> operator (<strong>!==</strong>), as using the <em>not equal</em> operator (<strong>!=</strong>) would again be a bug, as the zero returned by the function would, in fact, be equal (but not identical) to FALSE.</p><p>Again, I hope you can take some solace in knowing that we all make mistakes, no matter the level of experience (or maybe that&#8217;s depressing?). I personally find it frustrating to make mistakes that I&#8217;m already aware of as a possibility, but on the bright side, making mistakes you know about makes them easier to fix!</p><h2 id="qa">Q&amp;A =&gt; Could You Say More About Stored Procedures?</h2><p>Oguz had prompted me to write a bit about stored procedures in general and in MySQL in particular. Stored procedures are one of those higher-end database concepts which you may have heard about but never really used (other examples include VIEWs and UNIONs). I previously wrote about stored procedures in my &#8220;<a
href="http://www.larryullman.com/books/mysql-visual-quickstart-guide-2nd-edition/">MySQL: Visual QuickStart Guide</a>&#8221; and my &#8220;<a
href="http://www.larryullman.com/books/php-5-advanced-visual-quickpro-guide-2nd-edition/">PHP 5 Advanced: Visual QuickPro Guide</a>&#8220;, and then relied upon them extensively in the second example of my &#8220;<a
href="http://www.larryullman.com/books/effortless-e-commerce-with-php-and-mysql/">Effortless E-Commerce with PHP and MySQL</a>&#8220;.</p><p>Both <em>stored procedures</em> and <em>stored functions</em> fall under the category of <a
href="http://dev.mysql.com/doc/refman/5.1/en/stored-routines.html">stored routines</a>, added to MySQL in version 5.1 (and MySQL is still adding features in this area). A stored routine is simply a memorized set of SQL queries and code. Think of it like taking any block of PHP code that interacts with a database, has conditionals, does something with the query data, etc., but store all of that in the database itself. The primary difference between a stored procedure and a stored function is that a stored <em>function</em> can return only a single value whereas a stored <em>procedure</em> can return an entire result set (i.e., multiple rows of multiple columns of data). For example, in &#8220;PHP 5 Advanced&#8221;, a stored function is created that returns the distance in miles between two points on the globe, which involves complicated trigonometry using latitude and longitude. A call to that function is then part of a standard SELECT query, as if it were any other predefined MySQL function. Conversely, in &#8220;Effortless E-Commerce with PHP and MySQL&#8221;, stored procedures are used to update shopping carts, return a list of sale items, and much more. Both types of routines can also take arguments, just like functions in PHP.</p><p>Stored routines offer several benefits, the most important of which is improved security. Because all of the database references—table and column names—are in the stored routines, a PHP script using those routines need not have any knowledge of the particulars of the database. Further, a stored routine can use its arguments in queries with the same security as <em>prepared statements</em>, thereby preventing SQL injection attacks. Applications with the highest level of security requirements, such as banking, rely upon stored routines.</p><p>You can also get better performance using stored routines, both because the routines can be cached and because less data has to be transferred to the database (just the data itself gets transferred; all the SQL is already in the database). Using stored routines also offers improved application portability, in that many different types of clients—PHP scripts, command line tools, GUI applications, etc.—can make use of the same stored routines.</p><p>There are arguments against using stored routines, too. For starters, you&#8217;ll need a relatively current version of MySQL, and the ability to create an execute stored routines (these are permissions not necessarily offered by, for example, shared hosting environments). Stored routines also marry your applications to specific database applications (e.g., MySQL or Oracle), although stored routines are part of the SQL standard and may be somewhat translatable from one database application to the next. And, as with most things, there&#8217;s a learning curve involved and debugging applications that use stored routines becomes a bit harder.</p><p>You can find out more about stored routines in the books I mentioned, in the <a
href="http://dev.mysql.com/doc/refman/5.1/en/stored-routines.html">MySQL manual&#8217;s main page for stored routines</a>, and in the stored routines <a
href="http://dev.mysql.com/doc/refman/5.1/en/faqs-stored-procs.html">FAQ</a> and <a
href="http://dev.mysql.com/doc/refman/5.1/en/stored-program-restrictions.html">restrictions</a> pages of the MySQL manual.</p><h2 id="thinking">What is Larry Thinking? =&gt; Doing What I Do: Web Development</h2><p>In this newsletter I&#8217;m finishing what became a series on IT careers. I first wrote about becoming a better programmer, in two parts(<a
href="http://www.larryullman.com/2011/02/01/what-is-larry-thinking-36-becoming-a-better-programmer-and-more/#thinking">1</a> and <a
href="http://www.larryullman.com/2011/02/25/what-is-larry-thinking-37-becoming-a-better-programmer-part-2/#thinking">2</a>). Then I wrote about <a
href="http://www.larryullman.com/2011/03/22/what-is-larry-thinking-38-building-a-career/#thinking">building a career</a> and <a
href="http://www.larryullman.com/2011/04/16/what-is-larry-thinking-39-how-i-got-here-and-the-future/#thinking">how I got here</a>. Next, I wrote about <a
href="http://www.larryullman.com/2011/05/12/what-is-larry-thinking-40-doing-what-i-do-part-1/#thinking">some of the specifics of what I do</a>, focussing on the writing side. In the <a
href="http://www.larryullman.com/2011/06/09/what-is-larry-thinking-41-doing-what-i-do-part-2/#thinking">previous newsletter</a>, I discussed training. This leaves me with the last thing that I do: Web and application development (i.e., programming).</p><p>Web and application development jobs have a wide range of possibilities with a wide range of potential income. Small, simple jobs may pay a few hundred dollars; big, complex, and well-funded projects can pay tens of thousands or hundreds of thousands. Getting any job, regardless of size, is a two-step process: 1) finding out about the job; and, 2) convincing the client to hire you.</p><p>There are online sites for finding projects, but you&#8217;ll be competing with everyone else there. You&#8217;ll have better luck by networking: connecting with people, businesses, and organizations that might be able to make use of your abilities. For example, for a couple of years I was the outside programmer that did the dynamic functionality for a graphic designer. She got the projects, managed the clients, the contracts, and the billing, and I just did my share of the work. A perfect arrangement for me! Local user groups, schools, and similar communities can be good ways to hook up with people in a casual way that might pan out down the line.</p><p>As for convincing clients to hire you, the most important criteria in my mind are good communication skills. Everyone says that communication skills are important, but not that many people excel in this area, and way too many don&#8217;t even try to communicate well. <em>Be clear, responsive, and punctual in your communications!</em> Doing so demonstrates that you have a level of professionalism needed to do the work itself. If you can&#8217;t clearly express yourself in an email, if you fail to answer questions asked of you, or if you&#8217;re negligent in responding promptly, it suggests that the work you do will be poorly put together, will fail to meet expectations, and not be done on time, either.</p><p>Secondarily, you&#8217;ll need to have a portfolio showing what you&#8217;re capable of. If you don&#8217;t have a portfolio, then give them something that they can look at. One of my very first clients, for whom I&#8217;m still working, wanted a bit of JavaScript coding for his site. At that time I had no portfolio to show him, so as part of my bid, I did the work itself and presented that. Nothing more clearly indicates your ability to do a project than actually doing the project! Further, the client could also see, before he hired me, that the project would be finished quickly (because it already was). Yes, I ran the risk of making no money for my efforts, but at the time I needed the work and had to go out on a limb. It really panned out, and I would do it again if I felt I had to (arguably, I have had to in the past, as getting published involves some amount of writing on spec).</p><p>And this leads me to a point that you&#8217;ll (hopefully) learn in time as you grow your skills and your budget: you&#8217;ll always adjust your bids not just to the project and the client but to your situation. When I&#8217;m especially busy or if a project isn&#8217;t that interesting, clients will get the &#8220;I don&#8217;t really want to do this project but if I am going to do it, I&#8217;m going to get paid well&#8221; bid. When I&#8217;m not that busy or a project is interesting, I&#8217;ll provide a cheaper bid. Life is always a matter of time versus money, and the professional is constantly making adjustments along that scale.</p><p>As a final cornucopia of thoughts, first, don&#8217;t be afraid to overbid. Even if you&#8217;re desperate, you may really come to regret getting a project at a low bid. If anything, it tells you a lot about a client that wants the lowest price: you probably don&#8217;t want to work with people that want things on the cheap. There is no doubt you will sometimes make less money on a project than you should (and hopefully sometimes make more), but try not to plan on shortchanging yourself. For that matter, have a good contract in place with expectations clearly laid out so that you don&#8217;t get steamrolled.</p><p>Next, you could consider becoming a specialist in one area: CMS (e.g., Joomla), WordPress, etc. You run the risk of not being able to get work as easily, because you are so specialized, but you may also be able to make more money, and get better at a smaller set of skills faster, by narrowing your focus.</p><p>And lastly, if you&#8217;re working on a project and you&#8217;re having problems and aren&#8217;t going to make the deadline, handle the situation professionally. Never hide from clients, be as honest as you can, and always reply to emails promptly. For more strategies along these lines, check out <a
href="http://brainzooming.com/project-management-techniques-when-time-running-down/6869/">this nice article</a>.</p><p>So that&#8217;s it on my long series on building a career in IT. As happens with me, all the time, what started off as a simple idea expanded and expanded. I worry that I ran out of steam at the end here, but hopefully you&#8217;ve benefitted from this discussion somehow, and I&#8217;ve helped you, in whatever small way, in pursuing your dream of an IT career (as for me, my dream involves a hammock overlooking the Caribbean Sea).</p><h2 id="news">Larry Ullman&#8217;s Book News =&gt; &#8220;PHP and MySQL for Dynamic Web Sites&#8221; (4th Edition) and &#8220;Modern JavaScript: Develop and Design&#8221;</h2><p>I&#8217;m very pleased to say that I&#8217;ve completed the first draft of the fourth edition of &#8220;PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide&#8221; (and by &#8220;first draft&#8221;, I mean the first draft submitted to the publisher; there are multiple writing drafts just to get to that point). As with the fourth edition of &#8220;<a
href="http://www.larryullman.com/books/php-for-the-web-visual-quickstart-guide-4th-edition/">PHP for the Web: Visual QuickStart Guide</a>&#8220;, I added a &#8220;Review and Pursue&#8221; section to the end of each chapter. I also expanded the coverage of SQL and MySQL, including much more on JOINs. One new chapter introduces the <a
href="http://www.jquery.com">jQuery</a> JavaScript framework, with examples of form validation and performing Ajax requests. Another new chapter introduces the fundamentals of Object-Oriented Programming, using the MySQL Improved extension for several examples, and the <a
href="http://www.php.net/datetime">DateTime</a> class for another. In the appendix, I&#8217;ve included a few pages on configuring the Apache Web server, providing the syntax for performing common tasks such as password protecting directories and URL rewriting.</p><p>Last, but not least, I am pleased to announce that I have in my hands a contract to write the book &#8220;Modern JavaScript: Develop and Design&#8221; for Peachpit Press. This is the publisher I&#8217;ve worked with the most, and so I&#8217;m quite comfortable with them. The book will be in a new series, titled &#8220;Develop and Design&#8221;, specifically created for code-based books (the first title in the series is on ActionScript). The series does <em>not</em> use the two-column format like the Visual QuickStart/QuickPro series (which some people like, some people don&#8217;t), and will be in full color, a first for me. The publisher has allotted me up to 600 pages, which is quite a lot, and by using a publisher, the book will have the widest possible availability (Peachpit Press really worked with me on making this happen). I&#8217;ll begin formally writing the book in late July or early August so that it comes out by the end of the year. Once again, my thanks to everyone for their interest in this book, and for all of the feedback.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2011/07/04/what-is-larry-thinking-42-doing-what-i-do-part-3/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>The CodeLobster PHP IDE</title><link>http://www.larryullman.com/2011/06/23/the-codelobster-php-ide/</link> <comments>http://www.larryullman.com/2011/06/23/the-codelobster-php-ide/#comments</comments> <pubDate>Thu, 23 Jun 2011 14:48:42 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[cakephp]]></category> <category><![CDATA[codeigniter]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[ide]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[smarty]]></category> <category><![CDATA[wordpress]]></category> <category><![CDATA[yii]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2627</guid> <description><![CDATA[I&#8217;ve been contacted a couple of times now by the people behind CodeLobster, a PHP-centric IDE, in the hopes that I&#8217;d review/mention CodeLobster on this site. Now, CodeLobster only runs on Windows, which means I haven&#8217;t, and probably won&#8217;t, use it myself (I primarily use a Mac, only using Windows for testing purposes), but I [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve been contacted a couple of times now by the people behind <a
href="http://www.codelobster.com/">CodeLobster</a>, a PHP-centric IDE, in the hopes that I&#8217;d review/mention CodeLobster on this site. Now, CodeLobster only runs on Windows, which means I haven&#8217;t, and probably won&#8217;t, use it myself (I primarily use a Mac, only using Windows for testing purposes), but I have no problems mentioning products and sites here that I don&#8217;t personally use, because such things may still be of use to you (you, whoever you are, presumably are a separate entity with your own interests, needs, etc., and are statistically more likely to be running Windows). Anyway&#8230;</p><p>So, CodeLobster is an IDE for PHP that runs on Windows. It&#8217;s available in both a free and &#8220;professional&#8221; version, the professional version costing $100 (US). The free version comes with an HTML editor and inspector, a CSS editor, a JavaScript editor, a PHP editor, and a PHP debugger. This all includes the standard features such as code completion, code collapsing, browser preview, project management, FTP, and so forth. The professional version includes all of those features, plus plug-ins for specific tools and frameworks: CakePHP, CodeIgniter, Drupal, jQuery, Joomla, Smarty, Symfony, WordPress, and Yii. In other words, the professional version gives you code completion, contextual help, and so forth for these additional tools that you may also be programming in.</p><p>As I said, I haven&#8217;t personally used it, but if you&#8217;re looking for a PHP/Web Development IDE, it may be worth checking out.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2011/06/23/the-codelobster-php-ide/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Using Cookies in the Yii Framework</title><link>http://www.larryullman.com/2011/06/04/using-cookies-in-the-yii-framework/</link> <comments>http://www.larryullman.com/2011/06/04/using-cookies-in-the-yii-framework/#comments</comments> <pubDate>Sat, 04 Jun 2011 14:28:06 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[cookie]]></category> <category><![CDATA[csrf]]></category> <category><![CDATA[framework]]></category> <category><![CDATA[mvc]]></category> <category><![CDATA[security]]></category> <category><![CDATA[yii]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=2552</guid> <description><![CDATA[In a previous post, I wrote about . In this one, I&#8217;ll look at using cookies. Neither is that difficult, but as with all things regarding frameworks, the solution may not be obvious at first. And there are some ways to make use cookies in Yii in a more secure manner.To create a cookie in [...]]]></description> <content:encoded><![CDATA[<p>In a previous post, I wrote about <a
href="http://www.larryullman.com/2011/05/03/using-sessions-with-the-yii-framework/">using sessions in Yii-based sites</a>. In this one, I&#8217;ll look at using cookies. Neither is that difficult, but as with all things regarding frameworks, the solution may not be obvious at first. And there are some ways to make use cookies in Yii in a more secure manner.<span
id="more-2552"></span>To create a cookie in PHP without using a framework, you just call the <a
href="http://us.php.net/setcookie">setcookie()</a> function. To create a cookie while using the Yii framework, you don&#8217;t use <strong>setcookie()</strong>, but rather create a new element in the <strong>Yii::app()-&gt;request-&gt;cookies</strong> array. (Note that sessions are stored in <strong>Yii::app()-&gt;session</strong>, but cookies are in <strong>Yii::app()-&gt;request-&gt;cookies</strong>, because cookies are part of the HTTP request a browser makes of a Web server).</p><p>What you&#8217;ll want to do to create a cookie is create a new object of type <a
href="http://www.yiiframework.com/doc/api/1.1/CHttpCookie/">CHttpCookie</a>: Yii&#8217;s class for cookies. Here, then, is the syntax for setting a cookie in Yii:</p><pre class="brush: php; title: ; notranslate">Yii::app()-&gt;request-&gt;cookies['name'] = new CHttpCookie('name', 'value');</pre><p>You must use the same <em>name</em> value in both places, replacing it with the actual cookie name. Remember that the cookie&#8217;s name, and value, are visible to users in their browsers, so one ought to be prudent about what name you use and be extra mindful of what values are being stored.</p><blockquote><p>Tip: Because the cookie&#8217;s name must be used twice in the code, you may want to consider assigning the cookie&#8217;s name to a variable that is used in both instances instead.</p></blockquote><p>Once you&#8217;ve created a cookie, you can access it (on subsequent pages, because cookies are never immediately available to the page that set them), using <strong>Yii::app()-&gt;request-&gt;cookies['name']-&gt;value</strong>. You have to use the extra <strong>-&gt;value</strong> part, because the &#8220;cookie&#8221; being created is actually an object of type <strong>CHttpCookie</strong> (and Yii, internally, takes care of actually sending the cookie to the browser and reading the received cookie from the browser).</p><p>To test if a cookie exists, just use <strong>isset()</strong> on <strong>Yii::app()-&gt;request-&gt;cookies['name']</strong>, as you would any other variable.</p><p>To delete an existing cookie, just unset the element as you would any array element:</p><pre class="brush: php; title: ; notranslate">unset(Yii::app()-&gt;request-&gt;cookies['name']);</pre><p>To delete all existing cookies (for that site), use</p><pre class="brush: php; title: ; notranslate">Yii::app()-&gt;request-&gt;cookies-&gt;clear();</pre><p>By default, cookies will be set to expire when the browser window is closed. To change that, you need to modify the properties of the cookie. You can&#8217;t do so when you create the <strong>CHttpCookie</strong> object (i.e., the only arguments to the constructor are the cookie&#8217;s name and value), so you must separately create a new object of type <strong>CHttpCookie</strong>, to be assigned to <strong>Yii::app()-&gt;request-&gt;cookies</strong> later:</p><pre class="brush: php; title: ; notranslate">$cookie = new CHttpCookie('name', 'value');</pre><p>Then adjust the <strong>expire</strong> attribute:</p><pre class="brush: php; title: ; notranslate">$cookie-&gt;expire = time() + (60*60*24); // 24 hours</pre><p>Then add the cookie to the application:</p><pre class="brush: php; title: ; notranslate">Yii::app()-&gt;request-&gt;cookies['name'] = $cookie;</pre><p>You can manipulate other cookie properties using the above syntax: <strong>domain</strong>, <strong>httpOnly</strong>, <strong>path</strong>, and <strong>secure</strong>. Each of these correspond to the arguments to the <strong>setcookie()</strong> function. (You can also manipulate the value of the cookie through <strong>$cookie-&gt;value</strong> and the cookie&#8217;s name through <strong>$cookie-&gt;name</strong>). For example, if you want to limit a cookie to a specific domain, or subdomain, use <strong>domain</strong>; to limit it to a specific folder, use <strong>path</strong>; and to only transmit the cookie over SSL, set <strong>secure</strong> to <strong>true</strong>.</p><p>You can also improve the security of your cookies by setting Yii&#8217;s <strong>enableCookieValidation</strong> to <strong>true</strong>, in the Yii configuration file:</p><pre class="brush: php; title: ; notranslate">return array(
    'components'=&gt;array(
        'request'=&gt;array(
            'enableCookieValidation'=&gt;true,
        ),
    ),
);</pre><p>Cookie validation prevents cookies from being manipulated in the browser. To accomplish that, Yii stores a hashed representation of the cookie&#8217;s value when it gets sent, and then compares the received cookie&#8217;s value to ensure they are the same. Obviously there&#8217;s extra overhead required to do this, but in some instances, the extra effort is justified by the extra security.</p><p>Finally, one good reason to use cookies in a Yii-based site, even if the site is otherwise using sessions, is to prevent <a
href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">Cross-site Request Forgery (CSRF)</a> attacks. A CSRF works like this: malicious site A has some code on it, such as an image tag whose <strong>src</strong> attribute points to a page on site B that does something meaningful: <em>http://www.example.com/page.php?action=this</em>. When any viewer loads the page on site A, the use of that <strong>src</strong> attribute has the effect of that user performing a request of the page on site B.</p><p>As an example, let&#8217;s say that an administrator at your site logs in and does whatever but doesn&#8217;t log out. The administrator therefore still has a cookie in her or his browser indicating access to the site (i.e., the user could open the browser and perform admin tasks without logging in again). Now let&#8217;s say that the <strong>src</strong> attribute on malicious site A points to a page on your site that deletes a blog posting. If the administrator with the live cookie loads that page on site A, it will have the same effect as if that administrator went to your site and requested that page directly. This is not good.</p><p>To prevent a CSRF attack on your site, first make sure that all significant form submissions use POST instead of GET. You should be using POST for any form that changes server content anyway, but a CSRF POST attack is a bit harder to pull off than a GET attack.</p><p>Second, set <strong>enableCsrfValidation</strong> to <strong>true</strong> in your configuration file:</p><pre class="brush: php; title: ; notranslate">return array(
    'components'=&gt;array(
        'request'=&gt;array(
            'enableCsrfValidation'=&gt;true,
        ),
    ),
);</pre><p>By doing this, Yii will send a cookie with a unique identifier to the user. All forms will then store that same identifier in a hidden input. The form submission will only be handled then if the two identifiers match. With the case of a CSRF attack, the two identifiers will not match because the form&#8217;s identifier will not be passed as part of the request (I hope this is clear; if not, let me know). Note that this only works if you&#8217;re using <a
href="http://www.yiiframework.com/doc/api/1.1/CHtml">CHtml</a> to create your forms (if you manually create the form tags, Yii won&#8217;t insert the necessary code for preventing CSRF attacks).</p><p>The most important thing to remember about cookies, which I&#8217;ve already stated, is that cookies are visible to the user in the browser. And unless you&#8217;re using SSL for the cookies, they are also visible to anyone else while being transmitted back and forth between the server and the client (which happens on every page request). So be careful of what gets stored in a cookie! If the data is particularly sensitive, use sessions instead of cookies.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2011/06/04/using-cookies-in-the-yii-framework/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> </channel> </rss>
<!-- Served from: www.larryullman.com @ 2012-05-21 15:50:09 by W3 Total Cache -->
