


<?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>Learn DooPHP &#187; Demos &amp; Snippets</title>
	<atom:link href="http://learn.doophp.com/category/demos-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://learn.doophp.com</link>
	<description>Learn DooPHP - a high performance MVC based PHP framework</description>
	<lastBuildDate>Thu, 18 Aug 2011 19:47:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Handling sessions without Apache sessions</title>
		<link>http://learn.doophp.com/2010/09/handling-sessions-without-apache-sessions/</link>
		<comments>http://learn.doophp.com/2010/09/handling-sessions-without-apache-sessions/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 16:08:00 +0000</pubDate>
		<dc:creator>Milos Kovacki</dc:creator>
				<category><![CDATA[Demos & Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://learn.doophp.com/?p=216</guid>
		<description><![CDATA[<p>You are all familiar that Apache sessions are slow and sometimes insecure. In this text I will try to implement way of handling sessions with all Doo::cache mechanisms that are available in DooPhp.<br />
So our sessions will be stored in some of the cache mechanisms. First we will start with writting our session class that will start and end session, we will save it in protected/class folder.<br />
Here is our Session.class</p>
<pre class="brush: php;">
&#60;?php
/**
 * Session handler
 *
 * @author Milos Kovacki &#60;kovacki@gmail.com&#62;
 * @copyright Milos Kovacki 2010 &#60;kovacki@gmail.com&#62;
 */
 class Session
 {

 public static $_sessionId = NULL;
 public static $session = array();

 /**
 * Start session
 */
 public static function startSession() {
 self::$_sessionId = (isset($_COOKIE['session_id']) ? $_COOKIE['session_id'] : NULL);
 if ((!self::$_sessionId)&#124;&#124;(!(self::$session=Doo::cache(Doo::conf()-&#62;sessionCacheType)-&#62;get('session_'.self::$_sessionId)))) {
 // Create new session
 self::$_sessionId = md5($_SERVER['REMOTE_ADDR'] . time() . rand(0,128));
 self::$session['ip'] = $_SERVER['REMOTE_ADDR'];
 self::$session['created'] = time();
 }
 setcookie('session_id', self::$_sessionId, (time()+3600*24*90), '/');
 }

 /**
 * End session
 */
 public static function endSession() {
 $sessionStored = Doo::cache(Doo::conf()-&#62;sessionCacheType)-&#62;set('session_'.self::$_sessionId, self::$session);
 }

 }
</pre>
<p>You all noticed variable  Doo::conf()-&#62;sessionCacheType so we need to add it in our protected/config/common.conf edit it and add:</p>
<pre class="brush: php;">

$config['sessionCacheType'] = 'apc';
</pre>
<p>You can choose any type that is supported in Doo::cache, now we will edit our index.php, here is my bootstrap:</p>
<pre class="brush: php;">

&#60;?php
/**
* BOOTSTRAP
*/
//ini_set('display_errors', 1);
include './protected/config/common.conf.php';
include './protected/config/routes.conf.php';
include $config['BASE_PATH'].'Doo.php';</pre>]]></description>
		<wfw:commentRss>http://learn.doophp.com/2010/09/handling-sessions-without-apache-sessions/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Profiling and DB Profiling with DooPHP</title>
		<link>http://learn.doophp.com/2009/12/profiling-and-db-profiling-with-doophp/</link>
		<comments>http://learn.doophp.com/2009/12/profiling-and-db-profiling-with-doophp/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 15:41:08 +0000</pubDate>
		<dc:creator>Leng</dc:creator>
				<category><![CDATA[Demos & Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[db profiling]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[profiler]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://learn.doophp.com/?p=174</guid>
		<description><![CDATA[<p>If you have read the previous tutorial on <a href="http://learn.doophp.com/2009/12/using-doophp-logging-tools/">logging</a> you will find that <strong>profiling </strong>with DooPHP framework is relatively similar to the way you log messages.</p>
<p>Performance profiling can be used to measure the time &#38; memory needed for the specified code blocks and find out what the performance bottleneck is. Instead of calling log() you change it to<strong> beginProfile()</strong> and <strong>endProfile()</strong>. We need to mark the beginning and the end of each code block by inserting the following methods:</p>
<pre class="brush: php;">
Doo::logger()-&#62;beginProfile('block_id_here');
//...everything here will be profiled
Doo::logger()-&#62;endProfile('block_id_here');
</pre>
<p>Code blocks need to be nested properly. A code block cannot intersect with another. It must be either at a parallel level or be completely enclosed by the other code block.</p>
<p>All of the profiled results can be organized in category, simply pass in another parameter at the end of the method beginProfile():</p>
<pre class="brush: php;">
//default category is 'application'
Doo::logger()-&#62;beginProfile('id', 'editpost');
//...everything here will be profiled
Doo::logger()-&#62;endProfile('id');
</pre>
<p>To retrieve the profiled results, you called <strong>getProfileResult()</strong>. You have to pass in the block ID as parameter and you will get an associative array which shows you the time and memory used when processing the code block.</p>
<pre class="brush: php;">
Doo::logger()-&#62;beginProfile('block_id');
//...everything here will be profiled
Doo::logger()-&#62;endProfile('block_id');
$result = Doo::logger()-&#62;getProfileResult('block_id');
</pre>
<p>To view the profiled results, you just have to call showLogs(). By default it will return a neatly</p>]]></description>
		<wfw:commentRss>http://learn.doophp.com/2009/12/profiling-and-db-profiling-with-doophp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using DooPHP Logging Tools</title>
		<link>http://learn.doophp.com/2009/12/using-doophp-logging-tools/</link>
		<comments>http://learn.doophp.com/2009/12/using-doophp-logging-tools/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 02:58:16 +0000</pubDate>
		<dc:creator>Leng</dc:creator>
				<category><![CDATA[Demos & Snippets]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[normal]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://learn.doophp.com/?p=154</guid>
		<description><![CDATA[<p>DooPHP comes with its own <strong>profiler and logging tool</strong> by default. The class that handle this in the framework is DooLog (<em>dooframework/app/logging/DooLog.php</em>)</p>
<p>There are a few methods in this file where you can use for profiling and logging queries or important message in your application. You can log a message by calling:</p>
<pre class="brush: php;">
Doo::logger()-&#62;log('Something fishy here!', DooLog::Alert);
</pre>
<p>Or you can use the Alias methods instead of passing the log level:</p>
<pre class="brush: php;">
Doo::logger()-&#62;alert('Something fishy here!');
Doo::logger()-&#62;emerg('message...');
Doo::logger()-&#62;crit('message...');
Doo::logger()-&#62;err('message...');
Doo::logger()-&#62;warn('message...');
Doo::logger()-&#62;notice('message...');
Doo::logger()-&#62;info('message...');
Doo::logger()-&#62;trace('message...');
</pre>
<p>All of the log messages can be organized by category, simply pass in another parameter at the end of the methods:</p>
<pre class="brush: php;">
Doo::logger()-&#62;log('Something fishy here!', DooLog::ALERT, 'editpost');
Doo::logger()-&#62;emerg('message...', 'editpost');
Doo::logger()-&#62;alert('message...', 'editpost');
</pre>
<p>To view the logged messages, you just have to call showLogs(). By default DooLog will return a neatly formatted XML log which can be filtered by level or category. You can get a plain text log if you need so:</p>
<pre class="brush: php;">
//display all logs
echo Doo::logger()-&#62;showLogs();

//display plain text log
echo Doo::logger()-&#62;showLogs(false);

//display only logs in category editpost
echo Doo::logger()-&#62;showLogs(true, null, 'editpost');

//display only logs in level Alert and category editpost
echo Doo::logger()-&#62;showLogs(true, DooLog::ALERT, 'editpost');
</pre>
<p>When you have to write the log messages into file, all you have to do is call writeLogs(). Similar to showLogs(), it writes the XML string to file by default.</p>
<pre class="brush: php;">

//Creates a log file</pre>]]></description>
		<wfw:commentRss>http://learn.doophp.com/2009/12/using-doophp-logging-tools/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Concept of how to work with DooFramework</title>
		<link>http://learn.doophp.com/2009/09/concept-of-how-to-work-with-dooframework/</link>
		<comments>http://learn.doophp.com/2009/09/concept-of-how-to-work-with-dooframework/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 16:36:55 +0000</pubDate>
		<dc:creator>Milos Kovacki</dc:creator>
				<category><![CDATA[Demos & Snippets]]></category>

		<guid isPermaLink="false">http://learn.doophp.com/?p=114</guid>
		<description><![CDATA[<p>Ok in this article I will show you how should you work with DooFramework, when I am making website I like to have one super class that extends DooController class and in constructor of that class I will add all stuff needed for my application, so lets make that class, we should name it for example CoreController <img src='http://learn.doophp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: php;">
&#60;?php

class CoreController extends DooController {

 /**
 * Current URL
 */

 protected static $_currentUrl = null;

 /**
 * Instance of Doo::db
 */

 protected $_db = null;

 /**
 * Translator
 */
 protected $_translate = null;

 /**
 * Instance of Doo::cache
 */

 protected $_cache = null;

 /**
 * Base path of application
 */

 public $_basePath = null;

 /**
 * Instace of DooSession
 */
 public $_session = null;

 /**
 * Instance of DooAcl
 */

 public $_acl = null;

 /**
 * Host
 */

 public $host = null;

 /**
 * Js path
 */

 public  $jsPath = null;

 public function __construct() {
 $this-&#62;_basePath = Doo::conf()-&#62;ROOT_DIR;
 // add some globals that we need
 $this-&#62;_db = Doo::db();
 $this-&#62;_view = DooController::view();
 $this-&#62;host = Doo::conf()-&#62;host;
 $this-&#62;_view-&#62;host = Doo::conf()-&#62;host;
 // ACL
 $this-&#62;_acl = Doo::acl();
 // add sessions
 $this-&#62;_session = Doo::session(&#34;mywebsite&#34;);
 $templateVariables = $this-&#62;getSettings();
 // session
 $this-&#62;_view-&#62;_session = $this-&#62;_session;
 $this-&#62;_cache = Doo::cache('apc');
 $this-&#62;jsPath = $this-&#62;_view-&#62;host . 'static/js/';
 }

 /**
 * Before run method
 */

 public</pre>]]></description>
		<wfw:commentRss>http://learn.doophp.com/2009/09/concept-of-how-to-work-with-dooframework/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
