Learn DooPHP: High performance PHP framework

Concept of how to work with DooFramework

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 :)

<?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->_basePath = Doo::conf()->ROOT_DIR;
 // add some globals that we need
 $this->_db = Doo::db();
 $this->_view = DooController::view();
 $this->host = Doo::conf()->host;
 $this->_view->host = Doo::conf()->host;
 // ACL
 $this->_acl = Doo::acl();
 // add sessions
 $this->_session = Doo::session("mywebsite");
 $templateVariables = $this->getSettings();
 // session
 $this->_view->_session = $this->_session;
 $this->_cache = Doo::cache('apc');
 $this->jsPath = $this->_view->host . 'static/js/';
 }

 /**
 * Before run method
 */

 public
Read More...

DooForm learn to work with forms

Ok in this tutorial I will show you how do you work with forms, its very simple.
Loading DooForm helper is very easy:

Doo::loadHelper('DooForm');

First you create form from array and then just call

echo $form->render();

To render the form, render function is returning html of the form. So we will begin making one simple element, lets say textfield:

$form = new DooForm(array(
    'method' => 'post',
    'action' => $action,
    'elements' => array(
        'username' => array('text', array(
            'required' => true,
            'label' => 'My username: ',
            'attributes' => array("style" => 'border:1px solid #000;', 'class' => 'username-field'),
            'field-wrapper' => 'div',
            'validators' => array(
                array('username',4,7),
                array('maxlength',6,'This is too long'),
                array('minlength',6)
             )
        ))
    )
));

As you can see all form data you can add into form array, so when you are creating form you will have to define method, action and elements you have in your form, elemnts is another array, that array will contain all form elements. You begin with naming your element and then create array that will describe that element (type, label, validators, field-wrappers, etc…)

So in element you will have for example:


'username' => array('text', array(
    'required' => true,
    'label' => 'My username: ',
    'attributes' => array("style" => 'border:1px solid #000;', 'class' => 'mitar'),
    'field-wrapper' => 'div',
    'validators' => array(
        array('username',4,7),
        array('maxlength',6,'This is too long'),
        array('minlength',6))
    )
),

So

Read 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

Read 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

Read More...