Posts Tagged ‘model’

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 »

Create a simple To Do List in DooPHP – Part 2

Introduction

This tutorial will guide you through all the steps required to get started using DooPHP through the creation of a simple To Do List Application. The tutorial is split into a number of sections and you will need to read the guide from the begining in order to understand whats going on.

  • Part 1 – Getting Started
  • Part 2 – The Signup Form
  • Part 3 – User Authentication – Coming Soon
  • Part 4 – The To Do List – Coming Soon
  • Part 5 – Adding AJAX Functionality – Coming Soon

Creating the Signup Form

The first thing we need to do is to create a new controller which will handel registration tasks. For this we will create a new Controller with the name RegistrationController and this will handel all aspects of registration. Right now this will consist of a single action – Signup. Therefore we must create a new file public_html\protected\controller\RegistrationController.php and the contents of this file will be:

More »

Create a simple To Do List in DooPHP – Part 1

Introduction

This tutorial will guide you through all the steps required to get started using DooPHP through the creation of a simple To Do List Application. The tutorial is split into a number of sections and you will need to read the guide from the begining in order to understand whats going on.

  • Part 1 – Getting Started
  • Part 2 – The Signup Form
  • Part 3 – User Authentication – Coming Soon
  • Part 4 – The To Do List – Coming Soon
  • Part 5 – Adding AJAX Functionality – Coming Soon

Our Objective for this Tutorial

In this tutorial we will be creating a simple To Doo List Manager Web Application and through the course of the tutorial we will be covering the following topics:

  • Obtaining and Deploying the Base DooPHP Application
  • Setting up the MySQL Database
  • Creating the Models
  • Creating the To Do Manager Application
    • Signup Form
    • User Authentication
    • User Home Page
    • Task Actions
    • Enhancing you application with AJAX

You can view a demo of the finished project here. Some screen shots of the final application are also included below:

TODO: IMAGES TO GO IN HERE WHEN I FINISH!

TODO: UPDATE THE DEMO LINK ABOVE

More »