Creating a bundle.


Making sure you have fit the needs of every other class can be tiring, and repetitive work. Especially if every time you make an upgrade you have to go into another class and add relationships, and various other methods to meet the dependencies. Bulding your bundle can honestly be as simple as creating an empty class.


Building your bundle class

Creating your first bundle is as simple as declaring a class. In fact thats all your doing. For the examples on this page the bundle I'm going to build is MyBundle so to start I am going to create a folder inside my bundle category folder called MyBundle. Then I'm going to declare the class Bundle inside the Bundles\MyBundle namespace. That's it you have created a Bundle. Now lets fill it.

_bundle.php

Using database models

You can make add database modeling and relationship support by extending the \Bundles\SQL\SQLBundle class. This will automatically read the configure/sql_bundle.yaml file and create the designated tables, and relationships between tables within and outside your bundle.

_bundle.php (using database models) configure/sql_structure.yaml

To create a relationship with another bundle you can define your relationship as - yourbundle.yourtable this will automatically create any needed fields on the other table.

To access a model of the current bundle you are going to use e::MyBundle()->getRow(id);. To access a list of rows you will use e::MyBundle()->getRows();. The singular and plural definitions are set inside the yaml configuration by the singular and plural

NOTE: You cannot call a model without setting the singular and plural of a table!


Using Event Methods

E3 has a flexible event system. By default the first time you call a bundle the method _on_first_use() method will be run. This is useful if you want to scan other bundles for extensions that this bundle needs to handle. For an example please reference out SQL bundle in library/SQLBundle.php and _bundle.php. You will notice that when you extend the SQLBundle we are loading your sql structure file, and storing it inside the Bundles\SQL\Bundle::$db_structure array. When _on_first_use() is called if there were any changes to the SQL Structure files it automatically updates the database as required.

To call an event you will run e::events()->myEvent(arg1, arg2); this will call the declared _on_myEvent(arg1, arg2) in EVERY bundle!

Download Evolution
System Requirements
PHP >= 5.3
Apache >= 2.0
MySQL >= 5.1
Apache mod_rewrite ~
PHP mbstring ~
PHP pcre ~
GIT ~