PHPackages                             voodoophp/voodoo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. voodoophp/voodoo

ActiveFramework[Framework](/categories/framework)

voodoophp/voodoo
================

A micro PHP 5.4 Modular MVC framework, that contains only the libraries to get you started

1.21.0(12y ago)7321010[2 issues](https://github.com/mardix/Voodoo/issues)MITPHPPHP &gt;=5.4.0

Since Mar 10Pushed 2y ago4 watchersCompare

[ Source](https://github.com/mardix/Voodoo)[ Packagist](https://packagist.org/packages/voodoophp/voodoo)[ Docs](https://github.com/mardix/Voodoo)[ RSS](/packages/voodoophp-voodoo/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (17)Used By (0)

Voodoo 1.x.x
============

[](#voodoo-1xx)

#### A Simple, Easy, Intuitive PHP Framework for Those Who Keep It Simple

[](#a-simple-easy-intuitive-php-framework-for-those-who-keep-it-simple)

---

Name: Voodoo

License: MIT

Design: Modular MVC

Requirements: PHP 5.4

Compliance: PSR-2

Author: [Mardix](http://github.com/mardix)

Copyright: This Year - Mardix

[VoodooPHP.org](http://voodoophp.org)

[Forums](https://groups.google.com/d/forum/voodoophp/)

*This is an overview of Voodoo, please go to [VoodooPHP.org](http://voodoophp.org) for a complete documentation of the framework*

---

About Voodoo!
-------------

[](#about-voodoo)

Voodoo is Modular MVC framework written in PHP. Its main goal is to ensure separation of concerns by keeping your code organized and avoid mixing database calls, HTML tags and business logic in the same script.

Voodoo, first, organize your application into subset of MVC structure which are independent from other one. These subsets are called Modules. Modules can be an admin section, the main site, intranet, or can be used for A/B testing.

Modules improve maintainability by enforcing logical boundaries between components. By being Modular, Voodoo allows developers/designers to work on individual module at the same time, thus making development of program faster. New features or new sections can be implemented quickly without changing other sections. And when it's no longer needed, the module can be deleted and everything is still gravy.

---

### Features Highlight

[](#features-highlight)

- Slim
- RESTful
- API ready
- MVC
- Shared Application
- Modular MVC
- Namespaced
- PSR compliant
- Front Controller
- Templates
- Handlebars (templating system)
- Smart Routing
- [VoodOrm](https://github.com/mardix/VoodOrm)
- Annotation
- [Paginator](https://github.com/mardix/Paginator)
- [Handlebars](https://github.com/mardix/Handlebars)
- Bootstrap CSS/JS framework
- HTTP Request
- Voodooist (generate code on the fly)

---

Install Voodoo with Composer
----------------------------

[](#install-voodoo-with-composer)

To install Voodoo, create or edit the **composer.json** file, and add the code below in the 'require':

```
"voodoophp/voodoo": "1.*"

```

Your composer.json file should look something similar to this:

```
{
    "name": "voodoophp/myapp",
    "description": "My awesome Voodoo App",
    "require": {
        "voodoophp/voodoo": "1.*"
    }
}

```

then run the command below to download Voodoo and its dependencies

```
composer install

```

Assuming that your composer installed the packages in your `/vendor` directory, you should see at least the following when you go inside of /vendor

```
	|
	+-- composer.json
	|
	+-- vendor/
		|
		+-- composer/
		|
		+-- voodoophp/

```

---

Setup &amp; Filesystem
----------------------

[](#setup--filesystem)

Now the Voodoo is installed, it's time to set it up so it creates the directories for your applications.

Assuming that composer installed packages in your `/vendor` directory, the Voodoo framework will be in: `/vendor/voodoophp/voodoo`

Enter the command below

```
cd vendor/voodoophp/voodoo/src/Voodoo/Voodooist
php ./setup.php

```

Once the setup is done, you should have a filesystem similar to this:

```
|
+-- App/
	|
	+-- .htaccess
	|
	+-- _conf/
	|
	+-- Www/
		|
		+-- Config.conf.php
		|
		+-- Main/
			|
			+-- Controller/
			|
			+-- Model/
			|
			+-- Views/
|
+-- assets/
	|
	+-- bootstrap/
	|
	+-- css/
	|
	+-- img/
	|
	+-- js/
	|
	+-- jquery/
|
+-- vendor
		|
		+-- composer/
		|
		+-- voodoophp/
|
+-- composer.json
|
+-- .htaccess
|
+-- index.php
|
+-- robots.txt

```

**/App** : Contains your application's Modular MVC

**/App/\_conf** : Contains the configurations, ie: DB.conf.php for database settings, System.conf.php for system wide settings, app.json your application schema to create your MVC files on the fly.

**/App/Www**: That's your default application which contains your MVC files. When someone accesses your application that's where he/she will land, unless you change it to another application. You can also have */App/Site1*, */App/Site2*, */App/Api* and so on to create multi applications which share the same Voodoo code base.

**/assets/**: That's your application shared assets. For your convenience, we added Bootstrap and JQuery.

**/vendor/**: Where composer installed the packages

**/composer.json**: The composer file

**/index.php**: The front-controller file which redirect everything to Voodoo to do its magic!

---

The Voodooist
-------------

[](#the-voodooist)

The Voodooist is our servant, it will help us create directories and files properly namespaced per PSR-0 in our Voodoo application.

Once our application has been setup, Voodooist requires: /App/\_conf/app.json and /App/voodooist.php. These files were created during the initial setup.

#### - App/\_conf/app.json

[](#--app_confappjson)

**App/\_conf/app.json** is a JSON file that contains the layout of your application, including modules, controllers, controller's action etc. It is ran by Voodooist to setup your application. Below is a basic **app.json**

```
{
    "createPublicAssets" : true,
    "applications" : [
        {
            "name" : "www",
            "modules" : [
                {
                    "name" : "Main",
                    "template" : "Default",
                    "isApi" : false,
                    "omitViews" : false,

                    "controllers" : [
                        {
                            "name" : "Index",
                            "actions" : ["index", "login", "logout", "about-us"]
                        },
                        {
                            "name" : "Account",
                            "actions" : ["index", "info", "preferences"]
                        }
                    ],

                    "models" : [
                        {
                            "name" : "User",
                            "dbAlias" : "MyDB",
                            "table" : "user",
                            "primaryKey" : "id",
                            "foreignKey" : "%s_id"
                        },
                        {
                            "name" : "User/Preference",
                            "dbAlias" : "MyDB",
                            "table" : "user_preference",
                            "primaryKey" : "id",
                            "foreignKey" : "%s_id"
                        }
                    ]
                }
            ]
        }
    ]
}

```

#### - /App/Voodoist.php

[](#--appvoodoistphp)

Once Voodoo is setup, you won't need to go the `/vendor/voodoophp/voodoo/src/Voodoo/Voodooist/setup.php` to create your application's files. Voodoo created `/App/voodooist.php` to serve the same purpose. You will need it to create your application's files on the fly based on your /App/\_conf/app.json. All files will be properly namespaced per PSR-0, and placed inside of /App under their respective application.

Running the code below, will execute the `/App/_conf/app.json` set above:

```
cd /App
php ./voodooist.php

```

Upon execution of /App/voodooist.php you will should see a filesystem similar to this:

```
|
+-- App/
	|
	+-- .htaccess
	|
	+-- Www
        |
        +-- Config.conf.php
		|
		+-- Main
			|
			+-- Controller/
                |
                +-- BaseController.php (extends Voodoo\Core\Controller)
				|
				+-- Index.php (extends BaseController)
						::actionIndex()
						::actionLogin()
						::actionLogout()
						::actionAboutUs()
				|
				+-- Account.php (extends BaseController)
						::actionIndex()
						::actionInfo()
						::actionPreferences()
			|
			+-- Model/
				|
				+-- User.php
                |
                +-- User/Preference.php
			|
			+-- Views/
				|
				+-- Index/
					|
					+-- Index.html
					|
					+-- Login.html
					|
					+-- Logout.html
					|
					+-- AboutUs.html
				|
				+-- Account/
					|
					+-- Index.html
					|
					+-- Info.html
					|
					+-- Preferences.html
				|
				+-- _assets/
					|
					+-- js/
					|
					+-- css/
					|
					+-- img/
				|
				+-- _components/
					|
					+-- flash-message.html
					|
					+-- pagination.html
				|
				+-- _layouts/
					|
					+-- default.html
					|
					+-- head-tag.html
					|
					+-- footer.html
					|
					+-- header.html
|
+-- assets/ [+]
|
+-- vendor/ [+]
|
+-- index.php
|
+-- .htaccess

```

### Application (Multi-Applications)

[](#application-multi-applications)

Application is the upper level of your program. Everything must be in an application. An application can be another site sharing the same Voodoo code base of other application. Hence making Voodoo multi-sites , multi-applications ready.

You can have *Site1.com*, *Site2.com*, *SiteX.com* all under the same environment sharing the same front controller, same Voodoo code base. And since your application is namespaced PSR-0, it's easy to re-use code from other applications.

Inside of each applications are the applications modules. By default Voodoo creates the **WWW** which is the default entry point of your site. In large, Applications are sets of Modules. A more advance app.json looks like that with three applications: *Www, AnotherApp, Api*

/App/\_conf/app.json

```
{
    "createPublicAssets" : true,
    "applications" : [
        {
            "name" : "www",
            "modules" : [
                {
                    "name" : "Main",
                    "template" : "Default",
                    "isApi" : false,
                    "omitViews" : false,

                    "controllers" : [
                        {
                            "name" : "Index",
                            "actions" : ["index", "login", "logout", "about-us"]
                        },
                        {
                            "name" : "Account",
                            "actions" : ["index", "info", "preferences"]
                        }
                    ],

                    "models" : [
                        {
                            "name" : "User",
                            "dbAlias" : "MyDB",
                            "table" : "user",
                            "primaryKey" : "id",
                            "foreignKey" : "%s_id"
                        },
                        {
                            "name" : "User/Preference",
                            "dbAlias" : "MyDB",
                            "table" : "user_preference",
                            "primaryKey" : "id",
                            "foreignKey" : "%s_id"
                        }
                    ]
                }
            ]
        },
        {
            "name" : "AnotherApp",
            "modules" : [
                {
                    "name" : "Main",
                    "template" : "Default",
                    "isApi" : false,
                    "omitViews" : false,

                    "controllers" : [
                        {
                            "name" : "Index",
                            "actions" : ["index", "info"]
                        }
                    ]
                },
                {
                    "name" : "Admin",
                    "template" : "Default",
                    "isApi" : false,
                    "omitViews" : false,

                    "controllers" : [
                        {
                            "name" : "Index",
                            "actions" : ["index", "login"]
                        }
                    ]
                }
            ]
        },
        {
            "name" : "Api",
            "modules" : [
                {
                    "name" : "Main",
                    "template" : "",
                    "isApi" : true,
                    "omitViews" : true,

                    "controllers" : [
                        {
                            "name" : "Index",
                            "actions" : ["index", "status"]
                        }
                    ]
                }
            ]
        }
    ]
}

```

After running /App/voodooist.php you will get the following structure

```
|
+-- App/
	|
	+-- .htaccess
	|
	+-- Www
        |
        +-- Config.conf.php
		|
		+-- Main
			|
			+-- Controller/
                |
                +-- BaseController.php (extends Voodoo\Core\Controller)
				|
				+-- Index.php (extends BaseController)
						::actionIndex()
						::actionLogin()
						::actionLogout()
						::actionAboutUs()
				|
				+-- Account.php (extends BaseController)
						::actionIndex()
						::actionInfo()
						::actionPreferences()
			|
			+-- Model/
				|
				+-- User.php
                |
                +-- User/Preference.php
			|
			+-- Views/
				|
				+-- Index/
					|
					+-- Index.html
					|
					+-- Login.html
					|
					+-- Logout.html
					|
					+-- AboutUs.html
				|
				+-- Account/
					|
					+-- Index.html
					|
					+-- Info.html
					|
					+-- Preferences.html
				|
				+-- _assets/
					|
					+-- js/
					|
					+-- css/
					|
					+-- img/
				|
				+-- _components/
					|
					+-- flash-message.html
					|
					+-- pagination.html
				|
				+-- _layouts/
					|
					+-- default.html
					|
					+-- head-tag.html
					|
					+-- footer.html
					|
					+-- header.html
	|
	+-- AnotherApp
        |
        +-- Config.conf.php
		|
		+-- Main
			|
			+-- Controller/
                |
                +-- BaseController.php (extends Voodoo\Core\Controller)
				|
				+-- Index.php (extends BaseController)
						::actionIndex()
						::actionInfo()
			|
			+-- Views/
				|
				+-- Index/
					|
					+-- Index.html
					|
					+-- Info.html
				|
				+-- _assets/[+]
				|
				+-- _components/ [+]
				|
				+-- _layouts/ [+]
		|
		+-- Admin
			|
			+-- Controller/
                |
                +-- BaseController.php (extends Voodoo\Core\Controller)
				|
				+-- Index.php (extends BaseController)
						::actionIndex()
						::actionLogin()
			|
			+-- Views/
				|
				+-- Index/
					|
					+-- Index.html
					|
					+-- Login.html
				|
				+-- _assets/[+]
				|
				+-- _components/ [+]
				|
				+-- _layouts/ [+]
	|
	+-- Api
        |
        +-- Config.conf.php
		|
		+-- Main
			|
			+-- Controller/
                |
                +-- BaseController.php (extends Voodoo\Core\Controller\Api)
				|
				+-- Index.php (extends BaseController)
						::actionIndex()
						::actionStatus()
|
+-- assets/ [+]
|
+-- vendor/ [+]
|
+-- index.php
|
+-- .htaccess

```

### Modules

[](#modules)

Modules are the second level of your application. Application are sets of Modules and Modules are set of MVC application.

Each module contains one set of MVC. By default Voodoo will fall back to `Main` module if a module is not specified.

That's how the module **Main** looks like in the **Www** application.

```
|
+-- App/
	|
	+-- .htaccess
	|
	+-- Www
		|
		+-- Config.conf.php
		|
		+-- Main
			|
			+-- Controller/
				|
				+-- Index.php
						::actionIndex()
						::actionAbout()
			|
			+-- Model/
				|
				+-- MySampleModel.php
			|
			+-- View/
				|
				+-- Index/
					|
					+-- Index.html
					|
					+-- About.html
				|
				+-- _assets/
					|
					+-- js/
					|
					+-- css/
					|
					+-- img/
				|
				+-- _components/
					|
					+-- flash-message.html
					|
					+-- pagination.html
				|
				+-- _layouts/
					|
					+-- default.html
					|
					+-- head-tag.html
					|
					+-- footer.html
					|
					+-- header.html
|
+-- assets/ [+]
|
+-- vendor/ [+]
|
+-- index.php
|
+-- .htaccess

```

All classes are namespaced per PSR-0. So the main namespace for Www/Main are as follow:

```
App\Www\Main
App\Www\Main\Controller
App\Www\Main\Controller\Index
App\Www\Main\Model
App\Www\Main\Model\MySampleModel

```

Substitute `Www` for any other application name you would have the same structure.

#### What can modules be used for?

[](#what-can-modules-be-used-for)

Modules can be other sections of your site separated from the main site, let's say `App\Www\Admin` for an admin section or `App\Www\Api` to serve an API. It can be anything you want it. It can be used for A/B testing... etc...

---

Now you understand how Voodoo is structured let's get to know about how everything works

---

Front-Controller: /index.php
----------------------------

[](#front-controller-indexphp)

At the root of your application there is the **index.php**. Its job, as a front-controller, is to encapsulate the typical request/route/dispatch/response for the Voodoo application, by invoking `Voodoo\Core\Application`

/index.php

```
