Posts Tagged ‘difficult’

Managing your database(s) with DooPHP

This tutorial will demonstrate how to use the DooManageDb and DooUpdateDb classes to manage your projects database.

These classes have been developed to allow your application(s) to be independent of the database your users choose to use by allowing standard database definition to be used to define your database which is then translated into the SQL needed for the database engine the user is using. It also supports easy upgrading (and downgrading) of the database to allow for better version control support and rolling out of updates and unit testing.

In order to follow this tutorial you will need to use the latest version of DooPHP avaliable form the SVN repository (or version 1.3 or above – not out at the time of writing). The current implementation only supports MySQL and PgSQL at the moment so you will also need one of these 2 databases in order to follow the guide.

The first thing we need to do is to create a simple controller to run our tests from. Therefore create a new controller in your protected/controller/ folder. In this example I will use the controller “DatabaseController”. Now enter the following into the controller:

<?php
class DatabaseController extends DooController {

	public function updateDatabase() {

		echo '<h1>Update Database to Head</h1>' . PHP_EOL;

		/* DB Updater
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 »