Author Archive

Using DooPHP Logging Tools

DooPHP comes with its own profiler and logging tool by default. The class that handle this in the framework is DooLog (dooframework/app/logging/DooLog.php)

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:

Doo::logger()->log('Something fishy here!', DooLog::Alert);

Or you can use the Alias methods instead of passing the log level:

Doo::logger()->alert('Something fishy here!');
Doo::logger()->emerg('message...');
Doo::logger()->crit('message...');
Doo::logger()->err('message...');
Doo::logger()->warn('message...');
Doo::logger()->notice('message...');
Doo::logger()->info('message...');
Doo::logger()->trace('message...');

All of the log messages can be organized by category, simply pass in another parameter at the end of the methods:

Doo::logger()->log('Something fishy here!', DooLog::ALERT, 'editpost');
Doo::logger()->emerg('message...', 'editpost');
Doo::logger()->alert('message...', 'editpost');

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:

//display all logs
echo Doo::logger()->showLogs();

//display plain text log
echo Doo::logger()->showLogs(false);

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

//display only logs in level Alert and category editpost
echo Doo::logger()->showLogs(true, DooLog::ALERT, 'editpost');

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.


//Creates a log file
More »

Moving protected folder outside your Web Root

In the latest trunk of the framework, we are able to move the protected folder in an application outside your web server root directory. Let’s say you have a structure as below:

www/
    superapp/
        proctected/
            index.php
            global/

To move it outside the WWW folder:

     superapp/
        proctected/

    www/
        superapp/
            index.php
            global/

Just change the configs after you move your files, SITE_PATH setting

//original
C:/wamp/www/superapp/

//changes
C:/wamp/superapp/

If you don’t wish to keep the name protected and wanted everything under superapp, try this:

    superapp/
        view/
        controller/
        .....
    www/
        superapp/
            index.php
            global/

Add on a new setting to common.conf.php, PROTECTED_FOLDER:

$config['PROTECTED_FOLDER'] = '';
More »

Using DooModel for Database Operations

If you have ever read DooPHP guide on model, you will see that a basic Model class does not have to extend any superclass.

A basic Model class looks like this:

class User{
    public $id;
    public $uname;
    public $pwd;
    public $group;
    public $vip;

    public $_table = 'user';
    public $_primarykey = 'id';
    public $_fields = array('id', 'uname', 'pwd', 'group', 'vip');
}

With the basic Model class, you can search for a database record by:

//$this->db()->find('User');  is the same
Doo::db()->find('User');

//search for one record
Doo::db()->find('User', array('limit'=>1) );

//search for a user named 'david'
Doo::db()->find('User', array('where'=>"uname='david'", 'limit'=>1) );

//using prepared statement to avoid sql injection
Doo::db()->find('User', array(
                    'where' => 'user=?',
                    'param' => array($_GET['name']),
                    'limit' => 1
                )
           );

//Or simply use this for shorter code.
Doo::loadModel('User');
$u = new User;
$u->uname = $_GET['name'];
$result = Doo::db()->find($u, array('limit'=>1));

Although the above code is pretty straightforward, we can make it even shorter and cleaner. First of all, we would need to have our Models to extend the DooModel class. We will have our Model class as the code below, notice the constructor:

Doo::loadCore('db/DooModel');
class User extends DooModel {
    public $id;
    public $uname;
    public $pwd;
    public $group;
    public $vip;

    public $_table = 'user';
    public $_primarykey = 'id';
    public $_fields = array('id', 'uname', 'pwd', 'group', 'vip');

    function __construct(){
         parent::$className = __CLASS__;
    }
}

By

More »

DooPHP Sitemap Generator Tool Demo

This is a demo showing you how to use DooPHP sitemap generator tools to generate routes as well as Controller classes.

DooPHP Sitemap Generator tool

More »