Giter VIP home page Giter VIP logo

hp_oms's Introduction

CodeIgniter 2 + HMVC + Doctrine 2

Setup ready to use CodeIgniter framework with:

How to use?

Configuration

Set up application/config/config.php and application/config/database.php for your network.

Load Doctrine library adding it on autoload.php, example:

$autoload['libraries'] = array('doctrine');

Or load Doctrine library in any controller, example:

$this->load->library('doctrine');

Creating models

This setup uses docblock annotations mapping driver and models namespace, you can change it in application/libraries/Doctrine.php.

Example of root model (not in a module), it should be inside application/models:

namespace models;

/**
 * @Entity
 * @Table(name="users")
 */
class User {
	/**
	 * @Id
	 * @Column(type="integer")
	 * @GeneratedValue
	 */
	private $id;

	/**
	 * @Column(type="string", length=32, nullable=false)
	 */
	private $username;
	
	// ...
}

Example of model in a module, it should be inside application/[module_name]/models. Note the difference in namespace:

// Prototype:
// namespace [module_name]\models;
// Example:
namespace auth\models;

class User {
	/**
	 * @Id
	 * @Column(type="integer")
	 * @GeneratedValue
	 */
	private $id;

	/**
	 * @Column(type="string", length=32, nullable=false)
	 */
	private $username;
	
	// ...
}

Creating schemas

To generate automatically schemas for your models you can use the Doctrine console or the schema tool from library:

$this->doctrine->tool->createSchema('auth\models\User');

Other useful methods:

$this->doctrine->tool->dropSchema('auth\models\User');

$this->doctrine->tool->updateSchema('auth\models\User');

Using models

Loading from controllers it's easy, example:

$user = new auth\models\User;
// ...
$this->doctrine->em->persist($user);

You can also shorten the instantiation with the use operator (before class definition):

use auth\models\User;

class Test extends CI_Controller {
	// ...
	
	public function index()
	{
		$user = new User;
		// ...
	}
}

Doctrine console

Doctrine console can be used in terminal from application/third_party/doctrine-orm/bin/doctrine, examples:

php doctrine list

php doctrine orm:schema-tool:create

php doctrine orm:schema-tool:update

php doctrine orm:schema-tool:drop

More information

hp_oms's People

Contributors

rufusmbugua avatar

Watchers

James Cloos avatar Collins Ojenge avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.