• Stars
    star
    188
  • Rank 205,563 (Top 5 %)
  • Language
    PHP
  • Created almost 13 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create HMVC modules with this lightweight extension for Codeiginter 2

CodeIgniter HMVC Modules

This extension for CodeIgniter enables the use of the Hierarchical Model View Controller(HMVC) pattern and makes your application modular. This allows easy distribution of independent components (MVC) in a single directory across other CodeIgniter applications. All modules are grouped in their own folder and can have their own controller, model, view, library, config, helper and language files.

Installation

Download the file from github and place them into their corresponding folders in the application directory.

Note: to use the HMVC functionality, make sure the Controller and Router you use extend their HMVC class.

Next, add the location of your modules directory to the main config.php file:

/*
|--------------------------------------------------------------------------
| Modules locations
|--------------------------------------------------------------------------
|
| These are the folders where your modules are located. You may define an
| absolute path to the location or a relative path starting from the root
| directory.
|
*/

$config['modules_locations'] = array(APPPATH . 'modules/');

Functionallity

This is the basic structure of a HMVC module:

/modules
    /module
       /controllers
       /config
       /helpers
       /language
       /libraries
       /models

From within a module you can load its own resources just like you always do. If on the other hand, you want to load resources from another module you can do this by adding the module's name like a directory structure:

class Hello extends CI_Controller {
    
    public function index() {
        // load a model from the current module
        $this->load->model('local_model');
        
        // load a model from another module
        $this->load->model('other_module/model');

        // HMVC example
        $this->load->controller('module/controller/method', $params = array(), $return = FALSE);
    }
}

Because of the modified router, the module's controllers are accessible like a directory structure. Controllers may be loaded from the application/controllers sub-directories or the module/controllers sub-directories:

/module/hello -> /module/controllers/hello.php (index method)
/module/hello -> /module/controllers/hello/hello.php (index method)
/module/hello -> /module/controllers/hello/(default_controller).php (hello method)
/module/hello -> /module/controllers/module.php (hello method)
/module/hello -> /module/controllers/(default_controller).php (hello method)

If the requested module contains a routes.php config file it will automatically be added to the main routes.

Hierarchical controllers

To load hierarchical controllers you use the $this->load->controller() method. This method works similar to loading views with CodeIgniter, this method accepts the following parameters:

  • URI: a URI string pointing to the requested controller (and method). This function uses the same locating technique as explained above.
  • Parameters: an array containing the arguments for the requested method.
  • Return : a boolean indicating whether the output should be returned or show on the screen (default).

For example, this is our main controller where we pass the request to a sub-controller in the same module:

class Specials extends CI_Controller {
    
    public function index() {
        $this->load->controller('blogs/random', array('specials'));
    }
    
}

And the sub-controller contains the real method:

class Blogs extends CI_Controller {

    public function random($type) {
        ...
    }
    
}

More Repositories

1

agent

👮 A PHP desktop/mobile user agent parser with support for Laravel, based on Mobiledetect
PHP
4,541
star
2

imagehash

🌄 Perceptual image hashing for PHP
PHP
1,976
star
3

date

🗓 A library to help you work with dates in multiple languages, based on Carbon.
PHP
1,813
star
4

optimus

🤖 Id obfuscation based on Knuth's multiplicative hashing method for PHP.
PHP
1,264
star
5

php-proxy

A PHP proxy script with https and post support
PHP
933
star
6

blade

🔪 A standalone version of Laravel's Blade templating engine for use outside of Laravel.
PHP
823
star
7

model

This model provides an eloquent-like base class that can be used to build custom models in Laravel and other frameworks
PHP
379
star
8

RTL8188-hostapd

hostapd for Realtek RTL8188
C
333
star
9

laravel-rollbar

Rollbar error monitoring integration for Laravel projects
PHP
329
star
10

laravel-ab

A server-side A/B testing tool for Laravel.
PHP
288
star
11

captain

⚓️ Easily start and stop docker compose projects
Go
241
star
12

codeigniter-advanced-images

Resize and crop images on the fly
PHP
181
star
13

dashboard

A server dashboard for Ubuntu
PHP
136
star
14

codeigniter-template-library

A template library for Codeigniter
PHP
107
star
15

laravel-raven

Sentry (Raven) error monitoring integration for Laravel projects
PHP
90
star
16

laravel-mongodb-session

A MongoDB session driver for Laravel
PHP
77
star
17

codeigniter-authentication-library

A secure authentication library for CodeIgniter
PHP
68
star
18

laravel-oauth

A Laravel OAuth 1 & 2 library
PHP
65
star
19

laravel-mongodb-sentry

An extension for Laravel-MongoDB that lets you work with Sentry
PHP
54
star
20

codeigniter-message-library

Store and display error or information messages to display on the current page or next page
PHP
51
star
21

lean

Use the PHP League's Container package with auto-wiring support as the core container in Slim 3
PHP
31
star
22

laravel-mongodb-core

A MongoDB based query builder for Laravel
PHP
28
star
23

php-chef

Opscode Chef API PHP library
PHP
20
star
24

chef-patch

Helps you replace text and lines in files from Chef recipes.
Ruby
20
star
25

palenight.zsh-theme

My custom zsh theme
13
star
26

laravel-mongodb-lite

A lightweight MongoDB database library and model for Laravel 4
PHP
11
star
27

vagrant

My personal Vagrant development environment
HTML
7
star
28

quotebot

Quotebot for slack
TypeScript
5
star
29

docker

My personal Docker setup
5
star
30

docker-php-cs-fixer

A tool to automatically fix PHP coding standards issues
4
star
31

ddd-oke-cars

PHP
4
star
32

docker-php

Custom PHP docker image with some basic extensions
Dockerfile
4
star
33

cryptonope

Replace crypto words with random things
JavaScript
3
star
34

homebrew-custom

Custom homebrew formulas
Ruby
2
star
35

auto-commit

JavaScript
2
star
36

spacegray-monokai

A Monokai color scheme for Sublime's Spacegray theme
1
star