Author Archive

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

More »

Quick guide to DooSession

This will be a quick guide how to use DooSession, first of all you need to call a DooSession class, I love to have one super class that extends DooController class. In super class constructor I make session and create everything I need for a website.

Calling session class needs one parameter and thats namespace name, often you wish to put name for your session.

$this->_application = Doo::session("mywebsite");

Now that you created session namespace you can start using it, storing in session and getting stuff from it. For example you want to define username of user that is registered:

$this->_application->user = "John";

Now you are accessing it from controller with:

$this->_application->user

Another nice thing is to have access to session from your view scripts, I am doing it like this, inside constructor of my super class I add:

$data['application'] = Doo::session("mywebsite");
$this->renderc('templatefile', $data);

Now from your view scripts you can access your user variable like:

$this->data['application']->user

Thats about it, all functions that you have in doo session class are in API.

http://doophp.com/documentation/api_svn

More »