<?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</title> <atom:link href="http://www.larryullman.com/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>What is Larry Thinking? #55 =&gt; Good Companies, Books, and Answers</title><link>http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/</link> <comments>http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/#comments</comments> <pubDate>Mon, 21 May 2012 11:03:07 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[book]]></category> <category><![CDATA[hosting]]></category> <category><![CDATA[newsletter]]></category> <category><![CDATA[oop]]></category> <category><![CDATA[regex]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3199</guid> <description><![CDATA[In this edition… About This Newsletter What Were You Thinking? =&#62; Ajax and Search Engines On the Web =&#62; My Web Host, ServInt On the Web =&#62; 37 Tested PHP, Perl, and JavaScript Regular Expressions On the Blog =&#62; Review of &#8220;Technical Blogging&#8221; by Antonio Cangiano Q&#38;A =&#62; Have You Changed Your Opinion of OOP? [...]]]></description> <content:encoded><![CDATA[<p>In this edition…</p><ul><li><a
href="http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/#about">About This Newsletter</a></li><li><a
href="http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/#you">What Were You Thinking? =&gt; Ajax and Search Engines</a></li><li><a
href="http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/#web1">On the Web =&gt; My Web Host, ServInt</a></li><li><a
href="http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/#web2">On the Web =&gt; 37 Tested PHP, Perl, and JavaScript Regular Expressions</a></li><li><a
href="http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/#blog">On the Blog =&gt; Review of &#8220;Technical Blogging&#8221; by Antonio Cangiano</a></li><li><a
href="http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/#qa1">Q&amp;A =&gt; Have You Changed Your Opinion of OOP?</a></li><li><a
href="http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/#qa2">Q&amp;A =&gt; Why does false equal 0?</a></li><li><a
href="http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/#news">Larry Ullman&#8217;s Book News =&gt; &#8220;PHP Advanced and Object-Oriented Programming</a></li></ul><p><span
id="more-3199"></span></p><h2 id="about">About This Newsletter</h2><p>So, in case you hadn&#8217;t noticed (or are new to the newsletter), it now has a new template. It&#8217;s a bit more involved than the previous template (two columns instead of just one), but is simpler in other ways, too. The new look will more closely match the updated scheme for <a
href="http://LarryUllman.com">LarryUllman.com</a>, whenever I get around to putting that online (aka, July). Basically what I&#8217;m going with for the updated site is a white background, minimum of images, blue for headings, and, above all, a clear presentation of content.</p><p>To create this newsletter template, I used the template builder from <a
href="http://campaignmonitor.com.">Campaign Monitor</a>, whom I use for these newsletters. Campaign Monitor costs me $30/month (US), but I really think it&#8217;s worth it. They have a good product, and the user interface they&#8217;ve created is tremendous. In any case, I&#8217;m hoping that since I used their system, the resulting template will look reasonably good on most systems and devices.</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; Ajax and Search Engines</h2><p>In my <a
href="http://www.larryullman.com/2012/04/30/what-is-larry-thinking-54-salt-pepper-99designs/#qa1">previous newsletter</a>, I answered a question about making Ajax-derived content available to search engines. Yogesh was kind enough to share a link at <a
href="https://developers.google.com/webmasters/ajax-crawling/">Google Developers</a> in which Google explains what else you can do to make Ajax-derived content indexable. Thanks, Yogesh!</p><h2 id="web1">On the Web =&gt; My Web Host, ServInt</h2><p>Since I&#8217;m dishing out accolades (e.g., Campaign Monitor), I&#8217;d like to recognize the company I use for Web hosting: <a
href="http://www.servint.net">ServInt</a>. I&#8217;ve been using ServInt for my Web hosting for almost five years now and I&#8217;m so, so happy with their service. They only provide Virtual Private Servers (VPS) and dedicating hosting, so ServInt is not for everyone. But I think their packages are reasonably priced and their customer service is excellent. Their customer service is excellent! I&#8217;m paying $50 (USD) per month and am happily doing so. I have complete control over my little area of the server and don&#8217;t have to worry about what someone else might have done that would bring my site down. I have a few sites on the server, which garner between 500,000 and 1 million page views per month, and the lowest-level Essential VPS setup handles that easily.</p><p>There are two reasons I&#8217;m mentioning ServInt now. One is that I get asked this question a lot. Although if you&#8217;re not interested in a VPS account, these companies have also been recommended in my <a
href="http://www.larryullman.com/forums/index.php?/topic/132-web-hosting-recommendation/">forums</a>:</p><ul><li><a
href="http://www.dreamhost.com">Dreamhost</a></li><li><a
href="http://www.hostduplex.com">HostDuplex</a></li><li><a
href="http://hostgator.com">HostGator</a></li></ul><p>Besides letting you all know about a good hosting company, if you&#8217;re looking for one, I wanted to thank the people that have used me as a reference when creating his or her own account with ServInt. I don&#8217;t know who has done so, but a couple of people have signed up with ServInt and mentioned me in the past few months, which gives me a small credit on my account. Thanks for that!</p><h2 id="web2">On the Web =&gt; 37 Tested PHP, Perl, and JavaScript Regular Expressions</h2><p>Some time ago I stumbled upon <a
href="http://www.virtuosimedia.com/dev/php/37-tested-php-perl-and-javascript-regular-expressions">37 Tested PHP, Perl, and JavaScript Regular Expressions</a>. This is just a list of 37 Perl-Compatible Regular Expressions (PCRE) that you can use for common purposes: credit card numbers, dates, postal codes, URLs, email addresses, and more. A good resource to have around!</p><h2 id="blog">On the Blog =&gt; Review of &#8220;Technical Blogging&#8221; by Antonio Cangiano</h2><p>I <a
href="http://www.larryullman.com/2012/05/07/review-of-technical-blogging-by-antonio-cangiano/">just recently reviewed</a> the book &#8220;<a
href="http://amzn.to/H6gFcE">Technical Blogging</a>&#8221; by <a
href="http://antoniocangiano.com/">Antonio Cangiano</a>. It&#8217;s a very good book, and one that I&#8217;m happy that I read. For more, check out the <a
href="http://www.larryullman.com/2012/05/07/review-of-technical-blogging-by-antonio-cangiano/">review on my blog</a>.</p><h2 id="qa1">Q&amp;A =&gt; Have You Changed Your Opinion of OOP?</h2><p>In response to my previous newsletter, Marten asked if I have changed my opinion about procedural vs. object-oriented programming. I suspect the question was raised in part because I&#8217;m currently working on &#8220;<a
href="http://amzn.to/M6yvzg">PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide</a>&#8220;. This is something I&#8217;ve discussed in the past, and am happy to go through again. The short answer is no, I have not changed my opinion. And here is what that opinion is:</p><blockquote><p>Procedural programming is better in some situations and OOP is better in some situations.</p></blockquote><p>This is an interesting debate, because PHP is one of the few programming languages that allows you to work procedurally or objectively. You can&#8217;t do procedural code with Java, JavaScript, or Ruby, and you can&#8217;t use objects with C. In PHP, you can <em>choose</em> to use objects or not use objects.</p><p>As for myself, obviously if I&#8217;m using JavaScript, Ruby, or ActionScript, I&#8217;m going to use objects. If I&#8217;m doing C, I&#8217;m not. On some PHP projects, I&#8217;ll use procedural code. On other PHP projects, I&#8217;ll use objects. Obviously any project I do that uses the <a
href="http://www.yiiframework.com">Yii framework</a> will use objects, as most frameworks are OOP in nature. So I&#8217;m totally comfortable with both approaches and I have no preference for one over the other, I always just try to choose the right tool for the job.</p><p>That, of course, is what we should all be doing as developers. There are very few absolutes when it comes to programming; there&#8217;s mostly just opinions. I&#8217;m sure that part of the reason it may have seemed like I didn&#8217;t care for OOP is that I don&#8217;t care for the presumption that OOP is better than procedural programming. OOP has its strengths and weaknesses, as does procedural programming. One is not categorically better or worse than the other. In PHP, which allows for both, there&#8217;s a very strong argument to being comfortable with both approaches so that you, too, can choose the right tool for each job.</p><p>This belief of mine also applies to frameworks. People who are really intro frameworks sometimes assert that programming with frameworks is vastly superior. It&#8217;s not. Not all the time, that is. For some developers, with some projects, a framework is the better choice. For some developers, with some projects, a framework would be the worse choice.</p><p>I like analogies, so I&#8217;ll end this with one: I like tools, I like working around the house and being handy. I have probably about 30 screwdrivers and four electric drill/drivers, including a relatively new, and quite powerful, impact driver. The analogy is that this impact driver (OOP) is the better way to drive a screw, but that&#8217;s patently false. The driver was much more expensive than any screwdriver, and it&#8217;s much heavier, and I need to go looking for the right bit, and I need to keep the batteries charged. And aside from all that, if I had to put a small screw into the back of a picture frame, the impact driver would be a <em>terrible</em> choice. But the same goes for the screwdriver (procedural): if I had to drive a three-inch lag bolt into a post, trying to do that with a screwdriver would be a decision I&#8217;d regret for a long, long time.</p><p>Do away with the assumptions, learn as much as you can, and always try to choose the right tool for the job.</p><h2 id="qa2">Q&amp;A =&gt; Why does false equal 0?</h2><p>Matti sent me this question via Twitter, specifically wondering what the difference is between 0 and 1 and true and false in PHP, and why false equals 0. This is a common point of confusion and cause of many bugs. However, the issue isn&#8217;t with the differences between these values but rather with how conditionals are evaluated and what equality is.</p><p>When you write any conditional in PHP, PHP needs to determine whether that conditional is true or false. For many conditionals, such as comparison, it&#8217;s pretty easy to identify true/false: is <strong>$x</strong> greater than 5 or no? Other conditionals are more subjective, though, and the language needs to define its rules for these situations. For example, <code>if ($x) {</code>. Is that conditional true or false? Well, it depends upon the value of <strong>$x</strong>, of course.</p><p>Obviously, if <strong>$x</strong> has a value of <strong>true</strong>, then the conditional is true. The same goes for <strong>$x</strong> having a value of &#8220;something&#8221;. It&#8217;s also pretty easy to decide that null is going to be treated as false. Things get tricky, though, when you have values such as 0 and an empty string. If <code>$x = 0;</code>, then should that conditional be true or false? The variable has been deliberately assigned a value, but the value is 0. Again, these are the kinds of choices that creators of a language have to make. In PHP, 0, an empty string, false, and null are all considered <em>empty</em> values, which get evaluated as false when used as the basis of a conditional.</p><p>Similarly, language designers have to make decisions as to what constitutes equality. If you compare two values of the same type—a string against a string, a number against a number, it is again easy to evaluate equality. It gets complicated when you compare values of different types: <code>if (2 == "2")</code>. That conditional compares the number 2 against the string &#8220;2&#8243;. These two values are not <em>identical</em> because of their different types, but are they equal?</p><p>To compare two different types, languages have to cast (i.e., forcibly convert) one type to the other. Generally, casting converts a value down to a simpler type. In that conditional, PHP will convert the string &#8220;2&#8243; to its numeric equivalent, which is 2. When you compare a Boolean against a non-Boolean, the non-Boolean has to be casted to a Boolean. As we&#8217;ve already seen, the empty values are treated as false in a conditional, so those values—0, an empty string, null, and false—are cast to the Boolean <strong>false</strong>. Hence, 0 does equal <strong>false</strong>.</p><p>Fortunately, programming languages tend to be pretty consistent in what gets treated as false (JavaScript also equates 0, an empty string, null, and false). The bugs arise in situations where your code tests for &#8220;truthiness&#8221; when it shouldn&#8217;t. For example, the conditional <code>if ($x) {</code> is fine unless one of the empty values is a valid value for <strong>$x</strong>. If it&#8217;s okay for <strong>$x</strong> to have a value of an empty string, you&#8217;d need to change your conditional accordingly. In PHP, the <strong>empty()</strong> function can discern between a variable just being set (i.e., assigned a value), and having a non-empty value. As another example, the <strong>strpos()</strong> function in PHP looks for a needle in a haystack, returning the starting indexed position where the needle is found. If the needle is found at the very beginning of the haystack, then the function will return 0. If you were to do this, you&#8217;d have a bug:</p><blockquote><p><code>if (strpos($haystack, $needle)) {</code></p></blockquote><p>The assumption is that the condition will be true if the needle is found in the haystack, but as written, the condition will only be true if the needle is found in the haystack <em>but not as the first thing in the haystack</em>. The proper way to write that conditional is:</p><blockquote><p><code>if (strpos($haystack, $needle) !== false) {</code></p></blockquote><p>Also note that it&#8217;s an identity comparison to false, because using != contains the same bug, as 0 does equal false.</p><p>Thanks to Matti for the good question. I hope this has clarified the issue and please, anyone, let me know if you have more questions or comments about this or similar matters.</p><h2 id="news">Larry Ullman&#8217;s Book News =&gt; &#8220;PHP Advanced and Object-Oriented Programming&#8221;</h2><p>First, I continue to receive a lot of positive feedback on the &#8220;<a
href="http://www.larryullman.com/books/modern-javascript-develop-and-design/">Modern JavaScript: Develop and Design</a>&#8221; book, which makes me very happy. I&#8217;ve posted a couple of the comments <a
href="http://www.larryullman.com/books/modern-javascript-develop-and-design/reviews/">on my Web site</a>, and currently the book has received five reviews on <a
href="http://amzn.to/wsdmkq">Amazon</a>, all for five stars. The book seems to be selling well, too, which is great, but knowing that I was able to do what I set out to do—and that my intention actually did match up with what readers wanted—is paramount. My continued thanks to everyone for their interest in the book and for the nice words on it.</p><p>Right now, I&#8217;m continuing to chug away on the third edition of my PHP advanced book, titled &#8220;<a
href="http://amzn.to/M6yvzg">PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide</a>&#8220;. I&#8217;ve written four chapters thus far and hope to get another two written before I head off to Istanbul (in 10 days!).</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/05/21/what-is-larry-thinking-55-good-companies-books-answers/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Learn to Write</title><link>http://www.larryullman.com/2012/05/18/learn-to-write/</link> <comments>http://www.larryullman.com/2012/05/18/learn-to-write/#comments</comments> <pubDate>Fri, 18 May 2012 13:34:05 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[Uncategorized]]></category> <category><![CDATA[browsers]]></category> <category><![CDATA[html]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3198</guid> <description><![CDATA[There was a recent posting by Jeff Atwood titled &#8220;Please Don&#8217;t Learn to Code&#8220;, which received a lot of recent discussion. It&#8217;s a bit silly, to me, because the impetus for that post—a tweet by NY Mayor Bloomberg suggesting he was going to learn to code in 2012—was almost certainly sent out as a promotional message [...]]]></description> <content:encoded><![CDATA[<p>There was a recent posting by Jeff Atwood titled &#8220;<a
href="http://www.codinghorror.com/blog/2012/05/please-dont-learn-to-code.html">Please Don&#8217;t Learn to Code</a>&#8220;, which received a lot of recent discussion. It&#8217;s a bit silly, to me, because the impetus for that post—a tweet by NY Mayor Bloomberg suggesting he was going to learn to code in 2012—was almost certainly sent out as a promotional message for a NYC-based company (<a
href="http://www.codecademy.com">CodeAcademy</a>), not as a sincere expression of the mayor&#8217;s side interests. In any case, Atwood&#8217;s piece came across to some as unnecessarily harsh, and while it&#8217;s hard to argue that <em>everyone</em> should learn to code, it&#8217;s also elitist to suggest that people should&#8217;t learn X because they&#8217;re not going to be able to do it in a way you think is right.</p><p>The reason I mention Atwood&#8217;s piece is because <a
href="http://www.randsinrepose.com">Rands in Repose</a> had a very nice reaction post titled &#8220;<a
href="http://www.randsinrepose.com/archives/2012/05/16/please_learn_to_write.html">Please Learn to Write</a>&#8220;. Maybe it&#8217;s because I am a writer, but the suggestion—Hey, if you want to improve yourself, communicate better.—rings true to me.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/05/18/learn-to-write/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <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>Interview with Douglas Crockford</title><link>http://www.larryullman.com/2012/05/11/interview-with-douglas-crockford/</link> <comments>http://www.larryullman.com/2012/05/11/interview-with-douglas-crockford/#comments</comments> <pubDate>Fri, 11 May 2012 11:00:21 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[crockford]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3193</guid> <description><![CDATA[SmashingMagazine recently published an interview with Douglas Crockford. Crockford, in case you&#8217;re not familiar, is one of the key proponents of JavaScript. One of JavaScript&#8217;s &#8220;founding fathers&#8221;, if you will. His Master Class video series on JavaScript and the history of programming is really quite illuminating. The interview is part of a new SmashingMagazine series called &#8220;How I Work&#8221;. [...]]]></description> <content:encoded><![CDATA[<p><a
href="http://smashingmagazine.com">SmashingMagazine</a> recently <a
href="http://coding.smashingmagazine.com/2012/04/27/yahoos-doug-crockford-on-javascript/">published an interview</a> with <a
href="http://www.crockford.com">Douglas Crockford</a>. Crockford, in case you&#8217;re not familiar, is one of the key proponents of JavaScript. One of JavaScript&#8217;s &#8220;founding fathers&#8221;, if you will. His <a
href="http://my.safaribooksonline.com/video/programming/javascript/9781449379759">Master Class video series</a> on JavaScript and the history of programming is really quite illuminating.</p><p>The interview is part of a new SmashingMagazine series called &#8220;How I Work&#8221;. As they describe it:</p><blockquote><p>These interviews revolve around how thinkers and creators in the Web world design, code, and create. The goal is not to get into the specific nuances of their craft (as that information already exists online), but rather step back and learn a bit about their habits, philosophies, and workflow for producing great work.</p></blockquote><p>For that reason, the interview is useful whether or not you do any JavaScript programming, as Crockford has great insights into programming in general. Just two things that caught my attention&#8230;</p><blockquote><p><strong>WHAT WERE THE TRAITS OF THE WEAK PROGRAMMERS YOU’VE SEEN OVER YOUR CAREER?</strong><br
/> That’s an easy one—lack of curiosity. They were so satisfied with the work that they were doing was good enough (without an understanding of what ‘good’ was) that they didn’t push themselves.</p></blockquote><p>and &#8230;</p><blockquote><p><strong>HOW MUCH OF A LANGUAGE DO YOU NEED TO KNOW?</strong><br
/> Virtually every programming language is too big. Language standards have difficulty removing unnecessary features but as users we can choose not to use it.<br
/> I would say you can do 100% with knowing 50% of the language.</p></blockquote><p>As for the first, the greatest thing about working for myself is the ability to learn whatever I want. I&#8217;m not pigeonholed into one subject or career. I can see what interests me and expand my knowledge as I see fit. (On the other hand, I&#8217;d certainly make more money if I specialized but there&#8217;s more to life than making money, they say.)</p><p>As for the second, that&#8217;s an interesting suggestion, and one I&#8217;ve not heard before. To be fair, when I write a book on a language, I have to make decisions about what to discuss and what not to (e.g., never cover goto!), but I wouldn&#8217;t have put that number at 50% or in that area. Still, it&#8217;s great that an expert on a language admits that much of it isn&#8217;t necessary, at least not most of the time.</p><p>After the interview, which isn&#8217;t too long, there are two video clips worth checking out. Both are around an hour long, but will give you a sense of what Crockford does in his Master Class videos. One of those videos, and many more, can be found in Yahoo!&#8217;s excellent <a
href="http://yuilibrary.com/theater/">YUI Theater</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/05/11/interview-with-douglas-crockford/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>What&#8217;s New in PHP 5.4</title><link>http://www.larryullman.com/2012/05/09/whats-new-in-php-5-4/</link> <comments>http://www.larryullman.com/2012/05/09/whats-new-in-php-5-4/#comments</comments> <pubDate>Wed, 09 May 2012 11:00:21 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Development]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3130</guid> <description><![CDATA[So PHP 5.4 came out a little while back, and although there aren&#8217;t any major changes, there are a couple to be aware of. Most of the changes involve either very advanced PHP programming (e.g., closures now support the $this variable) or somewhat advanced Object-Oriented Programming. But there are a some changes that will affect the [...]]]></description> <content:encoded><![CDATA[<p>So PHP 5.4 came out a little while back, and although there aren&#8217;t any major changes, there are a <a
href="http://docs.php.net/manual/en/migration54.new-features.php  " class="broken_link">couple to be aware of</a>. Most of the changes involve either very advanced PHP programming (e.g., closures now support the <strong>$this</strong> variable) or somewhat advanced Object-Oriented Programming. But there are a some changes that will affect the average PHP programmer, which I&#8217;ll outline here.<span
id="more-3130"></span></p><h2>Short Array Syntax</h2><p>Historically in PHP, on used the <strong>array()</strong> function to create a new array, as in:</p><pre class="brush: php; title: ; notranslate">$empty = array();
$numbers = array(1, 2, 3, 4);
$states = array('AL' =&gt; 'Alabama', 'AK' =&gt; 'Alaska', 'AZ' =&gt; 'Arizona');</pre><p>PHP 5.4 now has the short array syntax, which just replaces calls to <strong>array()</strong> with the array operator:</p><pre class="brush: php; title: ; notranslate">$empty = [];
$numbers = [1, 2, 3, 4];
$states = ['AL' =&gt; 'Alabama', 'AK' =&gt; 'Alaska', 'AZ' =&gt; 'Arizona'];</pre><p>This is all good and fine, and matches what you might be doing in other languages (such as JavaScript), but remember that you can only do this as of PHP 5.4. This means that unless you know that any server you&#8217;ll be using your code on, now or in the future, must be running PHP 5.4 or later.</p><h2>&lt;?= Always Available</h2><p>In previous versions of PHP, if the short open tags setting was enabled, you could do this shortcut to print the value of a variable:</p><pre class="brush: php; title: ; notranslate">&lt;?=$some_var; ?&gt;</pre><p>Most commonly you&#8217;ll see this when using frameworks and templating tools. As of PHP 5.4, this is now always an option, even if short tags are disabled. The only thing to be careful of with this syntax is that it assumes that <strong>$some_var</strong> has a value.</p><h2>Built-in Web Server</h2><p>In my opinion, the coolest addition is the built-in <a
href="http://docs.php.net/manual/en/features.commandline.webserver.php" class="broken_link">web server in CLI mode</a>. In fact, I&#8217;ve already written about it in Chapter 12 of 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 Advanced: Visual QuickPro Guide</a>&#8220;, which I&#8217;m currently writing. PHP&#8217;s command-line interface (CLI) mode allows you to run PHP commands and PHP scripts from the command-line interface. As of PHP 5.4, that command-line tool also has a basic Web server that can be enabled, letting you test PHP scripts in a Web browser without using Apache or IIS or another Web server application. In short, it just became a bit easier to quickly test some PHP code.</p><h2>The session_status() Function</h2><p>PHP 5.4 introduces some new functions, constants, classes, and methods, but the one that most piques my interest is <strong>session_status()</strong>. This function returns a constant indicating the current session status:</p><ul><li><strong>PHP_SESSION_DISABLED</strong> if sessions are disabled.</li><li><strong>PHP_SESSION_NONE</strong> if sessions are enabled, but none exists.</li><li><strong>PHP_SESSION_ACTIVE</strong> if sessions are enabled, and one exists.</li></ul><p>I haven&#8217;t played with this yet myself, but imagine it could be a useful debugging tool, at the very least.</p><h2>Removed Features</h2><p>Finally, you should be aware that PHP 5.4 has removed several features that have been deprecated for some time. Off these, three are important (in that they used to be important):</p><ul><li>Safe mode is no longer supported</li><li>Magic Quotes does not exist (and the <strong>get_magic_quotes_gpc()</strong> function always returns false)</li><li>The <strong>register_globals</strong> directive has been removed</li></ul><p>With these three changes, you can officially no longer use features that you hopefully stopped using a long, long time ago.</p><p>So there you have the key changes in PHP 5.4, aside from some of the more esoteric things. The changes here aren&#8217;t nearly on the same scale as those introduced in PHP 5.1 (e.g. <a
href="http://docs.php.net/pdo" class="broken_link">PDO</a> extension enabled), 5.2 (e.g., <a
href="http://docs.php.net/manual/en/ref.filter.php" class="broken_link">Filter</a> and <a
href="http://docs.php.net/manual/en/ref.json.php" class="broken_link">JSON</a> extensions enabled), and 5.3 (e.g., <a
href="http://docs.php.net/manual/en/language.namespaces.php" class="broken_link">namespaces</a> and <a
href="http://docs.php.net/manual/en/functions.anonymous.php" class="broken_link">closures</a>, the <a
href="http://docs.php.net/manual/en/book.fileinfo.php" class="broken_link">Fileinfo</a> extension, the <a
href="http://docs.php.net/manual/en/book.intl.php" class="broken_link">INTL</a> extension), but it&#8217;s good that a language that&#8217;s been around for so long continues to get tweaked, even in minor ways. Makes you wonder what&#8217;s left for PHP 5.5, let alone 6, though?</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/05/09/whats-new-in-php-5-4/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Review of &#8220;Technical Blogging&#8221; by Antonio Cangiano</title><link>http://www.larryullman.com/2012/05/07/review-of-technical-blogging-by-antonio-cangiano/</link> <comments>http://www.larryullman.com/2012/05/07/review-of-technical-blogging-by-antonio-cangiano/#comments</comments> <pubDate>Mon, 07 May 2012 11:00:44 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[Web Development]]></category> <category><![CDATA[blog]]></category> <category><![CDATA[book]]></category> <category><![CDATA[reading]]></category> <category><![CDATA[wordpress]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3166</guid> <description><![CDATA[As part of my  (which really turned out to be February-March), I&#8217;ve been going through a stack of books, and a virtual stack of ebooks, that I&#8217;ve had lying around for way too long. One of the first books from that stack that I read was &#8220;Technical Blogging&#8220;, by Antonio Cangiano. I bought the ebook [...]]]></description> <content:encoded><![CDATA[<p>As part of my <a
href="http://www.larryullman.com/2012/01/03/my-january-2012-non-resolutions-list/">January-February 2012 downtime</a> (which really turned out to be February-March), I&#8217;ve been going through a stack of books, and a virtual stack of ebooks, that I&#8217;ve had lying around for way too long. One of the first books from that stack that I read was &#8220;<a
href="http://amzn.to/H6gFcE">Technical Blogging</a>&#8220;, by <a
href="http://antoniocangiano.com/">Antonio Cangiano</a>. I bought the ebook through <a
href="http://pragprog.com/">Pragmatic Programmer</a>&#8216;s Black Friday sale back in November, and it&#8217;s available through Pragmatic Programmer, or Amazon, of course. Overall, I was quite impressed with the book, and I think it&#8217;s going to help me a lot. Before I discuss the book in detail, a quick bit of perspective&#8230;<span
id="more-3166"></span></p><p>I started blogging relatively recently, about two or three years ago, I think. In retrospect, I&#8217;m not sure why I started blogging, as I had no game plan and no intent of making money from the blog. I suspect the impetus was supporting <a
href="http://www.larryullman.com/books/">my books</a>, but that&#8217;s probably as much as I thought about it. Eventually I added a single Amazon widget to my site, again as a way to promote my books. In part because of the success of my <a
href="http://www.larryullman.com/series/learning-the-yii-framework/">Learning the Yii Framework</a> series, I was surprised when I started getting decent traffic to my site, and making a bit of money through the Amazon widget. To be completely transparent about the money, I make around a few hundred dollars per year with the site set up as is. I&#8217;m not quitting my day job on that, but it is enough to pay for my hosting costs, as well as my <a
href="http://www.larryullman.com/newsletter/">monthly newsletter</a>, and my<a
href="http://www.larryullman.com/forums/"> forum</a> software. After seeing a mist of potential in this area, and with 2012 being the year of legitimizing much of my business, I read &#8220;Technical Blogging.&#8221;</p><p>Like any well written book, it&#8217;s well organized, broken down into five sequential parts:</p><ul><li>Part I — Plan It</li><li>Part II — Build It</li><li>Part III — Promote It</li><li>Part IV — Benefit from It</li><li>Part V — Scale It</li></ul><p>In my own situation, I had already done parts two and four on my own blog, without ever giving much thought to parts one and three. Clearly, it&#8217;s hard to know if your site is succeeding when you&#8217;ve established no goals for it! And while my primary goal is to sell more books, after reading just the first part, I was able to come up with other, more immediate and tangible goals.</p><p>The book&#8217;s structure is sound, but the strength of the book is this: <strong>lots of concrete, specific advice</strong>. The book has decent breadth in the topics it covers, but always provides exact recommendations. For example, in the <em>Build It</em> chapter, Mr. Cangiano talks about the software and hosting options, from using <a
href="http://wordpress.org">WordPress</a> to more geeky options like <a
href="http://jekyllbootstrap.com/">Jekyll</a>. After covering the range of options, you get specific advice:</p><blockquote><p>&#8220;Opt for a self-hosted WordPress installation if you are the kind of person who doesn’t mind dealing with a remote Linux box.&#8221;</p></blockquote><p>and</p><blockquote><p>&#8220;If you don’t have an IT background or would like to test the waters before committing to something&#8230; I recommend Blogger (from Google) due to&#8230;&#8221;</p></blockquote><p>This approach—presenting the options, with pros and cons, and then making recommendations—continues throughout the book, even when it comes to the money and statistics. Mr. Cangiano explicitly talks about the hits his sites get and is bravely honest about the income, too. He discusses, for example, the effectiveness of various social media sites, and how much he earns from ads vs. Amazon referrals vs. sponsorships. Providing the details, regardless of their personal nature, makes it really easy for the reader to make his or her own decisions. For example, I don&#8217;t have any ads on my site now (a la <a
href="http://www.google.com/adsense">AdSense</a>), which is very much my preference. But I was worried that I was missing out on good money because of this value of mine. Mr. Cangiano, in a table citing his monthly income for a given month, shows that AdSense accounted for only 3% of the total. Knowing that, Mr. Cangiano has saved me from going through all the hassle of integrating AdSense, bothering viewers with random ads, only to make a smidgen of money.</p><p>The area in which I learned the most is promoting the blog via social media and other avenues, such as <a
href="http://www.reddit.com">Reddit</a>. All marketing stuff is foreign to me, and I&#8217;m just finally getting involved with social media. In fact, I&#8217;m in the process of creating a new theme for my site, which will more prominently feature my social media connections (and, more importantly, give more space to the content itself). Over the summer I&#8217;ll work harder to implement the social media tools, and I&#8217;ve set some goals for where I&#8217;d like to be in a year from now.</p><p>All in all, I have literally seven pages of notes that I took while reading the book. And while I&#8217;ve only begun using this new-found knowledge, I have no doubt that what I learned from &#8220;<a
href="http://amzn.to/H6gFcE">Technical Blogging</a>&#8221; will pay off. If you do technical blogging as well, I would highly recommend it!</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/05/07/review-of-technical-blogging-by-antonio-cangiano/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to Write a Book &#8211; The Short Honest Truth by Scott Berkun</title><link>http://www.larryullman.com/2012/05/04/how-to-write-a-book-the-short-honest-truth-by-scott-berkun/</link> <comments>http://www.larryullman.com/2012/05/04/how-to-write-a-book-the-short-honest-truth-by-scott-berkun/#comments</comments> <pubDate>Fri, 04 May 2012 11:00:26 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[Uncategorized]]></category> <category><![CDATA[book]]></category> <category><![CDATA[writing]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3186</guid> <description><![CDATA[I&#8217;ve just recently become aware of Scott Berkun, thanks to catching an excerpt from his &#8220;Confessions of a Public Speaker&#8221; book. I&#8217;ve since read that book, and it was wonderful (more on that in a separate post). I&#8217;m now following Berkun on Twitter, where he frequently Tweets older posts. One of those that I found [...]]]></description> <content:encoded><![CDATA[<p>I&#8217;ve just recently become aware of <a
href="http://www.scottberkun.com">Scott Berkun</a>, thanks to catching an excerpt from his &#8220;<a
href="http://www.amazon.com/gp/product/1449301959/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=larrullm09-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1449301959">Confessions of a Public Speaker</a>&#8221; book. I&#8217;ve since read that book, and it was wonderful (more on that in a separate post). I&#8217;m now following Berkun on <a
href="https://twitter.com/#!/berkun">Twitter</a>, where he frequently Tweets older posts. One of those that I found to be particularly on the nose was &#8220;<a
href="http://www.scottberkun.com/blog/2007/how-to-write-a-book-the-short-honest-truth/ ">How to Write a Book- the Short, Honest Truth</a>&#8220;. I get asked about publishing a lot (and recently had a long email conversation about this, which I&#8217;ll also share separately), and thought Berkun&#8217;s posting is quite valuable on the subject.</p><p>In the post, Berkun distinguishes between three aspects of writing a book:</p><ul><li>Anyone can write a book (i.e., you can write one right now, without needing anything else)</li><li>Getting published (which is a separate issue from writing a book)</li><li>Becoming famous and wealthy</li></ul><p>I know there are some people that would like to write a book as an experience, or as a way of sharing what they&#8217;ve learned. And some others like the imagined prestige and riches that come with writing a book. I&#8217;ve done quite well over the past decade, having written 22 books and sold over 350,000 copies, but I can verify that the prestige and riches aren&#8217;t all that you might imagine (I <a
href="http://www.larryullman.com/2012/04/02/what-is-larry-thinking-53-writing-and-working/#qa">recently discussed the economics in a newsletter</a>). That being said, I&#8217;m quite happy that I&#8217;m making a decent living doing something that I always dreamed of doing. I&#8217;ve been working for myself for 13 years now, which is something.</p><p>In any case, if you&#8217;re interested in the topic, check out Berkun&#8217;s post. It&#8217;s short, and well written. At the bottom, you&#8217;ll find links to more good articles on writing, if you&#8217;re not too discouraged by that point! His &#8220;<a
href="http://www.scottberkun.com/blog/2010/why-you-fail-at-writing/">Why You Fail at Writing</a>&#8221; is pretty good for helping you accomplish that goal of writing a book.</p><p>If you have any questions you&#8217;d like to ask me about what it means to be a writer, just let me know!</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/05/04/how-to-write-a-book-the-short-honest-truth-by-scott-berkun/feed/</wfw:commentRss> <slash:comments>2</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>Passing Values by Reference in PHP 5</title><link>http://www.larryullman.com/2012/04/25/passing-values-by-reference-in-php-5/</link> <comments>http://www.larryullman.com/2012/04/25/passing-values-by-reference-in-php-5/#comments</comments> <pubDate>Wed, 25 Apr 2012 11:28:33 +0000</pubDate> <dc:creator>Larry</dc:creator> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://www.larryullman.com/?p=3189</guid> <description><![CDATA[Every other year or so, I go through the PHP manual. Often I do this in coordination with a book I&#8217;m about to write, like now, as I&#8217;m writing the . Generally, though, I&#8217;m a big advocate of re-reading manuals. It&#8217;s a great way to correct mistaken thinking you may have, and to learn new [...]]]></description> <content:encoded><![CDATA[<p>Every other year or so, I go through the <a
href="http://www.php.net/manual/">PHP manual</a>. Often I do this in coordination with a book I&#8217;m about to write, like now, as I&#8217;m writing the <a
href="http://www.larryullman.com/2012/04/09/php-5-advanced-visual-quickpro-guide-3rd-edition-table-of-contents/">third edition of my &#8220;PHP 5 Advanced&#8221; book</a>. Generally, though, I&#8217;m a big advocate of re-reading manuals. It&#8217;s a great way to correct mistaken thinking you may have, and to learn new and better approaches. For example, I just came across something that had previously slipped past me: the ability to change an <a
href="http://www.php.net/manual/en/language.types.array.php">array</a> within a foreach loop by passing values by reference.</p><p>In versions of PHP prior to 5, in order to change the values of array elements within a loop, you had to do this:</p><pre class="brush: php; title: ; notranslate">foreach ($array as $key =&gt; $value) {
    $array[$key] = &quot;some updated $value&quot;;
}</pre><p>Just changing the value of <strong>$value</strong> within that <strong>foreach</strong> loop had no impact on the actual array element, as the loop only received the value of each array element, not the actual element itself.</p><p>This doesn&#8217;t come up often—if I need to change the elements in an array, I&#8217;m likely to use <a
href="http://www.php.net/array_walk">array_walk()</a>, but it&#8217;s nice to know that in PHP 5 you can pass array values by reference in a <strong>foreach</strong> loop, so that changing the value within the loop actually changes the array:</p><pre class="brush: php; title: ; notranslate">foreach ($array as &amp;$value) {
    $value = &quot;some updated $value&quot;;
}</pre><p>As you can see there, prefacing <strong>$value</strong> by <strong>&amp;</strong> means that the variable is passed by reference, not by value, just as you&#8217;d have in a function parameter.</p><p>Again, perhaps this isn&#8217;t a life changing thing to learn (okay, it isn&#8217;t), but it&#8217;s interesting to know. As I continue to work my way through the PHP manual (again!), I&#8217;ll continue to share interesting little tidbits I&#8217;m finding, or discovering anew.</p> ]]></content:encoded> <wfw:commentRss>http://www.larryullman.com/2012/04/25/passing-values-by-reference-in-php-5/feed/</wfw:commentRss> <slash:comments>4</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> </channel> </rss>
<!-- Served from: www.larryullman.com @ 2012-05-21 13:50:37 by W3 Total Cache -->
