<?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>Query7 &#187; php</title>
	<atom:link href="http://query7.com/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://query7.com</link>
	<description>PHP, Javascript, Python and Web Development</description>
	<lastBuildDate>Sat, 25 Jun 2011 21:29:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Kohana 3.1 Wiki Tutorial Routes</title>
		<link>http://query7.com/kohana-3-1-wiki-tutorial-routes</link>
		<comments>http://query7.com/kohana-3-1-wiki-tutorial-routes#comments</comments>
		<pubDate>Mon, 16 May 2011 07:39:43 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=1655</guid>
		<description><![CDATA[<p>In the original <a href="http://query7.com/kohana-3-1-wiki-tutorial">Kohana wiki application</a> the URLs in the views were hardcoded. If we wanted to change the domain name or restructure a route we would need to go through the application and change every single URL.</p>
<p>Thankfully the Kohana <em>Route</em> class comes with a method <em>url()</em> which allows us to generate URLs to routes we have specified in the application. In the first <a href="http://query7.com/kohana-3-1-wiki-tutorial">tutorial</a> we defined the following routes in <strong>application/bootstrap.php</strong>:</p>
<pre>Route::set('wiki-edit', 'wiki/&#60;page&#62;/edit')
	-&#62;defaults(array(
		'controller'=> 'wiki',
		'action'	=> 'edit_page',
	));

Route::set('wiki-save', 'wiki/&#60;page&#62;/save')
	-&#62;defaults(array(
		'controller'=> 'wiki',
		'action'	=> 'save_page',
	));

Route::set('wiki-page', 'wiki/&#60;page&#62;')
	-&#62;defaults(array(
		'controller'=> 'wiki',
		'action'	=> 'view_page',
	));

Route::set('default', 'wiki')
	-&#62;defaults(array(
		'controller' => 'wiki',
		'action'     => 'view_page',
		'id'		 => 'index',
	));
</pre>
<p>Before we can generate routes we need to set some configuration options in <strong>application/bootstrap.php</strong> (line ~82). We need to specify the <em>base_url</em> and <em>index_file</em> attributes in the array passed to <em>Kohana::init()</em>. The application on my local install is located at 127.0.0.1/query7kwiki/index.php, so my <em>Kohana::init()</em> statement would read:</p>
<pre>Kohana::init(array(
	'base_url'   =&#62; '/query7kwiki/',
	'index_file' =&#62; 'index.php'
));</pre>
<p>In <strong>application/views/edit.php</strong> the form <em>action</em> attribute was hardcoded to the value <em>/query7kwiki/index.php/wiki/</em>. That can be replaced by:</p>
<pre>&#60;?php echo Route::url('wiki-save', array('page' =&#62; $page)); ?&#62;</pre>
<p>In <strong>application/views/single.php</strong> there is a&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>In the original <a href="http://query7.com/kohana-3-1-wiki-tutorial">Kohana wiki application</a> the URLs in the views were hardcoded. If we wanted to change the domain name or restructure a route we would need to go through the application and change every single URL.</p>
<p>Thankfully the Kohana <em>Route</em> class comes with a method <em>url()</em> which allows us to generate URLs to routes we have specified in the application. In the first <a href="http://query7.com/kohana-3-1-wiki-tutorial">tutorial</a> we defined the following routes in <strong>application/bootstrap.php</strong>:</p>
<pre>Route::set('wiki-edit', 'wiki/&lt;page&gt;/edit')
	-&gt;defaults(array(
		'controller'=> 'wiki',
		'action'	=> 'edit_page',
	));

Route::set('wiki-save', 'wiki/&lt;page&gt;/save')
	-&gt;defaults(array(
		'controller'=> 'wiki',
		'action'	=> 'save_page',
	));

Route::set('wiki-page', 'wiki/&lt;page&gt;')
	-&gt;defaults(array(
		'controller'=> 'wiki',
		'action'	=> 'view_page',
	));

Route::set('default', 'wiki')
	-&gt;defaults(array(
		'controller' => 'wiki',
		'action'     => 'view_page',
		'id'		 => 'index',
	));
</pre>
<p>Before we can generate routes we need to set some configuration options in <strong>application/bootstrap.php</strong> (line ~82). We need to specify the <em>base_url</em> and <em>index_file</em> attributes in the array passed to <em>Kohana::init()</em>. The application on my local install is located at 127.0.0.1/query7kwiki/index.php, so my <em>Kohana::init()</em> statement would read:</p>
<pre>Kohana::init(array(
	'base_url'   =&gt; '/query7kwiki/',
	'index_file' =&gt; 'index.php'
));</pre>
<p>In <strong>application/views/edit.php</strong> the form <em>action</em> attribute was hardcoded to the value <em>/query7kwiki/index.php/wiki/</em>. That can be replaced by:</p>
<pre>&lt;?php echo Route::url('wiki-save', array('page' =&gt; $page)); ?&gt;</pre>
<p>In <strong>application/views/single.php</strong> there is a link to the edit that specific page. We can replace the <em>href</em> of the anchor tag with:</p>
<pre>&lt;?php echo Route::url('wiki-edit', array('page' =&gt; $page)); ?&gt;</pre>
<p>In the view <strong>application/views/create.php</strong> change the <em>href</em> of the create page link to:</p>
<pre>&lt;?php echo Route::url('wiki-edit', array('page' =&gt; $page)); ?&gt;</pre>
<p>The wiki application is now portable and can safely be moved to a different server without functionality breaking.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/kohana-3-1-wiki-tutorial-routes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kohana 3.1 Wiki Tutorial</title>
		<link>http://query7.com/kohana-3-1-wiki-tutorial</link>
		<comments>http://query7.com/kohana-3-1-wiki-tutorial#comments</comments>
		<pubDate>Mon, 09 May 2011 06:09:52 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=1632</guid>
		<description><![CDATA[<p>In this tutorial you will learn how to create a simple wiki using the PHP framework Kohana version 3.1. Several years ago Siddharta Govindaraj created a <a href="http://showmedo.com/videotutorials/video?name=1100000&#038;fromSeriesID=110">screencast</a> demonstrating how to create a wiki using Django, this is essentially the Kohana version of that. It covers using Kohana&#8217;s Routing, ORM and MVC systems. Full source code of the application is available on <a href="https://github.com/lastkarrde/query7kwiki">github</a>.</p>
<p>The wiki application has 3 different pages: </p>
<ul>
<li>/wiki/somepage/save &#8211; handles the saving of the page</li>
<li>/wiki/somepage/edit &#8211; displays a form that allows the user to edit the page</li>
<li>/wiki/somepage &#8211; displays the page</li>
</ul>
<h3>Configuration</h3>
<p>We will be using the ORM module to query the database for our wiki pages so we must load it in the <strong>application/bootstrap.php</strong> file (Line ~99).</p>
<pre>Kohana::modules(array(

	'database'   => MODPATH.'database',   // Database access
	'orm'        => MODPATH.'orm',        // Object Relationship Mapping

	));</pre>
<p>We also need to specify our database configuration settings. This is done in <strong>application/config/database.php</strong>.</p>
<pre>&#60;?php

return array
  (
  	'default' => array
  	(
  		'type'       => 'mysql',
  		'connection' => array(
  			'hostname'   => '127.0.0.1',
  			'username'   => 'root',
  			'password'   => 'root',
  			'persistent' => FALSE,
  			'database'   => 'query7kwiki',
  		),
  		'table_prefix' => '',
  		'charset'      => 'utf8',
  		'caching'      => FALSE,
  		'profiling'    => TRUE,
  	),
  );</pre><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>In this tutorial you will learn how to create a simple wiki using the PHP framework Kohana version 3.1. Several years ago Siddharta Govindaraj created a <a href="http://showmedo.com/videotutorials/video?name=1100000&#038;fromSeriesID=110">screencast</a> demonstrating how to create a wiki using Django, this is essentially the Kohana version of that. It covers using Kohana&#8217;s Routing, ORM and MVC systems. Full source code of the application is available on <a href="https://github.com/lastkarrde/query7kwiki">github</a>.</p>
<p>The wiki application has 3 different pages: </p>
<ul>
<li>/wiki/somepage/save &#8211; handles the saving of the page</li>
<li>/wiki/somepage/edit &#8211; displays a form that allows the user to edit the page</li>
<li>/wiki/somepage &#8211; displays the page</li>
</ul>
<h3>Configuration</h3>
<p>We will be using the ORM module to query the database for our wiki pages so we must load it in the <strong>application/bootstrap.php</strong> file (Line ~99).</p>
<pre>Kohana::modules(array(

	'database'   => MODPATH.'database',   // Database access
	'orm'        => MODPATH.'orm',        // Object Relationship Mapping

	));</pre>
<p>We also need to specify our database configuration settings. This is done in <strong>application/config/database.php</strong>.</p>
<pre>&lt;?php

return array
  (
  	'default' => array
  	(
  		'type'       => 'mysql',
  		'connection' => array(
  			'hostname'   => '127.0.0.1',
  			'username'   => 'root',
  			'password'   => 'root',
  			'persistent' => FALSE,
  			'database'   => 'query7kwiki',
  		),
  		'table_prefix' => '',
  		'charset'      => 'utf8',
  		'caching'      => FALSE,
  		'profiling'    => TRUE,
  	),
  );

  ?&gt;</pre>
<h3>Model</h3>
<p>Compared to most ORMs (Django, Doctrine, Propel), Kohana&#8217;s ORM is relatively light. You don&#8217;t need to specify the fields of your table as the Kohana ORM doesn&#8217;t attempt to generate the tables for you. It simply maps attribute names of the model object to field names in the database table. Be sure to check the <a href="http://kohanaframework.org/3.1/guide/">Kohana Documentation</a> for a detailed explanation of the ORM.</p>
<p><strong>application/classes/model/page.php</strong></p>
<pre>class Model_Page extends ORM
{

	protected $_table_name = 'page';

	public function rules()
	{
		return array(

			'title' => array(
						array('not_empty')
							)

		);
	}

}</pre>
<p>Execute the following SQL:</p>
<pre>CREATE TABLE `page` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NOT NULL ,
`content` TEXT NOT NULL
) ENGINE = MYISAM ;</pre>
<h3>Routing</h3>
<p>I define all routes at the bottom of <strong>application/bootstrap.php</strong>, however if you are working on a large application it may beneficial in the long run to define them in a separate file and then include them into the bootstrap file.</p>
<p><em>Route::set()</em> accepts 2 parameters. The first is the name of the route and the second is the URI pattern it should match. Because <em>Route::set()</em> returns an instance of <em>Kohana_Route</em>, we can chain the <em>defaults</em> method onto it. There we specify the controller and action that should be executed if the route is matched. </p>
<p>The <em>&lt;page&gt;</em> section of the URI pattern is captured from the URI and automatically passed to the controller method as an argument.</p>
<pre>Route::set('wiki-edit', 'wiki/&lt;page&gt;/edit')
	-&gt;defaults(array(
		'controller'=> 'wiki',
		'action'	=> 'edit_page',
	));

Route::set('wiki-save', 'wiki/&lt;page&gt;/save')
	-&gt;defaults(array(
		'controller'=> 'wiki',
		'action'	=> 'save_page',
	));

Route::set('wiki-page', 'wiki/&lt;page&gt;')
	-&gt;defaults(array(
		'controller'=> 'wiki',
		'action'	=> 'view_page',
	));

Route::set('default', 'wiki')
	-&gt;defaults(array(
		'controller' => 'wiki',
		'action'     => 'view_page',
		'id'		 => 'index',
	));
</pre>
<h3>Views</h3>
<p><strong><a href="http://query7.com/kohana-3-1-wiki-tutorial-routes">Read this tutorial on generating domain-independent, non hardcoded URLs</a></strong></p>
<p><strong>application/views/single.php</strong></p>
<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;&lt;?php echo $page; ?&gt;&lt;/title&gt;
	&lt;/head&gt;

	&lt;body&gt;

		&lt;h1&gt;&lt;?php echo $page; ?&gt;&lt;/h1&gt;
		&lt;p&gt;
			&lt;?php echo $content; ?&gt;
		&lt;/p&gt;
		&lt;hr&gt;
		&lt;p&gt;
			&lt;a href=&quot;/query7kwiki/index.php/wiki/&lt;?php echo $page; ?&gt;/edit&quot;&gt;Edit&lt;/a&gt;
		&lt;/p&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>application/views/create.php</strong></p>
<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;&lt;?php echo $page; ?&gt; - Create&lt;/title&gt;
	&lt;/head&gt;

	&lt;body&gt;

		&lt;h1&gt;&lt;?php echo $page; ?&gt;&lt;/h1&gt;
		&lt;p&gt;This page does not exist. &lt;a href=&quot;/query7kwiki/index.php/wiki/&lt;?php echo $page; ?&gt;/edit/&quot;&gt;Create?&lt;/a&gt;&lt;/p&gt;

	&lt;/body&gt;
&lt;/html&gt;</pre>
<p><strong>application/views/edit.php</strong></p>
<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;&lt;?php echo $page; ?&gt; - Edit&lt;/title&gt;
	&lt;/head&gt;

	&lt;body&gt;

		&lt;h1&gt;&lt;?php echo $page; ?&gt; - Edit&lt;/h1&gt;
		&lt;p&gt;
			&lt;form method=&quot;POST&quot; action=&quot;/query7kwiki/index.php/wiki/&lt;?php echo $page; ?&gt;/save/&quot;&quot;&gt;

				&lt;textarea rows=&quot;10&quot; cols=&quot;60&quot; name=&quot;content&quot;&gt;&lt;?php echo $content; ?&gt;&lt;/textarea&gt;
				&lt;br /&gt;
				&lt;input type=&quot;submit&quot; value=&quot;Edit Page&quot; name=&quot;submit&quot;&gt;
			&lt;/form&gt;
		&lt;/p&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre>
<h3>Controller</h3>
<p>The wiki only has one controller, <em>Controller_Wiki</em>, located in <strong>application/classes/controller/wiki.php</strong>. All of the methods accept one parameter, the name of the page which is automatically passed by the URL Router.</p>
<p>The <em>action_view_page()</em> method will display the wiki page if it exists or a &#8216;create&#8217; page if it does not exist. <em>$single-&gt;loaded()</em> will return true if the ORM returned a result, so if the page exists we load the &#8216;single&#8217; view and attach the appropriate variables to the view, if it does not exist then we load the &#8216;create&#8217; view.</p>
<pre>public function action_view_page($page)
{

	$single = ORM::factory('page')
			-&gt;where('title', '=', $page)
			-&gt;find();

	if($single->loaded())
	{
		$v = View::factory('single');
		$v-&gt;page = $page;
		$v-&gt;content = $single-&gt;content;
				}
	else
	{
		$v = View::factory('create');
		$v-&gt;page = $page;
	}

	$this-&gt;response-&gt;body($v);

}</pre>
<p><em>action_edit_page()</em> returns the &#8216;edit&#8217; page with the correct <em>content</em> field.</p>
<pre>public function action_edit_page($page)
{
	$single = ORM::factory('page')
			-&gt;where('title', '=', $page)
			-&gt;find();

	if($single-&gt;loaded())
	{
		$content = $single-&gt;content;
	}
	else
	{
		$content = '';
	}

	$v = View::factory('edit');
	$v-&gt;page = $page;
	$v-&gt;content = $content;

	$this-&gt;response-&gt;body($v);
}</pre>
<p><em>action_save_page()</em> handles saving the page after the user submits the edit form. It first checks to see if the page exists. If it does exist then we update the <em>content</em> attribute of the model with whatever was posted in the form. If it doesn&#8217;t exist then we make a new page by instantiating a new model, assigning the <em>title</em> and <em>content</em> attributes and saving it.</p>
<pre>public function action_save_page($page)
{
	$single = ORM::factory('page')
			-&gt;where('title', '=', $page)
			-&gt;find();

	$content = $this-&gt;request-&gt;post('content');

	if($single-&gt;loaded())
	{
		$single-&gt;content = $content;
		$single-&gt;save();
	}
	else
	{
		$new_single = new Model_Page();
		$new_single-&gt;title = $page;
		$new_single-&gt;content = $content;
		$new_single-&gt;save();
	}

	$this-&gt;request-&gt;redirect('http://127.0.0.1/query7kwiki/index.php/wiki/' . $page);

}</pre>
<p>Full source code of the application is available on <a href="https://github.com/lastkarrde/query7kwiki">Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/kohana-3-1-wiki-tutorial/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Twig Template Wrapper</title>
		<link>http://query7.com/php-twig-template-wrapper</link>
		<comments>http://query7.com/php-twig-template-wrapper#comments</comments>
		<pubDate>Mon, 02 May 2011 05:21:25 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://query7.com/?p=1587</guid>
		<description><![CDATA[<h3>Requirements</h3>
<ul>
<li><a href="https://github.com/fabpot/twig">Twig</a> downloaded and unarchived</li>
<li><a href="http://www.twig-project.org/doc/intro.html#basic-api-usage">Twig Autoloader</a> registered</li>
</ul>
<h3>Template Class</h3>
<p>The use of the <em>Settings</em> class is self explanatory. Just replaces the instances of <em>Settings</em> with your own configuration system (or just strings). All Twig settings are documented <a href="http://www.twig-project.org/doc/api.html#environment-options">here</a>.</p>
<pre>class Template
{

	public $context = array();

	private $template;

	public function __construct($template)
	{		

		$loader = new Twig_Loader_Filesystem(Settings::get('template_directories'));

		$twig = new Twig_Environment($loader, array(

			'cache' => Settings::get('template_cache_directory'),
			'debug' => Settings::get('debug'),

				)

		);

		$this->template = $twig->loadTemplate($template);

	}

	public function setContext(array $context = array())
	{
		$this->context = array_merge($context, $this->context);

	}

	public function render()
	{
		return $this->template->render($this->context);
	}	

	public function __toString()
	{
		return $this->render();
	}

	public function __set($key, $val)
	{
		$this->context[$key] = $val;
	}

	public function __get($key)
	{
		return $this->context[$key];
	}

}</pre>
<h3>Simple Example</h3>
<p><strong>hello.html</strong></p>
<pre>Hey there &#60;strong&#62;{{ name }}&#60;/strong&#62; welcome to the website.</pre>
<p><strong>Code in controller</strong></p>
<pre>$t = new Template('hello.html');
$t-&#62;name = 'Frank';
echo $t-&#62;render();</pre>
<p><strong>Output:</strong></p>
<pre>Hey there &#60;strong&#62;Frank&#60;/strong&#62; welcome to the website.</pre>
<h3>Example with Inheritance</h3>
<p><strong>base.html</strong></p>
<pre>&#60;h3&#62;Welcome to the website&#60;h3&#62;
{% block content %}{% endblock %}</pre>
<p><strong>hello.html</strong></p>
<pre>{% extends 'base.html' %}
{% block content %}
Hey there &#60;strong&#62;{{ name }}&#60;/strong&#62; welcome to the website.
{% endblock %}</pre>
<p><strong>Code in controller</strong></p>
<pre>$t = new Template('hello.html');
$t-&#62;name = 'Joe';
echo $t-&#62;render();</pre>

<p><strong>Output:</strong>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<h3>Requirements</h3>
<ul>
<li><a href="https://github.com/fabpot/twig">Twig</a> downloaded and unarchived</li>
<li><a href="http://www.twig-project.org/doc/intro.html#basic-api-usage">Twig Autoloader</a> registered</li>
</ul>
<h3>Template Class</h3>
<p>The use of the <em>Settings</em> class is self explanatory. Just replaces the instances of <em>Settings</em> with your own configuration system (or just strings). All Twig settings are documented <a href="http://www.twig-project.org/doc/api.html#environment-options">here</a>.</p>
<pre>class Template
{

	public $context = array();

	private $template;

	public function __construct($template)
	{		

		$loader = new Twig_Loader_Filesystem(Settings::get('template_directories'));

		$twig = new Twig_Environment($loader, array(

			'cache' => Settings::get('template_cache_directory'),
			'debug' => Settings::get('debug'),

				)

		);

		$this->template = $twig->loadTemplate($template);

	}

	public function setContext(array $context = array())
	{
		$this->context = array_merge($context, $this->context);

	}

	public function render()
	{
		return $this->template->render($this->context);
	}	

	public function __toString()
	{
		return $this->render();
	}

	public function __set($key, $val)
	{
		$this->context[$key] = $val;
	}

	public function __get($key)
	{
		return $this->context[$key];
	}

}</pre>
<h3>Simple Example</h3>
<p><strong>hello.html</strong></p>
<pre>Hey there &lt;strong&gt;{{ name }}&lt;/strong&gt; welcome to the website.</pre>
<p><strong>Code in controller</strong></p>
<pre>$t = new Template('hello.html');
$t-&gt;name = 'Frank';
echo $t-&gt;render();</pre>
<p><strong>Output:</strong></p>
<pre>Hey there &lt;strong&gt;Frank&lt;/strong&gt; welcome to the website.</pre>
<h3>Example with Inheritance</h3>
<p><strong>base.html</strong></p>
<pre>&lt;h3&gt;Welcome to the website&lt;h3&gt;
{% block content %}{% endblock %}</pre>
<p><strong>hello.html</strong></p>
<pre>{% extends 'base.html' %}
{% block content %}
Hey there &lt;strong&gt;{{ name }}&lt;/strong&gt; welcome to the website.
{% endblock %}</pre>
<p><strong>Code in controller</strong></p>
<pre>$t = new Template('hello.html');
$t-&gt;name = 'Joe';
echo $t-&gt;render();</pre>
</pre>
<p><strong>Output:</strong></p>
<pre>&lt;h3&gt;Welcome to the website&lt;h3&gt;
Hey there &lt;strong&gt;Joe&lt;/strong&gt; welcome to the website.</pre>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/php-twig-template-wrapper/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why You Should Be Using a PHP Framework</title>
		<link>http://query7.com/why-you-should-be-using-a-php-framework</link>
		<comments>http://query7.com/why-you-should-be-using-a-php-framework#comments</comments>
		<pubDate>Mon, 11 Apr 2011 08:34:09 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=1437</guid>
		<description><![CDATA[<p>All frameworks discussed in this post are full stack web frameworks coded in PHP such as Code Igniter, Symfony, Kohana, Yii and CakePHP. Some (but definitely not all) of the points below may apply to micro frameworks such as FatFreeFramework, Limonade, Glue and Slim.</p>
<h3>When should I use a framework?</h3>
<p>Frameworks should be used when constructing web applications. Any application that involves a database, forms, sessions, cookies or a remote service (such as Twitter or Facebook) will benefit from being powered by a framework. There is no need to use a framework for a website that has only one or two pages, nor for command line utility scripts.</p>
<h3>What features do frameworks provide?</h3>
<ul>
<li><strong>Database abstraction</strong>. Frameworks can abstract away SQL-vendor specific features. This allows you to change your SQL database without needing to rewrite any code. For example, switch from MySQL to Postgres or MSSQL. Some frameworks can also handle database relations automatically, which saves you having to write JOIN queries.</li>
<li><strong>Cache abstraction</strong>. Rather than using backend specific caching functions (such as <em>apc_add</em> and <em>apc_fetch</em>), you use a generic caching class which has support for multiple backends such as Memcache, APC and XCache.</li>
<li><strong>Form management</strong>. Symfony2 and CakePHP allow</li></ul><p>&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>All frameworks discussed in this post are full stack web frameworks coded in PHP such as Code Igniter, Symfony, Kohana, Yii and CakePHP. Some (but definitely not all) of the points below may apply to micro frameworks such as FatFreeFramework, Limonade, Glue and Slim.</p>
<h3>When should I use a framework?</h3>
<p>Frameworks should be used when constructing web applications. Any application that involves a database, forms, sessions, cookies or a remote service (such as Twitter or Facebook) will benefit from being powered by a framework. There is no need to use a framework for a website that has only one or two pages, nor for command line utility scripts.</p>
<h3>What features do frameworks provide?</h3>
<ul>
<li><strong>Database abstraction</strong>. Frameworks can abstract away SQL-vendor specific features. This allows you to change your SQL database without needing to rewrite any code. For example, switch from MySQL to Postgres or MSSQL. Some frameworks can also handle database relations automatically, which saves you having to write JOIN queries.</li>
<li><strong>Cache abstraction</strong>. Rather than using backend specific caching functions (such as <em>apc_add</em> and <em>apc_fetch</em>), you use a generic caching class which has support for multiple backends such as Memcache, APC and XCache.</li>
<li><strong>Form management</strong>. Symfony2 and CakePHP allow the developer to define forms as PHP code. The framework then handles all HTML widget generation, form validation and CSRF security automatically.</li>
<li><strong>Authentication</strong>. Most frameworks come with a generic user authentication module. They handle logging in and logging out, registration, session management and permissions. They are typically very easy to modify and add your own custom fields.</li>
<li><strong>Easy Debugging and Profiling</strong>. Kohana3 and Symfony2 come with debug toolbars. These allow you to inspect global variables, database queries, logs and load times in the current request.</li>
<li><strong>Internationalization.</strong> Built in translation frameworks let you easily create country specific versions of your website.</li>
</ul>
<h3>What benefits do I get from using a framework?</h3>
<ul>
<li><strong>Portability</strong>. Database and cache abstraction allows your application to be used on many different server setups. If your application is open source, more people will be able to install it.
<li><strong>Shorter development time</strong>. Because your not writing the same boilerplate user authentication, database and form code, development time is shortened dramatically. </li>
<li><strong>Application security</strong> &#8211; Security features such as authentication and permissions are handled for you by the framework. Database inputs are automatically sanitised and most frameworks have cross site request forgery (CSRF) protection built in.</li>
<li><strong>Community supported</strong> &#8211; Frameworks have forums, mailing lists and IRC channels supporting them. If you encounter a problem with the framework, chances are someone else has and a fix has already been made.</li>
<li><strong>Plugins and modules</strong>. Members of the community release plugins and modules which you can download and use in your application. These would be things such as integration with 3rd party APIs (Facebook, Twitter) and features such as template engine integration.</li>
<li><strong>Enforces good coding standard</strong>. Most frameworks force you to follow the Model, View, Controller principle. This makes you (the developer) think about how your code will be structured before you write it, making it of higher quality.</li>
<li><strong>Future proof your application</strong>. Frameworks are well documented and tested. If another developer was brought in on the project, or you sold your project, the new developer would just need to read up on the framework documentation and then would understand the code. If a framework wasn&#8217;t being used then time and money would need to be put into training the new developer.</li>
</ul>
<h3>What framework should I use?</h3>
<p>Everyone has their own opinion on which is the &#8220;best&#8221; framework. I recommend you have a look at all frameworks linked below, they each have different styles of structuring the application. If you have experience with Ruby On Rails then you may want to look at <a href="http://cakephp.org">CakePHP</a> and <a href="http://www.phpontrax.com/">Trax</a>. They both have ActiveRecord implementations and model themselves after Rails. <a href="http://qphp.net/">QPHP</a> will seem familiar for those with ASP.NET experience and <a href="http://symfony.org">Symfony2</a> will make people who know Java feel at home (<a href="http://query7.com/a-look-at-php-53-frameworks-symfony2">Symfony2 overview</a>). Also be sure to check out <a href="http://kohanaframework.org">Kohana</a>, <a href="http://codeigniter.com">Code Igniter</a>, <a href="http://yiiframework.org">Yii</a>, <a href="http://lithify.me/">Lithium</a>, <a href="http://fuelphp.com/">Fuel</a>, <a href="http://alloyframework.org/">Alloy</a> and <a href="http://akelos.org">Akelos</a> before making your decision.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/why-you-should-be-using-a-php-framework/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>A Look at PHP 5.3 Frameworks &#8211; Symfony2</title>
		<link>http://query7.com/a-look-at-php-53-frameworks-symfony2</link>
		<comments>http://query7.com/a-look-at-php-53-frameworks-symfony2#comments</comments>
		<pubDate>Mon, 14 Mar 2011 08:29:15 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=867</guid>
		<description><![CDATA[<p>Ever since PHP5.3 was released we have seen several new frameworks pop up in the PHP community. In this series of articles we will look at and evaluate some of the next generation PHP frameworks. Today we look at <a href="http://symfony-reloaded.org">Symfony2</a>.</p>
<h3>Overview</h3>
<p>Symfony2 is a full stack web enterprise framework created by well known PHP guru Fabien Potencier. The framework itself is divided up into several different packages (<em>Bundles</em>) which are tied together with a <a href="http://docs.symfony-reloaded.org/guides/internals/kernel.html">Kernel</a> object. Being a full stack framework Symfony2 offers almost everything you will need out of the box:</p>
<ul>
<li>Model, View, Controller separation</li>
<li>Database management with Doctrine2</li>
<li>Templating with either straight PHP templates or Twig</li>
<li>Testing with a layer built upon PHPUnit</li>
<li>Emails with SwiftMailer</li>
<li>Custom form, validation, auth, event and caching systems.
</li></ul>
<p>One thing that distinguishes Symfony2 from other frameworks is that it relies heavily on Dependency Injection and as a result alot of configuration needs to take place. The standard of the Symfony2 is top notch, it is clearly set out, commented and tested. The full stack nature of Symfony2 is also a big strength. If you were to start a high upkeep project, you could be sure that in 5&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Ever since PHP5.3 was released we have seen several new frameworks pop up in the PHP community. In this series of articles we will look at and evaluate some of the next generation PHP frameworks. Today we look at <a href="http://symfony-reloaded.org">Symfony2</a>.</p>
<h3>Overview</h3>
<p>Symfony2 is a full stack web enterprise framework created by well known PHP guru Fabien Potencier. The framework itself is divided up into several different packages (<em>Bundles</em>) which are tied together with a <a href="http://docs.symfony-reloaded.org/guides/internals/kernel.html">Kernel</a> object. Being a full stack framework Symfony2 offers almost everything you will need out of the box:</p>
<ul>
<li>Model, View, Controller separation</li>
<li>Database management with Doctrine2</li>
<li>Templating with either straight PHP templates or Twig</li>
<li>Testing with a layer built upon PHPUnit</li>
<li>Emails with SwiftMailer</li>
<li>Custom form, validation, auth, event and caching systems.
</ul>
<p>One thing that distinguishes Symfony2 from other frameworks is that it relies heavily on Dependency Injection and as a result alot of configuration needs to take place. The standard of the Symfony2 is top notch, it is clearly set out, commented and tested. The full stack nature of Symfony2 is also a big strength. If you were to start a high upkeep project, you could be sure that in 5 years all components of the stack (forms, validation, templating, testing, database) would still be maintained. An overview of the architecture of a Symfony2 application can be found <a href="http://docs.symfony-reloaded.org/quick_tour/the_architecture.html">here</a>.</p>
<h3>PHP, XML or Yaml?</h3>
<p>One of Symfony2&#8242;s unique features is that it allows you configure the majority of your application in either PHP, XML or Yaml. When Symfony2 is running in production mode, all XML or Yaml files are compiled and cached as native PHP files, so there is no performance advantage gained by using straight PHP. Frameworks such as Zend Framework only allow application settings to be defined in XML, Yaml or .ini format, Symfony2 goes a step further and allows you to specify functionality such as validations and url routes in these formats. For example, the following code snippets show how to validate the presence of the <em>$name</em> attribute in the <em>Author</em> object below.</p>
<pre>// Sensio/HelloBundle/Author.php
class Author
{
    private $name;
}</pre>
<p><strong>PHP</strong></p>
<pre>// Sensio/HelloBundle/Author.php
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Components\Validator\Constraints\NotBlank;

class Author
{
    private $name;

    public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        $metadata->addPropertyConstraint('name', new NotBlank());
    }
}</pre>
<p><strong>Yaml</strong></p>
<pre># Sensio/HelloBundle/Resources/config/validation.yml
Sensio\HelloBundle\Author:
    properties:
        name:
            - NotBlank: ~</pre>
<p><strong>XML</strong></p>
<pre>&lt;!-- Sensio/HelloBundle/Resources/config/validation.xml --&gt;
&lt;class name=&quot;SensioHelloBundleAuthor&quot;&gt;
    &lt;property name=&quot;name&quot;&gt;
        &lt;constraint name=&quot;NotBlank&quot; /&gt;
    &lt;/property&gt;
&lt;/class&gt;</pre>
<p><a href="http://docs.symfony-reloaded.org/guides/validator/overview.html">source</a></p>
<h3>Bundles</h3>
<p><em>Bundles</em> are packaged classes and methods which provide functionality for your application. Symfony2 ships with bundles that are required for the framework to run. These are things like <em>DoctrineBundle</em> (database), <em>TwigBundle</em> (templating), <em>SwiftmailerBundle</em> (emails) and <em>ZendBundle</em> (Zend Framework integration). Code inside bundles must follow the defined structure and naming guidelines, specified <a href="http://docs.symfony-reloaded.org/guides/bundles/best_practices.html">here</a> so that Symfony2 can automatically know where to find controllers, tests and translations. Bundles are what other frameworks would call plugins, modules or extensions. You can download Bundles developed by the community that provide features like user registration, Facebook integration and blog functionality from <a href="http://symfony2bundles.org">symfony2bundles.org</a>.</p>
<h3>Testing</h3>
<p>As you could expect with any enterprise framework, Symfony2 comes with complete testing functionality. Symfony2 provides a layer on top of PHPUnit for you to define your tests. You can write standard unit tests (as you would with PHPUnit) as well as &#8216;functional tests&#8217;. Functional tests are essentially automated front end testing, Symfony emulates a browser request to a specific URL of your application and you define what output you are expecting to see. This could be a specific HTTP response code or some HTML on the page.</p>
<div style="width:425px" id="__ss_4599947"><object id="__sse4599947" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=testing-100624020238-phpapp01&#038;stripped_title=unit-and-functional-testing-with-symfony2&#038;userName=fabpot" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse4599947" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=testing-100624020238-phpapp01&#038;stripped_title=unit-and-functional-testing-with-symfony2&#038;userName=fabpot" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px"></div>
</div>
<h3>HTTP Caching</h3>
<p>Every Symfony2 controller returns an instance of the <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Response.php">Response</a> object. The Response object has several methods available that allows the developer to set specific HTTP headers which are then sent to the browser. This allows the developer to have complete control over every header that is being sent back to the browser. The slides below show how powerful this feature can be.</p>
<div style="width:425px" id="__ss_4599971"><object id="__sse4599971" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=cache-100624020432-phpapp02&#038;stripped_title=caching-on-the-edge-with-symfony2&#038;userName=fabpot" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse4599971" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=cache-100624020432-phpapp02&#038;stripped_title=caching-on-the-edge-with-symfony2&#038;userName=fabpot" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></div>
<h3>Community</h3>
<p>Although Symfony2 is still in pre-beta, the majority of functionality is already in the framework. All official documentation and guides can be found on the Symfony2 website <a href="http://symfony-reloaded.org">Symfony-Reloaded.org</a>. If your a twitter user than I recommend following <a href="http://twitter.com/fabpot">@fabpot</a> (creator, developer of Symfony2), <a href="http://twitter.com/jwage">@jwage</a> (developer Symfony2, Doctrine) and <a href="http://twitter.com/symfony2">@symfony</a> (aggregated Symfony news). An <a href="http://wiki.phpbb.com/PhpBB4/RFC/Symfony_2">RFC</a> was recently posted on the phpBB4 wiki suggesting that phpBB4 be built using Symfony2. If it gets accepted then we could expect the thousands of mod developers for phpBB2 &#038; 3 would learn Symfony2 while developing mods for phpBB4. </p>
<h3>Conclusion</h3>
<p>I suspect developers with previous experience in Symfony1, Java and .NET would find Symfony2 perfect and won&#8217;t hesitate to use it. Those who use PHP frameworks such as Code Igniter, Kohana, CakePHP and Yii will find Symfony2 very different. The strict naming convention, long namespaces and dependency injection may put them off. If phpBB4 does decide to use Symfony2 then other open source PHP projects may follow and Symfony2 will no doubt become the most popular PHP framework. Regardless of developer preferences or immediate success, Symfony2 is an amazing piece of code and I highly suggest you try it out.</p>
<h3>Links</h3>
<ul>
<li><a href="http://symfony-reloaded.org">Symfony2 Homepage</a></li>
<li><a href="http://docs.symfony-reloaded.org/index.html">Symfony2 Documentation</a></li>
<li><a href="http://github.com/symfony/symfony">Symfony2 on Github</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/a-look-at-php-53-frameworks-symfony2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Proxies with cURL in PHP</title>
		<link>http://query7.com/using-proxies-with-curl-in-php</link>
		<comments>http://query7.com/using-proxies-with-curl-in-php#comments</comments>
		<pubDate>Sun, 13 Feb 2011 21:30:21 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=982</guid>
		<description><![CDATA[<p>If you are new to using PHP and cURL please refer to the <a href="http://query7.com/php-curl">PHP cURL tutorial</a>. It covers why you should using cURL (as opposed to file_get_contents) and goes over how to make cURL requests with a custom class.</p>
<p>This tutorial will cover how to use different types of proxies &#8211; SOCKS4, SOCKS5 and HTTP with cURL. </p>
<h3>Basic cURL Request</h3>
<p>We&#8217;ll start by creating a simple cURL script that requests the web page <a href="http://checkip.dyndns.org">checkip.dyndns.org</a> and displays the result on the screen. The website just displays our current IP address, this is useful when working with proxies. Below is our very basic cURL request. </p>
<pre>$url = 'http://checkip.dyndns.org/';

$c = curl_init($url);

curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($c);

echo '&#60;pre&#62;';
var_dump($result);
echo '&#60;/pre&#62;';

curl_close($c);</pre>
<p>As we can expect, the output will be your IP address.</p>
<pre>202.183.56.21</pre>
<h3>Using Proxies with cURL</h3>
<p>To use proxies with cURL we need to set 2 additional cURL options: <em>CURLOPT_PROXYTYPE</em> and <em>CURLOPT_PROXY</em>. <em>CURLOPT_PROXYTYPE</em> should be set to either <em>CURLPROXY_SOCKS5</em> or <em>CURLPROXY_SOCKS4</em>, depending on the type of proxy you are using. <em>CURLOPT_PROXY</em> should be set to the IP address and port of the proxy you are using.</p>
<p>If you are using an HTTP proxy then you&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>If you are new to using PHP and cURL please refer to the <a href="http://query7.com/php-curl">PHP cURL tutorial</a>. It covers why you should using cURL (as opposed to file_get_contents) and goes over how to make cURL requests with a custom class.</p>
<p>This tutorial will cover how to use different types of proxies &#8211; SOCKS4, SOCKS5 and HTTP with cURL. </p>
<h3>Basic cURL Request</h3>
<p>We&#8217;ll start by creating a simple cURL script that requests the web page <a href="http://checkip.dyndns.org">checkip.dyndns.org</a> and displays the result on the screen. The website just displays our current IP address, this is useful when working with proxies. Below is our very basic cURL request. </p>
<pre>$url = 'http://checkip.dyndns.org/';

$c = curl_init($url);

curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($c);

echo '&lt;pre&gt;';
var_dump($result);
echo '&lt;/pre&gt;';

curl_close($c);</pre>
<p>As we can expect, the output will be your IP address.</p>
<pre>202.183.56.21</pre>
<h3>Using Proxies with cURL</h3>
<p>To use proxies with cURL we need to set 2 additional cURL options: <em>CURLOPT_PROXYTYPE</em> and <em>CURLOPT_PROXY</em>. <em>CURLOPT_PROXYTYPE</em> should be set to either <em>CURLPROXY_SOCKS5</em> or <em>CURLPROXY_SOCKS4</em>, depending on the type of proxy you are using. <em>CURLOPT_PROXY</em> should be set to the IP address and port of the proxy you are using.</p>
<p>If you are using an HTTP proxy then you only need to set <em>CURLOPT_PROXY</em> to your proxy. <em>CURLOPT_PROXYTYPE</em> automatically defaults to <em>CURLPROXY_HTTP</em>.</p>
<p>As you can expect, the following script displays the IP address of the proxy.</p>
<pre>$url = 'http://checkip.dyndns.org/';

$c = curl_init($url);

curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($c, CURLOPT_PROXY, '68.119.83.81:27977');

$result = curl_exec($c);

echo '&lt;pre&gt;';
var_dump($result);
echo '&lt;/pre&gt;';

curl_close($c);</pre>
<p>Note: You&#8217;ll need to use your own proxy. The one supplied is made up.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/using-proxies-with-curl-in-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Developing a blog with CakePHP</title>
		<link>http://query7.com/developing-a-blog-with-cakephp</link>
		<comments>http://query7.com/developing-a-blog-with-cakephp#comments</comments>
		<pubDate>Fri, 11 Feb 2011 07:13:46 +0000</pubDate>
		<dc:creator>Adit Gupta</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=1046</guid>
		<description><![CDATA[<div id="_mcePaste">If you want to develop a blog from sctrach without using any CMS like WordPress or Drupal, then you&#8217;ve come at the right place! In this series, we will understand how to develop a blog using</div>
<div id="_mcePaste">the CakePHP framework. So, why CakePHP? CakePHP is a robust PHP Framework having an extensive community and excellent documentation. It&#8217;s based on the MVC pattern, which makes it really simple to use.</div>
<div id="_mcePaste">Moreover, you can add numerous functionalities to your web application or blog using this framework.</div>
<p>We would be covering the following topics in this series</p>
<ol>
<li>Installing and Configuring CakePHP</li>
<li>Understanding MVC</li>
<li>Creating a simple blog</li>
<li>Adding advanced features to your blog &#8211; Understanding Models, Views, Controllers in Depth</li>
<li>Understanding Helpers</li>
<li>Ajaxifying comments, adding content summary and Gravatar to your blog</li>
<li>Securing your blog</li>
</ol>
<p>In this article, we&#8217;ll just take a look at installing and configuring CakePHP.</p>
<p>Download the latest version of CakePHP framework from <a href="http://www.cakephp.org" target="_blank">CakePHP.org</a>. Make sure to download the stable release and not the release candidate.<br />
Unpack the contents of the Cake archive inside the &#8220;www&#8221; folder of <a href="http://www.wampserver.com/en/" target="_blank">wamp</a> or <a href="http://www.mamp.info/en/index.html" target="_blank">mamp</a> directory.You now have a folder in your document&#8230;</p>]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">If you want to develop a blog from sctrach without using any CMS like WordPress or Drupal, then you&#8217;ve come at the right place! In this series, we will understand how to develop a blog using</div>
<div id="_mcePaste">the CakePHP framework. So, why CakePHP? CakePHP is a robust PHP Framework having an extensive community and excellent documentation. It&#8217;s based on the MVC pattern, which makes it really simple to use.</div>
<div id="_mcePaste">Moreover, you can add numerous functionalities to your web application or blog using this framework.</div>
<p>We would be covering the following topics in this series</p>
<ol>
<li>Installing and Configuring CakePHP</li>
<li>Understanding MVC</li>
<li>Creating a simple blog</li>
<li>Adding advanced features to your blog &#8211; Understanding Models, Views, Controllers in Depth</li>
<li>Understanding Helpers</li>
<li>Ajaxifying comments, adding content summary and Gravatar to your blog</li>
<li>Securing your blog</li>
</ol>
<p>In this article, we&#8217;ll just take a look at installing and configuring CakePHP.</p>
<p>Download the latest version of CakePHP framework from <a href="http://www.cakephp.org" target="_blank">CakePHP.org</a>. Make sure to download the stable release and not the release candidate.<br />
Unpack the contents of the Cake archive inside the &#8220;www&#8221; folder of <a href="http://www.wampserver.com/en/" target="_blank">wamp</a> or <a href="http://www.mamp.info/en/index.html" target="_blank">mamp</a> directory.You now have a folder in your document root named after the release you&#8217;ve downloaded. We will rename this<br />
folder to &#8220;newblog&#8221; (or you can have any name of your choice) . The directory structure inside this folder should look something like this:</p>
<p><a href="http://query7.com/wp-content/uploads/2011/02/cp01.jpg"><img class="alignnone size-medium wp-image-730" title="cp01" src="http://query7.com/wp-content/uploads/2011/02/cp01-300x49.jpg" alt="" width="300" height="49" /></a></p>
<p>We would be doing all our work inside the <strong>app</strong> folder. The <strong>cake</strong> folder stores all the core functions for CakePHP. Make sure that you do not edit anything inside this folder. The vendors folder is where youíll place third-party PHP libraries you need to use with your CakePHP applications.<br />
You will notice that there are several other folders inside the app folder. We will take a look at each of them as we go on developing our blog.</p>
<h2>Configuring Cake PHP</h2>
<p>Configuring Cake PHP is pretty easy. Go inside the <strong>app &#8211;&gt; Config</strong> folder and open the <strong>database.php.default</strong> file with your favorite editor. Scroll down to the following array in the file:</p>
<pre> &lt; php 	var $default = array( 	'driver' =&gt; 'mysql',
'persistent' =&gt; false,
'host' =&gt; 'localhost',
'login' =&gt; 'username',
'password' =&gt; 'password',
'database' =&gt; 'databasename',
'prefix' =&gt; '',
);
?&gt;</pre>
<p>Enter your login, password, database name and save the file as <strong>database.php</strong>. That&#8217;s it!</p>
<p>Open you browser and go to  <strong>http://localhost/cakephp</strong>. You should now see the following success page:</p>
<p><a href="http://query7.com/wp-content/uploads/2011/02/cakephp01.jpg"><img class="alignnone size-medium wp-image-727" title="cakephp01" src="http://query7.com/wp-content/uploads/2011/02/cakephp01-300x140.jpg" alt="" width="300" height="140" /></a></p>
<p>However, you might see a colorless page like this:</p>
<p><a href="http://query7.com/wp-content/uploads/2011/02/cakephp02.jpg"><img class="alignnone size-medium wp-image-726" title="cakephp02" src="http://query7.com/wp-content/uploads/2011/02/cakephp02-300x141.jpg" alt="" width="300" height="141" /></a></p>
<p>It means that rewrite_module is not enabled in your Apache Server. To do so, click on the wampserver icon in your system tray and go to Apache&#8211;&gt;Apache modules and click on the rewrite_module in the list to enable it. It should work fine after rewrite_module has been enabled.</p>
<p>So, now that you&#8217;ve CakePHP up and running, we&#8217;ll move on to the next step in subsequent article. Do leave your comments if you&#8217;ve any doubts regarding this article.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/developing-a-blog-with-cakephp/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book Review: PHP5 CMS Framework Development</title>
		<link>http://query7.com/book-review-php5-cms-framework-development</link>
		<comments>http://query7.com/book-review-php5-cms-framework-development#comments</comments>
		<pubDate>Mon, 27 Dec 2010 00:01:44 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[book review]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=832</guid>
		<description><![CDATA[<p><a href="https://www.packtpub.com/php-5-cms-framework-development-second-edition/book?mid=230810xyyh5e">PHP5 CMS Framework Development</a> is a 322 page book that covers all aspects of creating a full featured content management system (CMS) in PHP5. The author Martin Brampton has a history of developing extensions for the Mambo and Joomla CMS projects. He became lead developer of the CMS Mambo before starting his own CMS, <a href="http://aliro.org/">Aliro</a>. The book is split up into 14 chapters. The first is an introduction to CMS and PHP5 concepts and the remaining 13 each look at a key feature of the CMS.</p>
<p><a href="http://query7.com/wp-content/uploads/php5cms.jpg"><img src="http://query7.com/wp-content/uploads/php5cms.jpg" alt="" title="php5cms" width="407" height="500" class="aligncenter size-full wp-image-860" /></a></p>
<p>The book starts by defining what a content management system is and what features it needs to have. It then gives some background into the Model View Controller and Object Relational concepts as well as the Factory, Singleton, Observer and Command design patterns. If you haven&#8217;t used a CMS before and don&#8217;t know PHP5 OOP, this chapter prepares you excellently for the rest of the book. </p>
<p>The remaining 13 chapters each cover a feature of the framework. This includes:</p>
<ul>
<li>Database abstraction</li>
<li>Access control, user authentication</li>
<li>Framework extensions/plugins</li>
<li>Caching</li>
<li>Internationalization</li>
<li>Error handling</li>
<li>Menus</li>
</ul>
<p>Brampton has done a great job at explaining each feature before he shows any code. This ensures&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><a href="https://www.packtpub.com/php-5-cms-framework-development-second-edition/book?mid=230810xyyh5e">PHP5 CMS Framework Development</a> is a 322 page book that covers all aspects of creating a full featured content management system (CMS) in PHP5. The author Martin Brampton has a history of developing extensions for the Mambo and Joomla CMS projects. He became lead developer of the CMS Mambo before starting his own CMS, <a href="http://aliro.org/">Aliro</a>. The book is split up into 14 chapters. The first is an introduction to CMS and PHP5 concepts and the remaining 13 each look at a key feature of the CMS.</p>
<p><center><a href="http://query7.com/wp-content/uploads/php5cms.jpg"><img src="http://query7.com/wp-content/uploads/php5cms.jpg" alt="" title="php5cms" width="407" height="500" class="aligncenter size-full wp-image-860" /></a></center></p>
<p>The book starts by defining what a content management system is and what features it needs to have. It then gives some background into the Model View Controller and Object Relational concepts as well as the Factory, Singleton, Observer and Command design patterns. If you haven&#8217;t used a CMS before and don&#8217;t know PHP5 OOP, this chapter prepares you excellently for the rest of the book. </p>
<p>The remaining 13 chapters each cover a feature of the framework. This includes:</p>
<ul>
<li>Database abstraction</li>
<li>Access control, user authentication</li>
<li>Framework extensions/plugins</li>
<li>Caching</li>
<li>Internationalization</li>
<li>Error handling</li>
<li>Menus</li>
</ul>
<p>Brampton has done a great job at explaining each feature before he shows any code. This ensures someone new to content management systems will understand the feature before being bombarded with snippets of code. For example, the chapter on Menus opens by explaining what function a menu has in the context of a CMS (as opposed to a static HTML website). It then talks about how menus can be represented in code and how they can be stored efficiently in a CMS. A screenshot of the database schema is then shown and each field is explained in detail. Finally we are walked through the important methods from the menu class.</p>
<p>Overall I found the book to be a great learning experience. It gives a good insight into how Aliro and other content management systems work under the hood. I feel it is important to emphasis that all implementations of framework features (database abstraction, menus, plugins etc.) are shown as code take directly from the Aliro framework. The book doesn&#8217;t teach you how to implement a feature, it shows you how the feature is implemented in Aliro. I found this to be a positive because Aliro is a full featured CMS. In many other books that teach you how to build a web application, the web app that is made has an absolute minimal feature set and you don&#8217;t learn a whole lot. Because all code is taken from Aliro, no corners are cut and the detail is superb.</p>
<p>There are a few negative points about PHP5 CMS Framework Development. Unfortunately one comes from the fact that all code snippets are taken directly from Aliro. There are several design decisions Brampton made that now contradict modern day PHP best practice. For example Aliro uses its own style of class naming, not the Zend_Style_Names (namespaces were implemented in PHP a year after this book was published). It also makes very heavy use of singletons which depending on what developer you ask, is a bad thing. There is no chapter on testing which is surprising considering the nature of application that is being built.</p>
<p>If your thinking about writing your own PHP framework or large web application then I recommend you read this book. Brampton does a great job at introducing each framework feature, so even if you have no experience with content management systems, you will be able to understand what he is talking about. Just keep in mind that this book shows and explains one way of implementing a feature, and that way isn&#8217;t necessarily the best or only way.</p>
<p>A 2nd edition of PHP5 CMS Framework Developed his since been published. </p>
<blockquote><p>New for this edition is a chapter discussing the transformation of URLs to turn ugly query strings into readable strings that are believed to be more “search engine friendly” and are certainly more user friendly. This topic is then extended into a review of ways to handle “friendly” URLs without going through query strings, and how to build RESTful interfaces.</p>
<p>The final chapter discusses the key issues that affect a wide range of specific content handlers and explores a practical example in detail. &#8211; <a href="https://www.packtpub.com/php-5-cms-framework-development-second-edition/book?mid=230810xyyh5e">source</a></p></blockquote>
<p><a href="https://www.packtpub.com/php-5-cms-framework-development-second-edition/book?mid=230810xyyh5e">PHP5 CMS Framework Development on PacktPub</a></p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/book-review-php5-cms-framework-development/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a module for Kohana3</title>
		<link>http://query7.com/writing-a-module-for-kohana3</link>
		<comments>http://query7.com/writing-a-module-for-kohana3#comments</comments>
		<pubDate>Mon, 20 Dec 2010 20:43:54 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[twig]]></category>

		<guid isPermaLink="false">http://query7.com/?p=775</guid>
		<description><![CDATA[<p>In this tutorial we will cover how to build a module from scratch in Kohana 3. If you aren&#8217;t familiar with the Kohana framework then I recommend you read the <a href="http://query7.com/an-introduction-to-kohana3-php-framework">beginners introduction to Kohana</a>.</p>
<h3>The Plan</h3>
<p>We will be building a module that replaces Kohana&#8217;s own view layer (<em>Kohana_View</em>). It will use the PHP template library <a href="http://twig-project.org">Twig</a>. We want our own view layer to be API compatible with Kohana&#8217;s view layer. This will ensure that other modules work out of the box and that the only code the developer will need to alter in their application are the templates (so that they are Twig compatible). No code in any controller will need to be modified.</p>
<p> Because Kohana follows HMVC (see beginners introduction to Kohana) we will be calling our class <i>View</i>. This means that all calls in the application to the class of <i>View</i> will be to the <i>View</i> class in our module, not Kohana&#8217;s own <i>View</i> class. </p>
<h3>Directory Structure</h3>
<p><a href="http://query7.com/wp-content/uploads/dir.png"><img src="http://query7.com/wp-content/uploads/dir.png" alt="" title="dir" width="148" height="201" class="aligncenter size-full wp-image-783" /></a></p>
<h3>Enabling The Module</h3>
<p>The name of any Kohana module is the same name as the directory inside the <i>modules</i> directory. So in this case it is <i>twig</i>. To activate any module, we must add it&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>In this tutorial we will cover how to build a module from scratch in Kohana 3. If you aren&#8217;t familiar with the Kohana framework then I recommend you read the <a href="http://query7.com/an-introduction-to-kohana3-php-framework">beginners introduction to Kohana</a>.</p>
<h3>The Plan</h3>
<p>We will be building a module that replaces Kohana&#8217;s own view layer (<em>Kohana_View</em>). It will use the PHP template library <a href="http://twig-project.org">Twig</a>. We want our own view layer to be API compatible with Kohana&#8217;s view layer. This will ensure that other modules work out of the box and that the only code the developer will need to alter in their application are the templates (so that they are Twig compatible). No code in any controller will need to be modified.</p>
<p> Because Kohana follows HMVC (see beginners introduction to Kohana) we will be calling our class <i>View</i>. This means that all calls in the application to the class of <i>View</i> will be to the <i>View</i> class in our module, not Kohana&#8217;s own <i>View</i> class. </p>
<h3>Directory Structure</h3>
<p><a href="http://query7.com/wp-content/uploads/dir.png"><img src="http://query7.com/wp-content/uploads/dir.png" alt="" title="dir" width="148" height="201" class="aligncenter size-full wp-image-783" /></a></p>
<h3>Enabling The Module</h3>
<p>The name of any Kohana module is the same name as the directory inside the <i>modules</i> directory. So in this case it is <i>twig</i>. To activate any module, we must add it to the array passed to <i>Kohana::modules</i> in <i>application/bootstrap.php</i>.</p>
<p><b>application/bootstrap.php &#8211; line 88</b></p>
<pre>Kohana::modules(array(
	'twig' => MODPATH.'twig',
	// 'auth'       => MODPATH.'auth',       // Basic authentication
	// 'cache'      => MODPATH.'cache',      // Caching with multiple backends
	// 'codebench'  => MODPATH.'codebench',  // Benchmarking tool
	// 'database'   => MODPATH.'database',   // Database access
	// 'image'      => MODPATH.'image',      // Image manipulation
	// 'orm'        => MODPATH.'orm',        // Object Relationship Mapping
	// 'oauth'      => MODPATH.'oauth',      // OAuth authentication
	// 'pagination' => MODPATH.'pagination', // Paging of results
	// 'unittest'   => MODPATH.'unittest',   // Unit testing
	// 'userguide'  => MODPATH.'userguide',  // User guide and API documentation
	));
</pre>
<h3>Twig</h3>
<p>We will be using Fabien Potencier&#8217;s Twig project as a replacement templating engine for Kohana. The Twig files themselves will be stored in <i>modules/twig/Twig/</i>. If you are familiar with git you could create a git submodule of Twig so you can update Twig independently from our <i>twig</i> Kohana module. However for the sake of this tutorial it is easier just to download the tarball and extract it.</p>
<p>Rather than including all Twig files explicitly (using <i>include</i> or <i>require</i> statements) we will use Twig&#8217;s own autoloader. We could call it either in <i>application/bootstrap.php</i> or <i>modules/twig/init.php</i>. Since the autoloader is specific to the <em>twig</em> module (and not to the application) it is better to put it in <i>modules/twig/init.php</i>. Every <i>init.php</i> file in every enabled module is called automatically every request by Kohana.</p>
<p><b>modules/twig/init.php</b></p>
<pre>require 'Twig/Autoloader.php';

Twig_Autoloader::register();
</pre>
<h3>Configuration</h3>
<p>Each developer that uses our <i>twig</i> module will have a different template directory and will want to pass different options to the Twig library when it&#8217;s instantiated (such as whether Twig runs in debug mode). Rather than hard coding these options into our module (which would force every developer using it to alter module code) we can use Kohana&#8217;s configuration system. </p>
<p>Because the configuration for our module is application specific, create <i>application/config/twig.php</i></p>
<p><b>application/config/twig.php</b></p>
<pre>// http://www.twig-project.org/book/03-Twig-for-Developers

return array(

	//Edit these per app.
	'template_dir' => 'C:/wamp/www/kohanaresources/application/views/',
	'cache_dir' => 'C:/wamp/www/kohanaresources/application/cache/',

	//Set to false in production application
	'auto_reload' => true,
	'debug' => true,

	//Misc settings. Don't touch unless you know what your doing.
	'trim_blocks' => false,
	'charset' => 'utf8',
	'base_template_class' => 'Twig_Template',
	'strict_variables' => false,

);
</pre>
<p>To access these array parameters that the developer sets, its a simple matter of:</p>
<pre>Kohana::config('twig.template_dir');</pre>
<h3>The View Class</h3>
<p><i>modules/twig/classes/view.php</i> is going to contain our class, <i>View</i>. It will handle the rendering of the template using Twig. As discussed above, we want our <i>View</i> class to have the same API as <i>Kohana_View</i>, so we will copy <i>system/classes/kohana/view.php</i> and make a small alteration to it. Most of the methods in <i>Kohana_View</i> provide different ways to set variables to the instance of <i>Kohana_View</i>. For example all three of these essentially do the same thing:</p>
<pre>$v = new View('some/template');

$v->website = 'Query7';
$v->set('website', 'Query7');
$v->bind('website', 'Query7');</pre>
<p>All loading and parsing of the template file is done in View::capture(). This is the only method from the original <i>Kohana_View</i> class that we will need to alter. Here is our new method in full:</p>
<p><b>modules/twig/classes/view.php &#8211; View::capture</b></p>
<pre>protected static function capture($kohana_view_filename, array $kohana_view_data)
{
	if (isset(View::$_global_data))
	{
		$data = array_merge($kohana_view_data, View::$_global_data);
	}
	else
	{
		$data = $kohana_view_data;
	}

	$loader = new Twig_Loader_Filesystem(Kohana::config('twig.template_dir'));

	$twig = new Twig_Environment($loader, array(

		'cache' => Kohana::config('twig.cache_dir'),
		'debug' => Kohana::config('twig.debug'),

		'auto_reload' => Kohana::config('twig.auto_reload'),
		'trim_blocks' => Kohana::config('twig.trim_blocks'),
		'charset' => Kohana::config('twig.charset'),
		'base_template_class' => Kohana::config('twig.base_template_class'),
		'strict_variables' => Kohan::config('twig.strict_variables')
	));

	$template = $twig->loadTemplate($kohana_view_filename);

	return $template->render($data);
}</pre>
<p>Our function first combines all data to be passed to the template in a single array, <i>$data</i>. It then instantiates <i>Twig_Loader_Filesystem</i> and passes the location of the template directory to it. <i>Twig_Enviroment</i> is then instantiated and the different configuration options are passed there. Finally the template is loaded and rendered.</p>
<h3>Example of <i>twig</i> in use</h3>
<p><b>some method in a controller</b></p>
<pre>$v = new View('colors.html');

$v->colors = array('red','blue','yellow','purple');

$this->request->response = $v->render();</pre>
<p><b>colors.html</b></p>
<pre>
{% for c in colors %}
    {{ c }},
{% endfor %}
</pre>
<p><b>output</b></p>
<pre>
red,blue,yellow,purple,
</pre>
<h3>Finishing Up</h3>
<p>After you have finished any Kohana module you should write the necessary documentation and tests. Kohana has it&#8217;s own <a href="https://github.com/kohana/unittest">module</a> that integrates PHPUnit with the Kohana framework. The majority of Kohana modules are open source on Github, with repositories named kohana-<i>*modulename*</i>. Finally you will want to promote your module. Announcing it on the Kohana <a href="http://forum.kohanaframework.org/">forum</a> and on Twitter are good ways to get it some attention.</p>
<p>If you have any questions or feedback please leave them in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/writing-a-module-for-kohana3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Introduction to Kohana3 PHP Framework</title>
		<link>http://query7.com/an-introduction-to-kohana3-php-framework</link>
		<comments>http://query7.com/an-introduction-to-kohana3-php-framework#comments</comments>
		<pubDate>Sun, 12 Dec 2010 23:25:30 +0000</pubDate>
		<dc:creator>logan</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://query7.com/?p=740</guid>
		<description><![CDATA[<p>This is a brief introduction into the Kohana framework. The next two tutorials will cover how to build a blog in Kohana.</p>
<h3>Installation</h3>
<p>Installing Kohana is very straight forward, just <a href="http://kohanaframework.org/download">download</a> the latest stable version of Kohana and unzip it. No need to mess around with yaml or xml files like other frameworks. Navigating to the directory on your web server should give you a page similar to&#8230;</p>
<p><a href="http://query7.com/wp-content/uploads/install.png"><img src="http://query7.com/wp-content/uploads/install.png" alt="" title="install" width="500" height="516" class="alignnone size-full wp-image-743" /></a></p>
<h3>Filesystem</h3>
<p>The filesystem plays a big part in the operation of the Kohana framework. Kohana follows the <a href="http://en.wikipedia.org/wiki/Presentation-abstraction-control">HMVC</a> pattern (hierarchical model view controller). This means that the same filesystem structure exists at multiple locations in the framework. The following directories exist in the <em>application</em>, <em>system </em>and in all module directories:</p>
<ul>
<li>classes</li>
<li>config</li>
<li>i18n</li>
<li>messages</li>
<li>tests</li>
</ul>
<p>When calling a class in Kohana, the autoloader checks if the class exists first in <em>application/classes/</em> , then in each of the installed modules, <em>classes</em> subdirectory and finally in <em>system/classes/</em>. If the file cannot be found then an exception is thrown. Kohana follows the <a href="http://query7.com/php-autoload">Zend_Class_Naming</a> style. For example, if you instantiated a class named Hello_World, Kohana would look at each of the following locations in this order. If it finds that&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>This is a brief introduction into the Kohana framework. The next two tutorials will cover how to build a blog in Kohana.</p>
<h3>Installation</h3>
<p>Installing Kohana is very straight forward, just <a href="http://kohanaframework.org/download">download</a> the latest stable version of Kohana and unzip it. No need to mess around with yaml or xml files like other frameworks. Navigating to the directory on your web server should give you a page similar to&#8230;</p>
<p><a href="http://query7.com/wp-content/uploads/install.png"><img src="http://query7.com/wp-content/uploads/install.png" alt="" title="install" width="500" height="516" class="alignnone size-full wp-image-743" /></a></p>
<h3>Filesystem</h3>
<p>The filesystem plays a big part in the operation of the Kohana framework. Kohana follows the <a href="http://en.wikipedia.org/wiki/Presentation-abstraction-control">HMVC</a> pattern (hierarchical model view controller). This means that the same filesystem structure exists at multiple locations in the framework. The following directories exist in the <em>application</em>, <em>system </em>and in all module directories:</p>
<ul>
<li>classes</li>
<li>config</li>
<li>i18n</li>
<li>messages</li>
<li>tests</li>
</ul>
<p>When calling a class in Kohana, the autoloader checks if the class exists first in <em>application/classes/</em> , then in each of the installed modules, <em>classes</em> subdirectory and finally in <em>system/classes/</em>. If the file cannot be found then an exception is thrown. Kohana follows the <a href="http://query7.com/php-autoload">Zend_Class_Naming</a> style. For example, if you instantiated a class named Hello_World, Kohana would look at each of the following locations in this order. If it finds that it exists, it will return.</p>
<ul>
<li>application/classes/hello/world.php</li>
<li>modules/*moduleName*/classes/hello/world.php (it would check every installed module)</li>
<li>system/classes/hello/world.php</li>
</ul>
<h3>Configuration</h3>
<p>All configuration is stored in the config directory (Because of the HMVC filesystem, there are multiple config directories and the specific configuration file you specify can exist in any of them). Configuration files return an array. For example if we made the file <em>application/config/hello.php</em> and set the contents as</p>
<pre>return array(

    'website' => 'Query7',
    'url' => 'http://www.query7.com'

);</pre>
<p>If we wanted to access the properties of this configuration file we would use the Kohana::config() method.<br />
Calling </p>
<pre>Kohana::config('hello')</pre>
<p>would return</p>
<pre>
return array(
    'website' => 'Query7',
    'url' => 'http://www.query7.com'

);
</pre>
<p>and calling </p>
<pre>Kohana::config('hello.website')</pre>
<p>would return</p>
<pre>Query7</pre>
<h3>Modules</h3>
<p>Modules provide additional features and can be easily added to your application. Kohana3 ships with some modules including <em>database</em>, <em>orm</em> and <em>userguide</em> (which contains documentation). To enable modules in your project open <em>application/bootstrap.php</em> and scroll to around line 78. There you will see:</p>
<pre>Kohana::modules(array(
    // 'auth'       => MODPATH.'auth',       // Basic authentication
    // 'cache'      => MODPATH.'cache',      // Caching with multiple backends
    // 'codebench'  => MODPATH.'codebench',  // Benchmarking tool
    // 'database'   => MODPATH.'database',   // Database access
    // 'image'      => MODPATH.'image',      // Image manipulation
    // 'orm'        => MODPATH.'orm',        // Object Relationship Mapping
    // 'oauth'      => MODPATH.'oauth',      // OAuth authentication
    // 'pagination' => MODPATH.'pagination', // Paging of results
    // 'unittest'   => MODPATH.'unittest',   // Unit testing
    // 'userguide'  => MODPATH.'userguide',  // User guide and API documentation
    ));</pre>
<p>To enable a module, just uncomment the line (remove the initial //). To install your own modules, put the un-archived module in your modules directory, and add a line to the array above. For example if you were installing the <a href="https://github.com/shadowhand/hive">hive</a> module (an ORM for Kohana), you would put the hive directory into your modules directory and add the following line to the array passed to <em>Kohana::modules()</em></p>
<pre>'hive' => MODPATH.'hive'</pre>
<p>Now that the hive module is installed, the Kohana autoloader will add <em>modules/hive/</em> to it&#8217;s path so it will check in that directory for classes and configuration files (if necessary).</p>
<p>Most modules come with their own configuration scripts. Because of the way the Kohana3 file system is structured, you can copy the default configuration script from <em>modules/*name*/config/*script*.php</em> and paste it in <em>application/config/*script*.php</em> and Kohana will immediately start using the configuration file located in your application directory. A good example of this is with the database module. The file <em>modules/database/config/database.php</em> contains all of the database connection information. Because this information is specific to our application it should be copied over to <em>application/config/database.php</em> and values edited appropriately. You do not need to delete the old <em>modules/database/config/database.ph</em>p because Kohana looks for <em>application/config/database.php</em> first and as soon as it finds it, it will return. Nothing in modules directory should contain anything specific to your application.</p>
<p>Modules can contain a file called init.php in the root directory (modules/*moduleName*/init.php). If the module is installed, this file is called every request.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/an-introduction-to-kohana3-php-framework/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

