<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>Raymond Kolbe &#187; Cookbook</title>
	<atom:link href="http://www.raymondkolbe.com/category/computer-related/solar/cookbook/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.raymondkolbe.com</link>
	<description>Code, cars, and beer...</description>
	<lastBuildDate>Sun, 07 Feb 2010 17:14:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Solar e-mail helper that stops spammers</title>
		<link>http://www.raymondkolbe.com/2009/08/19/solar-e-mail-helper-that-stops-spammers/</link>
		<comments>http://www.raymondkolbe.com/2009/08/19/solar-e-mail-helper-that-stops-spammers/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 02:25:37 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[Solar]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=393</guid>
		<description><![CDATA[Tonight I created a helper for Solar that encodes mailto href addresses so SPAMers that scrape HTML pages will never get your addresses.
To use this helper, just do the following in your views/layouts:
echo $this-&#62;email('someuser@somehost.com', 'Ray');
Here is the helper code:
&#60;?php
/**
 * Generates an encoded mailto href to stop spammers from scrapping email
 * addresses from your [...]]]></description>
			<content:encoded><![CDATA[<p>Tonight I created a helper for Solar that encodes mailto href addresses so SPAMers that scrape HTML pages will never get your addresses.</p>
<p>To use this helper, just do the following in your views/layouts:</p>
<pre class="brush: php;">
echo $this-&gt;email('someuser@somehost.com', 'Ray');
</pre>
<p>Here is the helper code:</p>
<pre class="brush: php;">
&lt;?php
/**
 * Generates an encoded mailto href to stop spammers from scrapping email
 * addresses from your web pages.  This code is based on the PHP example
 * from http://rumkin.com/tools/mailto_encoder/
 *
 * @category Whitebox
 * @package Whitebox_View
 * @author Raymond J. Kolbe &lt;rkolbe@gmail.com&gt;
 */
class Whitebox_View_Helper_Email extends Solar_View_Helper {
    /**
     * The encoded email address.
     *
     * @var string
     */
    protected $_encoded_string = '';
    /**
     * The encoded index used to decode $_encoded_string/
     *
     * @var string
     */
    protected $_encoded_indexes = '';
    /**
     * Generates an encoded mailto href to stop spammers from
     * scrapping email addresses off your web pages.  Returns
     * an inline javascript code block that allows web browser
     * to read the mailto href.
     *
     * If javascript is disabled in the web browser, only the
     * link text is shown to the user.
     *
     * @param string $spec The email address (e.g. rkolbe@gmail.com)
     * @param string $text Href
     * @param array $attribs An array of href attributes
     * @return string An inline string of javascript to handle the
     * encoded mailto href
     */
    public function email($spec, $text = null, $attribs = null) {
        // escape the email address
        $spec = $this-&gt;_view-&gt;escape($spec);
        // build attribs, after dropping any 'href' attrib
        $attribs = (array) $attribs;
        unset($attribs['href']);
        $attribs = $this-&gt;_view-&gt;attribs($attribs);
        $this-&gt;_obfuscate(&quot;&lt;a href=\&quot;mailto:$spec\&quot;$attribs&gt;$text&lt;/a&gt;&quot;);
        $script = $this-&gt;_getScript();
        $script .= '&lt;noscript&gt;'.$text.'&lt;/noscript&gt;';
        return $script;
    }
    /**
     * Takes a given href and obfuscates it.
     *
     * @param string $link A full mailto href
     * @return void
     */
    protected function _obfuscate($link) {
        $scrambled_chars = str_shuffle($link);
        $this-&gt;_encoded_string = $this-&gt;_escapeString($scrambled_chars);
        $string_indexes = '';
        for ($i = 0; $i &lt; strlen($link); $i++) {
            $index = strpos($scrambled_chars, substr($link, $i, 1)) + 48;
            $string_indexes .= chr($index);
        }
        $this-&gt;_encoded_indexes = $this-&gt;_escapeString($string_indexes);
    }
    /**
     * Returns a block of javascript used to decode the mailto href.
     * This only allows web browsers to see the mailto address.
     *
     * @param void
     * @return string An inline block of javascript
     */
    protected function _getScript() {
        return $this-&gt;_view-&gt;scriptInline('&lt;!--
            chars = &quot;'.$this-&gt;_encoded_string.'&quot;;
            indexes = &quot;'.$this-&gt;_encoded_indexes.'&quot;;
            href = &quot;&quot;;
            for(j = 0; j &lt; indexes.length; j++){
                href += chars.charAt(indexes.charCodeAt(j) - 48);
            }
            document.write(href);
            // --&gt;');
    }
    /**
     * Prepares (escapes) a string for javascript.
     *
     * @param string $string The string to escape
     * @return string The escaped string
     */
    protected function _escapeString($string) {
        $string = str_replace(&quot;\\&quot;, &quot;\\\\&quot;, $string);
        $string = str_replace(&quot;\&quot;&quot;, &quot;\\\&quot;&quot;, $string);
        return $string;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2009/08/19/solar-e-mail-helper-that-stops-spammers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Table view helper it out!</title>
		<link>http://www.raymondkolbe.com/2009/07/25/table-view-helper-it-out/</link>
		<comments>http://www.raymondkolbe.com/2009/07/25/table-view-helper-it-out/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 17:00:15 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=390</guid>
		<description><![CDATA[Table view helper has been released!  Since my last post about writing a helper such as this, a lot has changed.  I hope to have API docs up soon. In the meantime you can download the code and check out the examples at its new project page.
]]></description>
			<content:encoded><![CDATA[<p>Table view helper has been released!  Since my last post about writing a helper such as this, a lot has changed.  I hope to have API docs up soon. In the meantime you can download the code and check out the examples at its new <a href="projects/table/">project page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2009/07/25/table-view-helper-it-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modifying Solar_View_Helper_Form</title>
		<link>http://www.raymondkolbe.com/2009/05/23/modifying-solar-view-helper-form/</link>
		<comments>http://www.raymondkolbe.com/2009/05/23/modifying-solar-view-helper-form/#comments</comments>
		<pubDate>Sat, 23 May 2009 18:34:57 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[Solar]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=221</guid>
		<description><![CDATA[Solar comes packed with many different view helpers that will make your life easier, such as inserting images, creating links, and generating forms.  However, sometimes a generic helper doesn&#8217;t cut it for custom behavior in a project.  For example, I wanted to change the way form field hints (field descriptions) and error messages [...]]]></description>
			<content:encoded><![CDATA[<p>Solar comes packed with many different <a href="http://solarphp.com/package/Solar_View">view helpers</a> that will make your life easier, such as <a href="http://solarphp.com/class/Solar_View_Helper_Image">inserting images</a>, <a href="http://solarphp.com/class/Solar_View_Helper_Href">creating links</a>, and <a href="http://solarphp.com/package/Solar_View_Helper_Form">generating forms</a>.  However, sometimes a generic helper doesn&#8217;t cut it for custom behavior in a project.  For example, I wanted to change the way form field hints (field descriptions) and error messages were displayed for the registration form at <a href="http://fahwebmon.white-box.us">http://fahwebmon.white-box.us</a>.  <strong>Note</strong> that I am using Solar_View_Helper_Form::auto() to generate my form automagically.  The only downside to this is that you do not have control over where errors are displayed on a page.</p>
<p><span id="more-221"></span></p>
<p>The default behavior of Solar_View_Helper_Form will output error messages like this:</p>
<p><img class="aligncenter size-full wp-image-234" title="default_behavior" src="http://white-box.us/wp-content/uploads/2009/05/default_behavior.jpg" alt="default_behavior" width="400" height="235" /></p>
<p>However, I had two things I needed to accomplish, 1) create form field hints that are displayed only when a text field is clicked, and 2) move all error messages to the top of the page.</p>
<p>Displaying the field hints was the easy part.  The form helper automatically adds in a class named &#8216;descr&#8217; to each field.  I decided to use this class name with a little jQuery (<a href="http://docs.jquery.com/Events/focus">focus</a> and <a href="http://docs.jquery.com/Events/blur">blur</a>) to accomplish my form hint behavior.</p>
<p>The issue I ran into was when the form had errors and a field containing a hint was displayed.</p>
<p><img class="aligncenter size-full wp-image-238" title="default_behavior_hint" src="http://white-box.us/wp-content/uploads/2009/05/default_behavior_hint.jpg" alt="default_behavior_hint" width="400" height="211" /></p>
<p>You can see that the hint should be aligned with the first text field, Username.  A little bit of Javascript and CSS manipulation could solve this problem but I wanted to consolidate the error messages to an eye catching location anyway, which in turn would solve my alignment issue.</p>
<p>Before I provide you with my solution, let me show you what the finished product looks like:</p>
<p><img class="aligncenter size-full wp-image-240" title="modified_behavior_hint" src="http://white-box.us/wp-content/uploads/2009/05/modified_behavior_hint.jpg" alt="modified_behavior_hint" width="400" height="206" /></p>
<p>You can see I have an eye catching error div at the top followed by the hint box being properly aligned.  I still need to implement either a) a red asterisk next to each invalid field or b) change the label colors to red.  I also need to update my error messages so they read proper.  Both of these minor changes are not solve in this blog post.  I&#8217;ll save that for a rainy day <img src='http://www.raymondkolbe.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><img class="alignright size-full wp-image-244" title="netbeans_screenshot" src="http://white-box.us/wp-content/uploads/2009/05/netbeans_screenshot.jpg" alt="netbeans_screenshot" width="151" height="144" />So, how did I do this?  I simply copied down Solar_View_Helper_Form from the Solar project to my working directory (Fahwebmon/View/Helper/Form.php) and renamed the class to Fahwebmon_View_Helper_Form.  <strong>Note</strong> that you don&#8217;t have to copy down the whole file.  You can create your own class and extend Solar_View_Helper_Form since we are only modifying the fetch() method on this class.</p>
<p>Here is the modified code.  <strong>Note</strong> that I have only tested this with text fields.</p>
<pre class="brush: php;">
public function fetch($with_form_tag = true)
{
// stack of output elements
$form = array();
$feedback = array();
// the form tag itself?
if ($with_form_tag) {
$form[] = '&lt;form' . $this-&gt;_view-&gt;attribs($this-&gt;_attribs) . '&gt;';
}
// what status class should we use?
if ($this-&gt;_status === true) {
$class = $this-&gt;_css_class['success'];
$feedback = $this-&gt;_feedback;
} elseif ($this-&gt;_status === false) {
$class = $this-&gt;_css_class['failure'];
} else {
$feedback = null;
$class = null;
}
// the hidden elements
if ($this-&gt;_hidden) {
// wrap in a hidden fieldset for XHTML-Strict compliance
$form[] = '    &lt;fieldset style=&quot;display: none;&quot;&gt;';
foreach ($this-&gt;_hidden as $info) {
$form[] = '        ' . $this-&gt;_view-&gt;formHidden($info);
}
$form[] = '    &lt;/fieldset&gt;';
$form[] = '    ';
}
// loop through the stack
$in_dl       = false;
$in_fieldset = false;
$in_group    = false;
foreach ($this-&gt;_stack as $key =&gt; $val) {
$type = $val[0];
$info = $val[1];
if ($type == 'element') {
// be sure we're in a &lt;dl&gt; block
if (! $in_dl) {
$form[] = '        &lt;dl&gt;';
$in_dl = true;
}
// setup
$label    = $this-&gt;_view-&gt;getText($info['label']);
$id       = $this-&gt;_view-&gt;escape($info['attribs']['id']);
$method   = 'form' . ucfirst($info['type']);
try {
// look for the requested element helper
$helper = $this-&gt;_view-&gt;getHelper($method);
} catch (Solar_Class_Stack_Exception_ClassNotFound $e) {
// use 'text' helper as a fallback
$method = 'formText';
$helper = $this-&gt;_view-&gt;getHelper($method);
}
// SPECIAL CASE:
// checkboxes that are not in groups don't get an &quot;extra&quot; label.
if (strtolower($info['type']) == 'checkbox' &amp;&amp; ! $in_group) {
$info['label'] = null;
}
// get the element output
$element = $helper-&gt;$method($info);
// get the element description
$dt_descr = '';
$dd_descr = '';
// only build a description if it's non-empty, and isn't a
// DESCR_* &quot;empty&quot; locale value.
if ($info['descr'] &amp;&amp; substr($info['descr'], 0, 6) != 'DESCR_') {
// build the base description.
// open the tag ...
$descr = &quot;&lt;&quot; . $this-&gt;_view-&gt;escape($this-&gt;_descr_tag);
// ... add a CSS class ...
if ($this-&gt;_descr_class) {
$descr .= ' class=&quot;'
. $this-&gt;_view-&gt;escape($this-&gt;_descr_class)
. '&quot;';
}
// ... add the raw descr XHTML, and close the tag.
$descr .= '&gt;' . $info['descr']
. '&lt;/' . $this-&gt;_view-&gt;escape($this-&gt;_descr_tag) . '&gt;';
// build both the &lt;dt&gt; and &lt;dd&gt; forms so we can use
// them in the right place.
if ($this-&gt;_descr_elem == 'dt') {
// using &lt;dt&gt;
$dt_descr = $descr;
} else {
// using &lt;dd&gt;
$dd_descr = $descr;
}
}
// add the element;
// handle differently if we're in a group.
if ($in_group) {
// add the element itself
$form[] = &quot;                $element&quot;;
} else {
$require = '';
// is the element required?
if ($info['require']) {
$require = ' class=&quot;' . $this-&gt;_css_class['require'] . '&quot;';
}
// add the form element with all parts in place
$form[] = &quot;            &lt;dt$require&gt;&lt;label$require for=\&quot;$id\&quot;&gt;$label&lt;/label&gt;$dt_descr&lt;/dt&gt;&quot;;
$form[] = &quot;            &lt;dd$require&gt;$element$dd_descr&lt;/dd&gt;&quot;;
$form[] = '';
}
// handle element feedback
if (!empty($info['invalid'])) {
foreach ($info['invalid'] as $invalid) {
$feedback[] = $label . ' ' . strtolower(substr($invalid, 0, 1) . substr($invalid, 1));
}
}
} elseif ($type == 'group') {
// be sure we're in a &lt;dl&gt; block
if (! $in_dl) {
$form[] = '        &lt;dl&gt;';
$in_dl = true;
}
$flag = $info[0];
$label = $info[1];
if ($flag) {
$in_group = true;
$form[] = &quot;            &lt;dt&gt;&lt;label&gt;$label&lt;/label&gt;&lt;/dt&gt;&quot;;
$form[] = &quot;            &lt;dd&gt;&quot;;
} else {
$in_group = false;
$form[] = &quot;            &lt;/dd&gt;&quot;;
$form[] = '';
}
} elseif ($type == 'fieldset') {
$flag = $info[0];
$legend = $this-&gt;_view-&gt;getText($info[1]);
if ($flag) {
$form[] = &quot;    &lt;fieldset&gt;&lt;legend&gt;$legend&lt;/legend&gt;&quot;;
$form[] = &quot;        &lt;dl&gt;&quot;;
$in_fieldset = true;
$in_dl = true;
} else {
$form[] = &quot;        &lt;/dl&gt;&quot;;
$form[] = &quot;    &lt;/fieldset&gt;&quot;;
$form[] = '';
$in_dl = false;
$in_fieldset = false;
}
}
}
if ($in_group) {
$form[] = '            &lt;/dd&gt;';
}
if ($in_dl) {
$form[] = '        &lt;/dl&gt;';
}
if ($in_fieldset) {
$form[] = '    &lt;/fieldset&gt;';
}
// add a closing form tag? This also determins where feedback should be.
if ($with_form_tag) {
// temporarily grab the open form tag and remove it from the array
$openFormTag = array_shift($form);
// add the form open tag and feedback
array_unshift($form, $openFormTag, $this-&gt;listFeedback($feedback, $class));
// finally add the closing form tag
$form[] = '&lt;/form&gt;';
} else {
// inject feedback as first element
array_unshift($form, $this-&gt;listFeedback($feedback, $class));
}
// reset for the next pass
$this-&gt;reset();
// done, return the output!
return implode(&quot;\n&quot;, $form);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2009/05/23/modifying-solar-view-helper-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BBCode PHP Syntax Highlighting For Lazy People</title>
		<link>http://www.raymondkolbe.com/2009/04/26/bbcode-php-syntax-highlighting-for-lazy-people/</link>
		<comments>http://www.raymondkolbe.com/2009/04/26/bbcode-php-syntax-highlighting-for-lazy-people/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 00:28:18 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=92</guid>
		<description><![CDATA[While working on one of my little side projects, I came across a problem where I wanted to highlight bbcode syle php tags in my text (e.g. [PHP] echo &#8220;code goes here&#8221;; [/PHP]).
Being lazy and using regex (I love it!), I came up with the following solution:
// test text w/embedded code
$text = &#34;This is a [...]]]></description>
			<content:encoded><![CDATA[<p>While working on one of my little side projects, I came across a problem where I wanted to highlight bbcode syle php tags in my text (e.g. [PHP] echo &#8220;code goes here&#8221;; [/PHP]).</p>
<p>Being lazy and using regex (I love it!), I came up with the following solution:</p>
<pre class="brush: php;">
// test text w/embedded code
$text = &quot;This is a sample text string with PHP style tags. [PHP] echo 'Hello'; [/PHP]
// and I made sure to make this case insensitive.
$pattern = &quot;/\[PHP\](.*)\[\/PHP\]/Uis&quot;;
// the magic!
$matchCount = preg_match_all($pattern, $text, $matches, PREG_SET_ORDER);
if ($matchCount !== false &amp;&amp; $matchCount &gt; 0) {
    foreach ($matches as $match) {
        // highlight_string forces us to start with at least the php opening tag
        $highlightedCode = highlight_string('&lt;?php'.$match[1].'?&gt;', true);
        // finally, replace the original non-highlighted text with the highlighted text
        $text = preg_replace($pattern, $highlightedCode, $text, 1);
    }
}
echo $text;
</pre>
<p>Just FYI, this was a quick one-off and wasn&#8217;t intended to scale with other bbcode style tags.  Also, in my real code, the [PHP] tags are lowercase.  The only reason they are uppercase is because the syntax highlighter in Wordpress isn&#8217;t smart enough to distinguish the tags in my code and tags to signify syntax highlighting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2009/04/26/bbcode-php-syntax-highlighting-for-lazy-people/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solar Cli</title>
		<link>http://www.raymondkolbe.com/2008/11/01/solar-cli/</link>
		<comments>http://www.raymondkolbe.com/2008/11/01/solar-cli/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 03:17:08 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[Solar]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=33</guid>
		<description><![CDATA[Overview
One of the nice things Solar has to offer is its CLI (Command Line Interface), which can be used to accomplish tasks that would otherwise eat up valuable time, such as creating applications, models, tests, documentation, and unit tests. In this entry, I will be showing you how to use the current (Solar v1.0.0 alpha2) [...]]]></description>
			<content:encoded><![CDATA[<h2>Overview</h2>
<p>One of the nice things Solar has to offer is its CLI (Command Line Interface), which can be used to accomplish tasks that would otherwise eat up valuable time, such as creating applications, models, tests, documentation, and unit tests. In this entry, I will be showing you how to use the current (Solar v1.0.0 alpha2) CLI, detailing commands, available options, parameters, and usage examples. So make sure that you have a fresh pot of coffee and let&#8217;s get to it!</p>
<p><span id="more-33"></span></p>
<h2>First Glance</h2>
<p>Under a <a href="http://solarphp.com/project/download">Solar system</a> you will find an executable called <code>solar</code>, located in the script directory. For our example, let&#8217;s assume our Solar system is installed under /var/www/solar/. You will find the executable under the directory /var/www/solar/script/.</p>
<p>From the terminal, change directories to /var/www/solar/. Let&#8217;s go ahead and run the <code>solar</code> executable and examine what is returned.</p>
<pre class="brush: plain;">
$ ./script/solar
Using include_path '.:..:/var/www/solar/include'.
Using config file '/var/www/solar/config/Solar.config.php'.
Solar command-line tool.
Usage: solar &lt;command&gt; &lt;options&gt; &lt;params&gt;
Try 'solar help' for a list of commands.
</pre>
<p>Here we can see what our include paths are, as well as the configuration file we are using. In a Solar system, Solar defaults to using Solar.config.php, the default configuration file.</p>
<p>You will also notice that the Solar CLI gives you the proper syntax to use, <code>solar &#060command&#062 &#060options&#062 &#060params&#062</code>. This is important so keep it in mind as we go along <img src='http://www.raymondkolbe.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  For now, let&#8217;s jump to the most basic command and the most helpful, <code>help</code>.</p>
<h3>Help command</h3>
<p>We can learn more about any command in the CLI by using the <code>help</code> command. The syntax for this is <code>solar help &#060command&#062</code> where <em>command</em> is the command we want to know more about. We can also get a list of available commands by typing <code>solar help</code>. Let&#8217;s give that a try, shall we?</p>
<pre class="brush: plain;">
$ ./script/solar help
Using include_path '.:..:/var/www/solar/include'.
Using config file '/var/www/solar/config/Solar.config.php'.
Solar command-line tool.
Usage: solar &lt;command&gt; &lt;options&gt; &lt;params&gt;
Try 'solar help &lt;command&gt;' for help on a specific command.
Available commands are:
    base
    help
    make-app
    make-docs
    make-model
    make-tests
    make-vendor
    run-tests
</pre>
<p>Here are all of our available commands. You can ignore the base command since this is just the command in which all other commands extend and is of no value to us here.</p>
<p>Here is a quick break down of each command.</p>
<ul>
<li><strong>base</strong> &#8211; Base class in which all commands extend. Not usable from the CLI!</li>
<li><strong>help</strong> &#8211; Returns command usage or a list of available commands.</li>
<li><strong>make-app</strong> &#8211; Generates a basic application or an application with <a href="http://paul-m-jones.com/?p=291">BREAD</a> functionality.</li>
<li><strong>make-docs</strong> &#8211; Generates package and API documentation files.</li>
<li><strong>make-model</strong> &#8211; Generates a model class from an SQL table.</li>
<li><strong>make-tests</strong> &#8211; Generates a test class (or set of classes) from a given class.</li>
<li><strong>make-vendor</strong> &#8211; Creates the appropriate directories and symlinks for a new project (also referred to as a vendor space).</li>
<li><strong>run-tests</strong> &#8211; Runs a series of tests or a single test.</li>
</ul>
<p>Please note that all commands have the following available options:</p>
<ul>
<li><strong>&#8211;config</strong> &#8211; Allows you to use a specific configuration file. Default is Solar.config.php.</li>
<li><strong>-V | &#8211;version</strong> &#8211; Returns version information.</li>
<li><strong>-v | &#8211;verbose</strong> &#8211; Displays verbose output when available.</li>
</ul>
<p>Now that we have a general idea of the available commands and proper syntax, let&#8217;s talk about each one in depth.</p>
<h2>Make-app</h2>
<p>Make-app allows you to rapidly generate a simple generic application or a more complex application that supports BREAD functionality on the fly.</p>
<h3>Help information</h3>
<pre class="brush: plain;">
$ ./script/solar help make-app
Using include_path '.:..:/var/www/solar/include'.
Using config file '/var/www/solar/config/Solar.config.php'.
No help is available for this command.
Valid options for this command are...
--config
:  Use this configuration file when starting Solar.
--extends
:  Extends from this class name.
--model
:  Add this model class automatically.
--target
:  The target directory, typically the PEAR directory.
-V | --version
:  Display version information and exit.
-v | --verbose
:  Display verbose output when available.
</pre>
<h3>Available options</h3>
<p><strong>Extends</strong><br />
The name of the class that we want to extend. This is handy if you are using a base class in which all applications extend. Currently defaults to Solar_App_Base.</p>
<p><strong>Model</strong><br />
Solar can auto generate an application with BREAD functionality when you specify a model to use. This adds functionality for browsing, reading, editing, adding, and deleting records from the database.</p>
<p><strong>Target</strong><br />
Allows you to specify the target directory to generate the given application. Not needed if you are using a Solar system.</p>
<h3>Available params</h3>
<p><strong>Class</strong><br />
The class name. This is required. An example would be Vendor_App_Blog.</p>
<h3>Usage examples</h3>
<p>Let&#8217;s say we want to create a simple application that will extend our page controller (Solar_Controller_Page). <em>For the examples that follow, our project will be named &#8220;Vendor.&#8221;</em></p>
<pre class="brush: plain;">
$ ./script/solar make-app --extends=Solar_Controller_Page Vendor_App_Hello
</pre>
<p>This generates a basic application named <em>Hello</em>. If you change your working directory to /var/www/solar/source/Vendor/App/Hello/ you should have the following structure:</p>
<ul>
<li>/Hello/Helper/</li>
<li>/Hello/Layout/</li>
<li>/Hello/Locale/</li>
<li>/Hello/Locale/en_US.php</li>
<li>/Hello/View/</li>
<li>/Hello/View/index.php</li>
<li>/Hello.php</li>
</ul>
<p>Now, let&#8217;s kick it up a notch and generate an application that uses an existing model. In this case, we want an application called <em>Blog</em>, for blog posts. The model we are using is called <em>Posts</em> since blogs usually contain posts. In this example I am assuming that the model <em>Posts</em> has already been created.</p>
<pre class="brush: plain;">
$ ./script/solar make-app --extend=Solar_Controller_Page --model=Vendor_Model_Posts Vendor_App_Blog
</pre>
<p>This will create all of the actions and views for browsing, reading, editing, adding, and deleting blog posts from the database.</p>
<p>Here are the generated files and directories, found under /var/www/solar/source/Vendor/App/Blog/.</p>
<ul>
<li>/Blog/Helper/</li>
<li>/Blog/Layout/</li>
<li>/Blog/Locale/</li>
<li>/Blog/Locale/en_US.php</li>
<li>/Blog/View/</li>
<li>/Blog/View/add.php</li>
<li>/Blog/View/browse.php</li>
<li>/Blog/View/delete.php</li>
<li>/Blog/View/edit.php</li>
<li>/Blog/View/read.php</li>
<li>/Blog/View/_record.php</li>
<li>/Blog.php</li>
</ul>
<h2>Make-docs</h2>
<p>Make-docs allows you to quickly turn your inline comments into solid documentation, like <a href="http://www.phpdoc.org/">phpDocumentor</a>.</p>
<h3>Help information</h3>
<pre class="brush: plain;">
$ ./script/solar help make-docs
Using include_path '.:..:/var/www/solar/include'.
Using config file '/var/www/solar/config/Solar.config.php'.
No help is available for this command.
Valid options for this command are...
--class-dir
:  Write class API docs to this directory.
--config
:  Use this configuration file when starting Solar.
--package-dir
:  Write package docs to this directory.
--source
:  The source directory, typically the PEAR directory.
-V | --version
:  Display version information and exit.
-v | --verbose
:  Display verbose output when available.
</pre>
<h3>Available options</h3>
<p><strong>Class-dir</strong><br />
The directory where class API documentation will be written to.</p>
<p><strong>Package-dir</strong><br />
The directory where package documentation will be written to.</p>
<p><strong>Source-dir</strong><br />
The directory where your project lives. Given the example we have been working with, this would be /var/www/solar/source/vendor/.</p>
<h3>Available params</h3>
<p><strong>Class</strong><br />
The class name. This is required. An example would be Vendor_App_Blog.</p>
<h3>Usage examples</h3>
<p>Let&#8217;s say we have an application called <em>Blog</em> and we wanted to generate documentation for it. It is as easy as doing the following.</p>
<pre class="brush: plain;">
$ ./script/solar make-docs --class-dir=/var/www/solar/source/vendor/docs/ --package-dir=/var/www/solar/source/vendor/docs/ --source=/var/www/solar/source/vendor/ Vendor_App_Blog
</pre>
<p>If you take a look at the <em>docs</em> directory, /var/www/solar/source/vendor/docs/, you will see a file and a folder with the same name, Vendor_App_Blog. The file in this directory contains the package information and the directory contains many files, each file containing information about each relevant method for our application.</p>
<h2>Make-model</h2>
<p>Make-model reduces the time it takes to set up models, which can be very time consuming to setup by hand. Make-model streamlines this process by reading your existing SQL table and creating the model based off of this information.</p>
<h3>Help information</h3>
<pre class="brush: plain;">
$ ./script/solar help make-model
Using include_path '.:..:/var/www/solar/include'.
Using config file '/var/www/solar/config/Solar.config.php'.
No help is available for this command.
Valid options for this command are...
--adapter
:  The SQL adapter class to use.
--config
:  Use this configuration file when starting Solar.
--connect
:  Connect to the database and fetch cols for the model setup.
--extends
:  Extend the model class from this parent class name.
--host
:  The host for the database connection.
--name
:  The name of the database to connect to.
--pass
:  The password for the database connection.
--port
:  The port for the database connection.
--table
:  The table name for the model to use.
--target
:  Write files to this directory, typically the include directory.
--user
:  The username for the database connection.
-V | --version
:  Display version information and exit.
-v | --verbose
:  Display verbose output when available.
</pre>
<h3>Available options</h3>
<p><strong>Adapter</strong><br />
The SQL adapter to use. Examples include <a href="http://solarphp.com/class/Solar_Sql_Adapter_Mysql">Solar_Sql_Adapter_Mysql</a> and <a href="http://solarphp.com/class/Solar_Sql_Adapter_Sqlite">Solar_Sql_Adapter_Sqlite</a>.</p>
<p><strong>Connect</strong><br />
If set to true, Solar connects to the SQL table to generate the model to reflect the columns in the table.</p>
<p><strong>Extends</strong><br />
The name of the class that we want to extend. Defaults to Solar_Sql_Model.</p>
<p><strong>Host</strong><br />
The host where the database resides (e.g. localhost).</p>
<p><strong>Name</strong><br />
Name of the database to connect to.</p>
<p><strong>Pass</strong><br />
Password to be used with user name.</p>
<p><strong>Port</strong><br />
Port that our database is running on.</p>
<p><strong>Table</strong><br />
Table name we want to create our model for and from.</p>
<p><strong>User</strong><br />
User name that has access to the database table.</p>
<h3>Available params</h3>
<p><strong>Class</strong><br />
The class name. This is required. An example would be Vendor_App_Blog.</p>
<h3>Usage examples</h3>
<p>Now, this is where using a configuration file makes life easy. First though, I am going to show you the (more time consuming) way to generate a model without changing your current (default) configuration file.</p>
<p>Just so I do not lose you, let me specify the basic settings I am using for my database.</p>
<ul>
<li>Database type: MySQL</li>
<li>Database name: vendor</li>
<li>Host: localhost</li>
<li>User name: root</li>
<li>Password: s3cr3tP@ssw0rd</li>
</ul>
<p>Now let&#8217;s generate a model that controls blog posts. The name of this model will be <em>posts</em>. The table layout we will be using looks like this:</p>
<ul>
<li>id (primary key, auto increment)</li>
<li>title (varchar(100))</li>
<li>body (text)</li>
<li>author (varchar(100))</li>
<li>created (datetime)</li>
<li>updated (datetime)</li>
</ul>
<p>For the lazy people reading this, you can just run the following MySQL to generate the table.</p>
<pre class="brush: plain;">
CREATE TABLE posts(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
    title VARCHAR(100),
    body VARCHAR(100),
    author VARCHAR(100),
    created DATETIME,
    updated DATETIME
) engine=INNODB
</pre>
<p>Now on to generating our model for posts (the long way).</p>
<pre class="brush: plain;">
$ ./source/solar make-model --adapter=Solar_Sql_Adapter_Mysql --connect=true --host=localhost --name=vendor --pass=s3cr3tP@ssw0rd --table=posts --user=root Vendor_Model_Posts
</pre>
<p>That is all there is to it. You can see the files generated by changing directories to /var/www/solar/source/vendor/Vendor/Model/. Here you will see the following layout.</p>
<ul>
<li>/Posts.php</li>
<li>/Posts/Collection.php</li>
<li>/Posts/Record.php</li>
<li>/Posts/Setup</li>
<li>/Posts/Setup/table_cols.php</li>
<li>/Posts/Setup/table_name.php</li>
</ul>
<p>Now, the easy way to generate models is to save your database connection information to your configuration file. Go ahead and open up Solar.config.php, located under the directory /var/www/solar/config/.</p>
<p>Add the following to the configuration file.</p>
<pre class="brush: php;">
$config['Solar_Sql']['adapter'] = 'Solar_Sql_Adapter_Mysql';
$config['Solar_Sql_Adapter_Mysql'] = array(
    'host' = 'localhost',
    'user' = 'root',
    'pass' = 's3cr3tP@ssw0rd',
    'name' = 'vendor',
);
</pre>
<p>Now, when we want to generate a model, we only need to do the following.</p>
<pre class="brush: plain;">
$ ./script/solar make-model --table=posts Vendor_Model_Posts
</pre>
<h2>Make-tests</h2>
<p>Make-tests is great for generating a single set or suite of tests that can (and should) be altered to test your classes.</p>
<h3>Help information</h3>
<pre class="brush: plain;">
$ ./script/solar help make-tests
Using include_path '.:..:/var/www/solar/include'.
Using config file '/var/www/solar/config/Solar.config.php'.
No help is available for this command.
Valid options for this command are...
--config
:  Use this configuration file when starting Solar.
--only
:  Make tests only for the named class; do not descend into subdirectories.
--target
:  Where the tests will be written to.
-V | --version
:  Display version information and exit.
-v | --verbose
:  Display verbose output when available.
</pre>
<h3>Available options</h3>
<p><strong>Only</strong><br />
Make tests only for the specified class (e.g. Vendor_App_Blog only).</p>
<p><strong>Target</strong><br />
The directory where the test files will be saved to. Defaults to the <em>tests</em> directory, /var/www/solar/source/vendor/tests/ for our example(s).</p>
<h3>Available params</h3>
<p><strong>Class</strong><br />
The class name. This is required. An example would be Vendor_App_Blog.</p>
<h3>Usage examples</h3>
<p>To generate a suite of tests for your classes, you need only to specify the <code>target</code> to save the tests to and the class in which you want to generate the tests for.</p>
<pre class="brush: plain;">
$ ./script/solar make-tests --target=/var/www/solar/source/vendor/tests/ Vendor_App_Blog
</pre>
<p>We are left with the the following directory structure under the <em>tests</em> directory, /var/www/solar/source/vendor/tests/.</p>
<ul>
<li>/Test/Vendor/</li>
<li>/Test/Vendor/App/</li>
<li>/Test/Vendor/App/Blog.php</li>
</ul>
<p>At this point you will want to edit <em>Blog.php</em> to edit the predefined tests for your class.</p>
<p>If you only need to generate a test for a specific class and you do not want to recursively create tests, issue the <em>only</em> option.</p>
<pre class="brush: plain;">
$ ./script/solar make-tests --only=true --target=/var/www/solar/source/vendor/tests/ Vendor_App_Blog
</pre>
<h2>Make-vendor</h2>
<p>Make-vendor generates the most basic vendor space for a new project. Before any application, model, etc. can be created, a vendor must be created.</p>
<h3>Help information</h3>
<pre class="brush: plain;">
$ ./script/solar help make-vendor
Using include_path '.:..:/var/www/solar/include'.
Using config file '/var/www/solar/config/Solar.config.php'.
No help is available for this command.
Valid options for this command are...
--config
:  Use this configuration file when starting Solar.
-V | --version
:  Display version information and exit.
-v | --verbose
:  Display verbose output when available.
</pre>
<h3>Available options</h3>
<p>None</p>
<h3>Available params</h3>
<p><strong>Name</strong><br />
The vendor name. This is required. An example could be <em>Vendor</em>.</p>
<h3>Usage examples</h3>
<p>To create a new vendor, simply do the following.</p>
<pre class="brush: plain;">
$ ./script/solar make-vendor Vendor
</pre>
<p>The following directories are generated.</p>
<ul>
<li>/source/vendor/bin/</li>
<li>/source/vendor/docs/</li>
<li>/source/vendor/tests/</li>
<li>/source/vendor/Vendor/App/</li>
<li>/source/vendor/Vendor/App/Public/</li>
<li>/source/vendor/Vendor/App/Public/images/</li>
<li>/source/vendor/Vendor/App/Public/scripts/</li>
<li>/source/vendor/Vendor/App/Public/styles/</li>
<li>/source/vendor/Vendor/Model/</li>
<li>/source/vendor/Vendor/Locale/</li>
<li>/source/vendor/Vendor/View/</li>
<li>/source/vendor/Vendor/View/Helper/</li>
</ul>
<p>And the following symlinks (*nix only) are made.</p>
<ul>
<li>/source/vendor/Vendor/ to /include/Vendor</li>
<li>/source/vendor/Vendor/App/Public/ to /docroot/public/Vendor/</li>
<li>/source/solar/bin/solar to /script/vendor</li>
</ul>
<h2>Run-tests</h2>
<p>Run-tests allows you to run the tests generated by <code>make-tests</code>.</p>
<h3>Help information</h3>
<pre class="brush: plain;">
$ ./script/solar help run-tests
Using include_path '.:..:/var/www/solar/include'.
Using config file '/var/www/solar/config/Solar.config.php'.
No help is available for this command.
Valid options for this command are...
--config
:  Use this configuration file when starting Solar.
--dir
:  The path to the tests directory.
--only
:  Run only the named test class; do not descend into subclass tests.
-V | --version
:  Display version information and exit.
-v | --verbose
:  Display verbose output when available.
</pre>
<h3>Available options</h3>
<p><strong>Dir</strong><br />
The directory where the tests are held.</p>
<p><strong>Only</strong><br />
Run a specific test class without descending into subclass tests.</p>
<h3>Available params</h3>
<p>None</p>
<h3>Usage examples</h3>
<p>In the usage example for <code>make-tests</code> shown above, we created a test class for our Blog application, Vendor_App_Blog. If we wanted to run this test all we would have to do is the following.</p>
<pre class="brush: plain;">
$ ./script/solar run-tests --dir=/var/www/solar/source/vendor/tests/
</pre>
<p>Note that if there are other tests in the <em>tests</em> directory those will be run as well. If we only want to run a specific test we would use the <code>only</code> option.</p>
<pre class="brush: plain;">
$ ./script/solar --dir=/var/www/solar/source/vendor/tests/Test/Vendor/App/Blog.php --only=true
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2008/11/01/solar-cli/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Virtual hosts and multiple Solar projects</title>
		<link>http://www.raymondkolbe.com/2008/09/27/virtual-hosts-and-multiple-solar-projects/</link>
		<comments>http://www.raymondkolbe.com/2008/09/27/virtual-hosts-and-multiple-solar-projects/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 02:42:42 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[Solar]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=31</guid>
		<description><![CDATA[In the first part of the series, Big Bang with Solar, I showed you how to download and install Solar for a single project. What I didn&#8217;t show you is a way to set up Solar for multiple virtual hosts under Apache, which is what I will be showing you today in our example.
For our [...]]]></description>
			<content:encoded><![CDATA[<p>In the first part of the series, <a href="http://white-box.us/2008/09/25/big-bang-with-solar-part-1/">Big Bang with Solar</a>, I showed you how to download and install Solar for a single project. What I didn&#8217;t show you is a way to set up Solar for multiple <a href="http://httpd.apache.org/docs/2.2/vhosts/">virtual hosts</a> under Apache, which is what I will be showing you today in our example.</p>
<p>For our example we will use the fictional web sites polygon-ex.com and square-ex.com. <em>If these sites actually exist I apologize in advance for using the names without permission&#8230;please forgive me <img src='http://www.raymondkolbe.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </em></p>
<p><span id="more-31"></span></p>
<h2>Configuring Apache</h2>
<p>Let&#8217;s start by creating two new configuration files for Apache. These configuration files will hold information pertaining to our virtual hosts.</p>
<pre class="brush: plain;">
$ cd /etc/httpd/conf.d/
$ touch polygon-ex.conf
$ touch square-ex.conf
</pre>
<p>Before we edit these files, let&#8217;s create the directories for each web site under /var/www.</p>
<pre class="brush: plain;">
$ cd /var/www
$ mkdir polygon-ex
$ mkdir square-ex
</pre>
<p>Now we can edit our configuration files. Let&#8217;s start with polygon-ex.com.</p>
<pre class="brush: plain;">
$ nano /etc/httpd/conf.d/polygon-ex.conf
</pre>
<p>To define the virtual host you will want something like the following.</p>
<pre class="brush: plain;">
&lt;virtualHost *:80&gt;
    ServerName polygon-ex.com
    DocumentRoot /var/www/polygon-ex/docroot
    &lt;directory /&gt;
        AllowOverride All
    &lt;/directory&gt;
&lt;/virtualHost&gt;
</pre>
<p><em>Note that you need to have &#8220;NameVirtualHost *:80&#8243; in your main httpd.conf file, most likely located at /etc/httpd/conf/httpd.conf, in order for virtual hosts to work. See <a href="http://httpd.apache.org/docs/2.2/vhosts/name-based.html#using">Using Name-based Virtual Hosts</a> in Apache&#8217;s documentation for more information regarding this.</em></p>
<p><em>Note that I have opted for <a href="http://httpd.apache.org/docs/2.2/vhosts/name-based.html">name-based virtual hosting</a> instead of <a href="http://httpd.apache.org/docs/2.2/vhosts/ip-based.html">IP-based</a>.</em></p>
<p><em>Note the line AllowOverride All. I have set very loose access here for example purposes only. Please refer to Apache&#8217;s wonderful documentation on the <a href="http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride">AllowOverride Directive</a> so you are not compromising the security of your server.</em></p>
<p>Now do the same for square-ex.conf but change the ServerName and DocumentRoot information to coincide with square-ex.com.</p>
<p>Last but not least, restart Apache.</p>
<pre class="brush: plain;">
$ /etc/init.d/httpd restart
</pre>
<h2>Obtaining and extracting Solar</h2>
<p>If you haven&#8217;t downloaded <a href="http://svn.solarphp.com/system/download/solar-system-1.0.0alpha2.tgz">solar-system-1.0.0alpha2.tgz</a> already, go do so now.</p>
<p>Change your working directory to where you saved solar-system-1.0.0alpha2.tgz and do the following.</p>
<pre class="brush: plain;">
$ tar -zxvf solar-system-1.0.0alpha2.tgz -C /var/www/polygon-ex
$ tar -zxvf solar-system-1.0.0alpha2.tgz -C /var/www/square-ex
</pre>
<p>Now if you change your working directory to /var/www/polygon-ex or /var/www/square-ex you will see a folder called &#8220;solar&#8221; under each. We do not want to keep the directory set up like this, since we want Solar to be installed at the root of our virtual host.</p>
<p>To correct this we just move some files around.</p>
<pre class="brush: plain;">
$ cd /var/www/polygon-ex/
$ mv ./solar/* ./
$ rm -Rf ./solar/
</pre>
<p>And for square-ex.</p>
<pre class="brush: plain;">
$ cd /var/www/square-ex/
$ mv ./solar/* ./
$ rm -Rf ./solar/
</pre>
<p>What we just did here, was move the contents of the &#8220;solar&#8221; directory up a level. We also removed the now empty &#8220;solar&#8221; directory that is no longer needed. Now our Apache configuration file will be able to find the directory &#8220;docroot.&#8221;</p>
<p>One last thing before we move on. We need to change the permissions of our /tmp folder within our project directories so that our pre-configured Solar project can read/write PHP sessions to our sessions folder (located at /var/www/polygon-ex/tmp/session and /var/www/square-ex/tmp/session).</p>
<pre class="brush: plain;">
$ cd /var/www/polygon-ex
$ chmod -R 777 ./tmp/
$ cd /var/www/square-ex
$ chmod -R 777 ./tmp/
</pre>
<h2>Testing it all out</h2>
<p>Now how do we know this all works? Well, let&#8217;s test it! First and foremost, since polygon-ex.com and square-ex.com are not real domains, we must enter them into our &#8220;hosts&#8221; file so we can resolve the domain name. Let&#8217;s do that now.</p>
<pre class="brush: plain;">
$ nano /etc/hosts
</pre>
<p>Your hosts file may look like the following.</p>
<pre class="brush: plain;">
127.0.0.1 localhost.localdomain localhost
</pre>
<p>We want to change it to look like this.</p>
<pre class="brush: plain;">
127.0.0.1 localhost.localdomain localhost polygon-ex.com square-ex.com
</pre>
<p>Go ahead and open up your web browser and point it to http://polygon-ex.com or http://square-ex.com. You should see &#8220;Hello World!&#8221; on each page.</p>
<p>If you are not convinced that each project is associated with its own domain then let&#8217;s step it up a bit and edit one of the Hello World examples.</p>
<pre class="brush: plain;">
$ nano /var/www/polygon-ex/source/solar/Solar/App/Hello/View/index.php
</pre>
<p>Change the text to read.</p>
<pre class="brush: plain;">
Hello World! - Welcome to polygon-ex.com!
</pre>
<p>Save and close that file and refresh http://polygon-ex.com in your web browser. You should now see the text we just entered. Now browse on over to http://square-ex.com and you will just see &#8220;Hello World!&#8221;</p>
<p>Ta da! You just setup two virtual hosts that use Solar. Now go explore Solar by visiting <a href="http://solarphp.com">SolarPHP.com</a> and don&#8217;t forget to join us on the <a href="http://solarphp.com/project/mailing-list">mailing list and/or in the IRC channel</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2008/09/27/virtual-hosts-and-multiple-solar-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big Bang with Solar &#8211; Part 1</title>
		<link>http://www.raymondkolbe.com/2008/09/25/big-bang-with-solar-part-1/</link>
		<comments>http://www.raymondkolbe.com/2008/09/25/big-bang-with-solar-part-1/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 00:13:16 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[Solar]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=29</guid>
		<description><![CDATA[So you have read the manual and browsed the Solar wiki. Now you want to get your hands dirty with setting up your own project. Good news, you&#8217;ve found the right place. In this series, I plan to show you, step-by-step, how to set up your very own project using Solar.
To make sure we stay [...]]]></description>
			<content:encoded><![CDATA[<p>So you have read the <a href="http://solarphp.org/manual">manual</a> and browsed the <a href="http://solarphp.org/">Solar wiki</a>. Now you want to get your hands dirty with setting up your own project. Good news, you&#8217;ve found the right place. In this series, I plan to show you, step-by-step, how to set up your very own project using Solar.</p>
<p>To make sure we stay on track, here is the scope for part 1 of the series.</p>
<ul>
<li>Download and Install Solar</li>
<li>Determine our project guidelines</li>
<li>Configure Apache using Virtual Hosts</li>
<li>Set up our bootstrap and configuration file</li>
<li>Create a &#8220;Hello World&#8221; example application</li>
</ul>
<p><span id="more-29"></span></p>
<h2>Required before starting</h2>
<p>There are a few prerequisites that must be addressed before we can begin. At a minimum, you must have PHP and MySQL installed on a Linux based system for this tutorial.</p>
<p>The system I am working with consists of the following:</p>
<ul>
<li>Fedora 9</li>
<li>Apache 2.2</li>
<li>MySQL 5.x</li>
<li>PHP 5.2.6</li>
</ul>
<p>My directory structure for Apache is as follows:</p>
<ul>
<li>/var/www/ &#8211; Apache directory</li>
<li>/var/www/html/ &#8211; Apache docroot (viewable on the web)</li>
<li>/etc/httpd/conf.d/ &#8211; Apache&#8217;s configuration directory</li>
</ul>
<p>If your structure does not look similar, you may be running a different OS or version of Apache. Please refer to your distribution&#8217;s manual for more information.</p>
<h2>Solar system install</h2>
<p>I will be working with Solar &#8220;system&#8221;, an all-in-one Solar package if you will, which includes Solar &#8220;core&#8221;, also known as the Solar framework. The main difference between &#8220;core&#8221; and &#8220;system&#8221; is that &#8220;core&#8221; is the standalone Solar framework whereas &#8220;system&#8221; contains &#8220;core&#8221; but also sets up your environment for development (directory structure). For more information, please refer to the <a href="http://solarphp.com/project/download">Solar download page</a> and the manual page on <a href="http://solarphp.org/manual:getting_started:skeleton_system">Skeleton System</a>. Remember, we are working with Solar &#8220;system&#8221;.</p>
<p>For the install, download <a href="http://svn.solarphp.com/system/download/solar-system-1.0.0alpha2.tgz">solar-system-1.0.0alpha2.tgz</a> to /var/www. Once the download is complete do the following:</p>
<pre class="brush: plain;">
$ cd /var/www
$ tar -zxvf solar-system-1.0.0alpha2.tgz
</pre>
<p>Solar is now installed at /var/www/solar. Now we want to set some folder permissions.</p>
<pre class="brush: plain;">
$ chmod -R 777 /var/www/solar/tmp
$ chmod -R 777 /var/www/solar/sqlite
</pre>
<p>The directory &#8220;tmp&#8221; includes a place to store cached files, PHP sessions, and log files. The directory &#8220;sqlite&#8221; only needs permissions to be set if you plan on using <a href="http://www.sqlite.org/">SQLite</a>. For our project I will be using MySQL.</p>
<p>Congrats! You have just installed Solar!</p>
<h2>Project guidelines</h2>
<p>Before we jump into setting up our project, let&#8217;s first start by figuring out what we want develop. My vote goes to something simple and practical. A blog!</p>
<p>Next, let&#8217;s outline our basic blog. What functions will our blog have? In this case, I want to keep things simple, so our blog will have the following functionality.</p>
<ul>
<li>Blog posts</li>
<li>Categories for posts</li>
<li>Tags for posts</li>
<li>Comments submitted by users</li>
<li>Users that can submit posts</li>
</ul>
<p>Lastly, we need a project name. I&#8217;m going to opt for &#8220;Bloggo.&#8221; Not very elegant or original, but you get the idea (Pardon me if I am infringing on any name brand sites out there&#8230;eek!).</p>
<h2>Setting up Apache</h2>
<p>We are getting closer to creating our first app, trust me! Before we get there though, we need to setup our Apache configuration and bootstrap file to coincide with our project.</p>
<p>Let&#8217;s get to it! First, let&#8217;s create the configuration file and edit it.</p>
<p><em>Note that I am using &#8220;su&#8221; to become root. This is because my normal user account does not have access to edit this file. You will see this throughout the tutorial. However, your credentials may differ and you need to be aware of this.</em></p>
<pre class="brush: plain;">
$ su
Password:
# touch /etc/httpd/conf.d/bloggo.conf
# nano /etc/httpd/conf.d/bloggo.conf
</pre>
<p>We want to add the following into our bloggo.conf file. As you can see here we are using <a href="http://httpd.apache.org/docs/2.0/vhosts/name-based.html">Name-based Virtual Hosts</a>. Since my server does not have a top level domain name, I am using localhost as the host name. Please see Apache&#8217;s <a href="http://httpd.apache.org/docs/2.0/vhosts/name-based.html">Virtual Host</a> documentation for more information.</p>
<pre class="brush: plain;">
NameVirtualHost *:80
&lt;virtualHost *:80&gt;
    ServerName localhost
    DocumentRoot /var/www/solar/docroot
    &lt;directory /&gt;
        AllowOverride All
    &lt;/directory&gt;
&lt;/virtualHost&gt;
</pre>
<p>Save and close our bloggo.conf file.</p>
<p>Let&#8217;s restart Apache.</p>
<pre class="brush: plain;">/etc/init.d/httpd restart</pre>
<p>If Apache did not throw any errors then we can move on. If you did receive errors, please review your .conf file.</p>
<h2>Basic configuration file</h2>
<p>Moving right along to our configuration file. Solar comes with a default configuration file so there isn&#8217;t much we need to do. However, some of the info contained in the default configuration file will need to be removed for our project. Go ahead and open up the default configuration file:</p>
<pre class="brush: plain;">
$ cd /var/www/solar
$ nano ./config/Solar.config.php
</pre>
<p>We will be editing the configuration file a bit as the project grows. For now, let&#8217;s specify the minimum parameters needed. You will need to edit your configuration file so it looks like the code below:</p>
<p><em>For more information on Solar&#8217;s configuration file syntax and use, see the <a href="http://solarphp.org/manual:solar:config_file">Solar Manual on Config File</a>.</em></p>
<pre class="brush: php;">
&lt;?php
/**
 * all config values go in this array, which
 * will be returned at the end of this script
 */
$config = array();
/**
 * system and autoload-include directories
 */
$system = dirname(dirname(__FILE__));
$config['Solar']['system'] = $system;
/**
 * ini_set values
 */
$config['Solar']['ini_set'] = array(
    'error_reporting' =&gt; (E_ALL | E_STRICT),
    'display_errors'  =&gt; true,
    'html_errors'     =&gt; true,
    'session.save_path' =&gt; &quot;$system/tmp/session/&quot;,
    'date.timezone'   =&gt; 'UTC',
);
/**
 * base action href
 */
$config['Solar_Uri_Action']['path'] = '/';
/**
 * base public directory href
 */
$config['Solar_Uri_Public']['path'] = '/public';
/**
 * front controller
 */
$config['Solar_Controller_Front'] = array(
    'classes' =&gt; array('Bloggo_App'),
    'disable' =&gt; array('base'),
    'default' =&gt; 'hello',
    'routing' =&gt; array(),
);
/**
 * done!
 */
return $config;
</pre>
<p>As you can see we are going to display PHP and HTML errors to the web browser. We only want to do this in a development environment. Once the project migrates to a production environment we would set these values to <em>false</em>.</p>
<h2>Creating a new project</h2>
<p>Ok, now that we got that out of the way, let&#8217;s create our project&#8217;s workspace, or vendor space, by using Solar&#8217;s built in CLI (command line interface).</p>
<pre class="brush: plain;">
$ ./script/solar make-vendor Bloggo
</pre>
<p>This will create all of the directories and symlinks needed for the most basic project. Your project&#8217;s structure is held under /var/www/solar/source/bloggo. You will also notice that we now have a &#8220;bloggo&#8221; executable under /var/www/solar/script. This is here in case you want to create your own CLI scripts.</p>
<p><em>Creating CLI scripts will not be covered in this series. For more information please see the Solar documentation on <a href="http://solarphp.com/class/Solar_Controller_Command/Overview">CLI</a> or examples under /var/www/solar/source/solar/Solar/Cli.</em></p>
<h2>Creating our first application &#8211; Hello</h2>
<p>Although this is somewhat covered in the manual under <a href="http://solarphp.org/manual:getting_started:skeleton_app">Getting Started &#8211; Skeleton App</a>, what isn&#8217;t covered is using the CLI to generate an application. What we about to do here is create the most basic application ever &#8211; &#8220;Hello World.&#8221;</p>
<p><em>The &#8220;Hello World&#8221; application will not be in our final project. I just want you to become a bit more familiar with the CLI and what files and directories are generated when making an application.</em></p>
<p>To create our application, let&#8217;s do the following from the terminal.</p>
<pre class="brush: plain;">
$ ./script/solar make-app Bloggo_App_Hello --extends=Solar_Controller_Page
</pre>
<p>You can also get a list of available commands from Solar by typing:</p>
<pre class="brush: plain;">
$ ./script/solar help
</pre>
<p>And you can see what available parameters there are for a specific command by typing:</p>
<pre class="brush: plain;">
$ ./script/solar help &lt;command&gt;
</pre>
<p>Let&#8217;s go take a look at what Solar generated. All applications for our project are housed under /var/www/solar/source/bloggo/Bloggo/App</p>
<p>You should have the following directory structure:</p>
<ul>
<li>/Hello/</li>
<li>/Hello/Helper/</li>
<li>/Hello/Layout/</li>
<li>/Hello/Locale/</li>
<li>/Hello/Locale/en_US.php</li>
<li>/Hello/View/</li>
<li>/Hello/View/index.php</li>
<li>/Hello.php</li>
</ul>
<p><em>For more information on the directory structure and what each directory is for, please see the App Directory Setup section under the <a href="http://solarphp.org/manual:getting_started:skeleton_app">Minimal Application Skeleton</a> page in the manual.</em></p>
<p><em>You will also see the directory /Public/ at the same level as our /Base/ directory. Note that this was not created when we created our &#8220;Hello World&#8221; application but rather when we created our Bloggo project.</em></p>
<p>Go ahead and open up Hello.php&#8230;go on&#8230;do it. You will see the following:</p>
<pre class="brush: php;">
&lt;?php
/**
 *
 * Generic application.
 *
 */
class Bloggo_App_Hello extends Solar_Controller_Page {
   /**
    *
    * The default action when no action is specified.
    *
    * @var string
    *
    */
   protected $_action_default = 'index';
   /**
    *
    * Generic index action.
    *
    * @return void
    *
    */
   public function actionIndex()
   {
   }
}
</pre>
<p>Pretty slick, huh? Now if you browse to http://localhost you should see a page with the text &#8220;Welcome to your new app.&#8221;</p>
<p><em>You can also access the Hello application by browsing to http://localhost/hello.</em></p>
<p>Now let&#8217;s go ahead and remove our &#8220;Hello World&#8221; application.</p>
<pre class="brush: plain;">
$ rm -Rf /var/www/solar/source/bloggo/Bloggo/App/Hello*
</pre>
<p>The next part of this series will jump into creating our first model and application (posts).</p>
<p>Until then, I urge you to join the <a href="http://solarphp.com/project/mailing-list">Solar mailing list and/or IRC channel</a> and start getting involved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2008/09/25/big-bang-with-solar-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SolarPHP authentication using MySQL</title>
		<link>http://www.raymondkolbe.com/2008/09/24/solarphp-authentication-using-mysql/</link>
		<comments>http://www.raymondkolbe.com/2008/09/24/solarphp-authentication-using-mysql/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 16:34:54 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[Solar]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=28</guid>
		<description><![CDATA[This post is an extension to SolarPHP&#8217;s current manual page on User Authentication and is intended for folks that already have a project setup using the SolarPHP framework. What I hope to accomplish here is to show you how to setup user authentication using MySQL and SolarPHP, something the Solar manual currently does not show [...]]]></description>
			<content:encoded><![CDATA[<p>This post is an extension to SolarPHP&#8217;s current manual page on <a href="http://solarphp.org/manual:getting_started:user_authentication">User Authentication</a> and is intended for folks that already have a project setup using the SolarPHP framework. What I hope to accomplish here is to show you how to setup user authentication using MySQL and SolarPHP, something the Solar manual currently does not show you how to do. What I do not cover here is setting up the login box for your project. The login box itself comes packaged with the Solar framework and will appear on your project page if you do not change the default layout.</p>
<p>Resources related to this tutorial can be found on the last page.</p>
<p><span id="more-28"></span></p>
<h2>Getting Started &#8211; Your configuration file</h2>
<p>First, we want to setup our configuration file to tell Solar to use the MySQL adapter so we can establish a connection to the database. For more information on how to setup a configuration file please reference <a href="http://solarphp.org/manual:solar:config_file">SolarPHP&#8217;s manual</a>.</p>
<p>[PHP]<br />
<?php<br />
$config = array();</p>
<p>// Front controller HREF prefix<br />
$config['Solar_Uri_Action']['path'] = '/index.php';</p>
<p>// Public directory HREF prefix<br />
$config['Solar_Uri_Public']['path'] = '/public';</p>
<p>// Specify our SQL adapter<br />
$config['Solar_Sql'] = array(<br />
    'adapter' => &#8216;Solar_Sql_Adapter_Mysql&#8217;,<br />
);</p>
<p>/*<br />
 *<br />
 * SQL adapter information<br />
 *<br />
 * `host` : Host that houses our database.<br />
 * `user` : User name that has access to the database.<br />
 * `pass` : Associated password with the user name.<br />
 * `name` : Name of the database we are connecting to.<br />
 *<br />
 */<br />
$config['Solar_Sql_Adapter_Mysql'] = array(<br />
    &#8216;host&#8217; => &#8216;localhost&#8217;,<br />
    &#8216;user&#8217; => &#8216;root&#8217;,<br />
    &#8216;pass&#8217; => &#8216;myS3cR37p@ssw0rd&#8217;,<br />
    &#8216;name&#8217; => &#8216;MyProject&#8217;,<br />
);</p>
<p>// Done!<br />
return $config;<br />
?><br />
[/PHP]</p>
<h2>MySQL table creation</h2>
<p>Next, we want to create the table that will hold our user information. At this point I am assuming that you have already created your database and the proper credentials associated with it. *Note the created and updated columns. I have thrown these in here for later use not covered in this post. You can leave these two columns out if you want.</p>
<p>[CODE]<br />
#<br />
# Basic user table layout<br />
#<br />
# name : Real name of our user.<br />
# handle : User name used to login with.<br />
# password : MD5 hash will be stored here.<br />
# created : Timestamp when the row was added.<br />
# updated: Timestamp when the row was modified.<br />
#<br />
CREATE TABLE users(<br />
id INT NOT NULL AUTO_INCREMENT,<br />
PRIMARY KEY(id),<br />
    name VARCHAR(255),<br />
    handle VARCHAR(255),<br />
    password VARCHAR(32),<br />
    created DATETIME,<br />
    updated DATETIME<br />
)<br />
[/CODE]</p>
<h2>Back to the configuration file &#8211; Setting up the authentication</h2>
<p>Now that we have our users table, we want to jump back into our configuration file and tell Solar to use the SQL adapter for authentication. This is what our final configuration file will look like.</p>
<p>[PHP]<br />
<?php<br />
$config = array();</p>
<p>// Front controller HREF prefix<br />
$config['Solar_Uri_Action']['path'] = '/index.php';</p>
<p>// Public directory HREF prefix<br />
$config['Solar_Uri_Public']['path'] = '/public';</p>
<p>// Specify our SQL adapter<br />
$config['Solar_Sql'] = array(<br />
    'adapter' => &#8216;Solar_Sql_Adapter_Mysql&#8217;,<br />
);</p>
<p>/*<br />
 *<br />
 * SQL adapter information<br />
 *<br />
 * `host` : Host that houses our database.<br />
 * `user` : User name that has access to the database.<br />
 * `pass` : Associated password with the user name.<br />
 * `name` : Name of the database we are connecting to.<br />
 *<br />
 */<br />
$config['Solar_Sql_Adapter_Mysql'] = array(<br />
    &#8216;host&#8217; => &#8216;localhost&#8217;,<br />
    &#8216;user&#8217; => &#8216;root&#8217;,<br />
    &#8216;pass&#8217; => &#8216;myS3cR37p@ssw0rd&#8217;,<br />
    &#8216;name&#8217; => &#8216;MyProject&#8217;,<br />
);</p>
<p>// Specify our authentication adapter<br />
$config['Solar_Auth'] = array(<br />
    &#8216;adapter&#8217; => &#8216;Solar_Auth_Adapter_Sql&#8217;,<br />
);</p>
<p>/*<br />
 *<br />
 * Authentication adapter information<br />
 *<br />
 * `table` : MySQL table holding our user information.<br />
 * `handle_col` : Specify the column for the user&#8217;s handle.<br />
 * `passwd_col` : Specify the column for the user&#8217;s password.<br />
 *<br />
 */<br />
$config['Solar_Auth_Adapter_Sql'] = array(<br />
    &#8216;table&#8217; => &#8216;users&#8217;,<br />
    &#8216;handle_col&#8217; => &#8216;handle&#8217;,<br />
    &#8216;passwd_col&#8217; => &#8216;password&#8217;,<br />
);</p>
<p>// Done!<br />
return $config;<br />
?><br />
[/PHP]</p>
<h2>Done! &#8211; Conclusion and additional resources</h2>
<p>That&#8217;s it! It really is that simple to change your authentication source from using a .htpasswd file to using MySQL. If any of you got lost in the process, please reference the materials below. If you are still stuck, please join the <a href="http://solarphp.com/project/mailing-list">SolarPHP mailing list and/or IRC channel</a> and post up <img src='http://www.raymondkolbe.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<ul>
<li><a href="http://solarphp.org/manual">Solar Manual</a> &#8211; The official SolarPHP manual.</li>
<li><a href="http://solarphp.org/manual:solar:config_file">Config File Help</a> &#8211; Working with SolarPHP&#8217;s configuration file.</li>
<li><a href="http://solarphp.com/class/Solar_Sql">Solar_Sql</a> and <a href="http://solarphp.com/class/Solar_Sql_Adapter_Mysql">Solar_Sql_Adapter_Mysql</a>- API references</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2008/09/24/solarphp-authentication-using-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
