Skip to content
This repository was archived by the owner on Apr 9, 2018. It is now read-only.

2. Getting Started

Circle Creative edited this page May 15, 2015 · 1 revision

Basic Knowledge

If you have experience using CodeIgniter it's won't be a big problems for understanding O2System. Basically O2System can become as alternative framework for building your web-based application. Much has same syntax with CodeIgniter, for reference you can read also CodeIgniter 3.0-dev User Guide.

Main Concept

Basically O2System has same concept with CodeIgniter it has Super Global Object, get_instance() function. The different are CodeIgniter is based on MVC only (Model-View-Controller) to do Modularity you must add third_party HMVC plugin into CodeIgniter such as O2System HMVC plugin for CodeIgniter and only support for single application building, O2System is based on HMVC (Hierarchical-Model-View-Controller) so is already supported for Modularity and with O2System you can built multi-application in one integrated core system.

System Registry

O2System is collected the map of your folder structure from the the first system is initiated. This is the heart of the system. For example please take a look at system/core/Loader.php. O2System do different way to loading file than CodeIgniter. O2System doesn't loop the paths for searching, because the System Registry has provide the path data. All the loader need to do is validate the requested.

Folder Structure

Single Application Example

apps
-- core
-- helpers
-- libraries
-- languages
-- models
-- views
-- controllers
-- modules
----- your_module_name
------ helpers
------ libraries
------ languages
------ models
------ views
------ controllers
system
-- core
-- helpers
-- libraries
-- languages
-- models
-- views
-- controllers
-- vendor
.htaccess
index.php

Multi Applications Example

apps
-- core
-- helpers
-- libraries
-- languages
-- models
-- views
-- controllers
-- your_app
---- core
---- helpers
---- libraries
---- languages
---- models
---- views
---- controllers
---- modules
----- your_module_name
------ helpers
------ libraries
------ languages
------ models
------ views
------ controllers
system
-- core
-- helpers
-- libraries
-- languages
-- models
-- views
-- controllers
-- vendor
.htaccess
index.php

The folder structure at each app and each module under app is same folder structure with system folder, you can add the folder based on your needs.

URL Pattern

O2System has a little bit different on the URL Pattern.

  • CodeIgniter Standard
http://localhost/controller/method/params
  • CodeIgniter with HMVC or O2System with Single Application
http://localhost/module/method/params 
(for accessing the module and controller which has same name with the module)

http://localhost/module/controller/method/params
(for accessing other controller at the module)
  • O2System with Multi-Applications
http://localhost/controller/method/params
(for accessing global apps controller)

http://localhost/module/method/params 
(for accessing the based app module and controller which has same name with the module)

http://localhost/module/controller/method/params
(for accessing other controller at the based app module)

http://localhost/app/module/method/params 
(for accessing the other app module and controller which has same name with the module)

http://localhost/app/module/controller/method/params
(for accessing other controller at the other app module)

Working with Composer

O2System is supported for development using composer autoload. The big different from O2System with CodeIgniter or Laravel is by default O2System has composer autoload on system folder (system/vendor) but you can add custom vendor under your apps folder (apps/vendor) also you can add under each app and each app module.

Others framework load all dependencies that defined on composer.json from the the first system is initiated. O2System doesn't load all at the same time, depends on your needs. For example if you has add custom vendor at the your app the O2System loader only load all composer vendor from system, apps, and your requested access app (by url or as defined on BASEAPP) same with the module under your app. It's only load when you access the module.

Inheritance and Overriding

O2System has inheritance based on loading.

  • Libraries, Controllers and Drivers Classes For extending the system classes you can extends start from the apps->app->module. Example:
O2_Controller 
-- App_Controller extends O2_Controller
---- Myapp_Controller extends App_Controller
------ Myapp_Modulename_Controller extends App_Controller
  • Configuration Overriding Sequence For overriding the main apps config you can create the same config file at apps, app, or module. Example:
apps/config/config.php
-- app/config/config.php (override with same variable or same key name)
  • Views Overriding Sequence Apps Views, App View, Module View can be replaced by created same view name under apps, app, module or themes module views. Example:
apps/views/error_404.tpl
-- app/views/error_404.tpl
-- app/modules/module_name/views/error_404.tpl
-- app/themes/theme_name/modules/module_name/error_404.tpl

Smart Loader

O2System can help you to perform load cross app and cross app modules. The syntax is still the same with CodeIgniter the only different is the called path

Standard Load

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

For Cross App Load

$this->load->library('app_name/class_name');

For Cross App Module Load

$this->load->library('app_name/module_name/class_name');

Avaliable load method: helper, library, driver, composer, model, view, theme, layout, config, lang Coming soon method: module, controller

Developer Helper

Usually for send output to the browser we are using this kind of methods:

1. echo '<pre>'.print_r($array).'</pre>'; die;
2. var_dump($array); die;

With O2System Developer Helper you can do much shorter, much better look also you can see the debug back traces.

1. print_out($array, $backtrace, $die); (for $backtrace and $die it's set to TRUE by default)
2. print_lines($something, $end); (for print combined lines, $end it's set to FALSE by default - set it into TRUE when you need the print line to be stopped - you can call it everywhere)

Avaliable developer function: print_out, print_lines, print_line_marker, print_dump, print_code, print_console Coming soon function: print_firebugs

Clone this wiki locally