HTML5 ane CSS3 for presentation slides

Here you can find my slides presented 2 days ago at Wordcamp Bulgaria. You will definitely need Firefox 4 beta 2 at least because my slides are based on DZslides, published by Paul Rouget and modified by me.

There is very funny video in there and you can learn Bulgarian while trying to understand what I am talking about :)

The good news is I was invited to WordCamp Romania and I will be presenting the same topic with the same technologies. I love OpenWeb and Open Technologies :)

Read More

How to Run Doctrine ORM with CodeIgniter

There are a lot of tutorials in the web regarding this subject, but I think this is the fastest and the easiest way to run a ORM solution with CodeIgniter.

How

1. Download (if you haven’t already) CodeIgniter
2. Download Doctrine from here
3. Extract CodeIgniter to your web root.
4. Extract Doctrine folder and Doctrine.php in system/plugins folder of your Coeigniter install.
5. Create a file with following content and save it in the same folder and name it as doctrine_pi.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
// system/application/plugins/doctrine_pi.php
 
// load Doctrine library
require_once BASEPATH.'/plugins/Doctrine.php';
 
// load database configuration from CodeIgniter
require_once APPPATH.'/config/database.php';
 
// this will allow Doctrine to load Model classes automatically
spl_autoload_register(array('Doctrine', 'autoload'));
 
// we load our database connections into Doctrine_Manager
// this loop allows us to use multiple connections later on
foreach ($db as $connection_name => $db_values) {
 
	// first we must convert to dsn format
	$dsn = $db[$connection_name]['dbdriver'] .
		'://' . $db[$connection_name]['username'] .
		':' . $db[$connection_name]['password'].
		'@' . $db[$connection_name]['hostname'] .
		'/' . $db[$connection_name]['database'];
 
	Doctrine_Manager::connection($dsn,$connection_name);
}
 
// CodeIgniter's Model class needs to be loaded
require_once BASEPATH.'/libraries/Model.php';
 
// telling Doctrine where our models are located
Doctrine::loadModels(APPPATH.'/models');
 
// (OPTIONAL) CONFIGURATION BELOW
 
// this will allow us to use "mutators"
Doctrine_Manager::getInstance()->setAttribute(
	Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
 
// this sets all table columns to notnull and unsigned (for ints) by default
Doctrine_Manager::getInstance()->setAttribute(
	Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS,
	array('notnull' => true, 'unsigned' => true));
 
// set the default primary key to be named 'id', integer, 4 bytes
Doctrine_Manager::getInstance()->setAttribute(
	Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS,
	array('name' => 'id', 'type' => 'integer', 'length' => 4));

6. Integration is ready.
7. Go to your system/application/config folder and edit:
7.1 autoload.php:

1
$autoload['plugin'] = array('doctrine');

7.2 database.php – fill your data
8. We are ready to make our first example

Why?

Doctrine is an Object Relational Mapper for PHP. It basically means that you can map your database tables to classes in your web application. You don’t need Models anymore and you don’t have to write SQL anyore, just use ORM.

Simple controller

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
 
class Users extends Controller {
 
	...
 
	function createuser()
	{
 
		$u= new User;	// The name of the ORM model and of the table
		$u->username = 'johndoe';
		$u->password = 'secret';
		$u->first_name = 'John';
		$u->last_name = 'Doe';
		$u->save();
 
 
 
	}
 
 
}

Here is the ORM model. Just few definitions, without a single track of SQL:)

1
2
3
4
5
6
7
8
9
10
class User extends Doctrine_Record {
 
	public function setTableDefinition() {
		$this->hasColumn('username', 'string', 255);
		$this->hasColumn('password', 'string', 255);
		$this->hasColumn('first_name', 'string', 255);
		$this->hasColumn('last_name', 'string', 255);
	}
 
}

This post was inspired by this tutorial here. You can see it, if you are interested in learning ORM from scratch with Doctrine and CodeIgniter, but PLEASE use this setup instead of described by other author..

Read More