Posts Tagged ‘easy’

(Deutsch) DooPHP Einsteiger-Tutorial

Alle, die auf der Suche nach einem Einsteiger-Tutorial für den Start mit DooPHP sind, finden hier eine einfache Anleitung zur Installation und Basis-Konfiguration einer typischen Webanwendung: DooPHP Installation und Konfiguration

More »

Using DooTranslator for translation

DooTranslator finnaly came out, it supports “Csv“, “Gettext“, “Array“, “Ini” for now, soon it will be implemented other “file types”. So for example you have your translation file with this contents:

en.svn

test;"This is just a test!"

Lets initialize DooTranslator class:

$translator = Doo::translator('Csv', $this->_basePath . 'languages/en/LC_MESSAGES/en.csv');
 echo $translator->translate("test");

As you can see its very simple, first argument is file type for translation and second is path to the file, third argument can be options array. For Csv you can set options like: delimiter, enclosure and length. Default value for delimiter is “;” and for enclosure is “.

Now we will add some options to our call, lets say we want some other delimiter then “;” and we want to add some caching.

$translator = Doo::translator('Csv', $this->_basePath . 'languages/en/LC_MESSAGES/main.csv', array('cache' => 'apc', 'delimiter' => '|'));

So now we have added cache mechanism that is “apc” and we added delimiter that is “|”, now in our en.csv we must change delimiter:

test|"This is just a test!"

Supported cache mechanisms are “apc”, “php”, “xcache” and “eaccelerator”.

Now lets add placeholders for translate method:

$translator->translate("Hello [_1], wellcome to my website!", array("John"));

This will show translated string with: “Hello John, wellcome to my website!”.

Ok thats about it, if you have any questions please do ask, this is simple translation class its still

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 »