PHP Classes

Define MVC: A front controller based MVC framework

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 272 All time: 7,703 This week: 455Up
Version License PHP version Categories
define-mvc 1.1GNU General Publi...5.5PHP 5, Libraries, Design Patterns
Description 

Author

This package implements a front controller based MVC framework.

It providers a router class that loads processes the current request URL and dispatches to the respective controller.

The package provides base classes for a controller, view, DAO, model, and service.

Picture of Nitesh Apte
  Performance   Level  
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

 

Example

<?php
use Define\Core\ObjectContainer;
use
Define\Core\Framework;
use
Define\Utilities\Session;
use
Define\DBDrivers\DatabaseBean;
use
Define\Utilities\Logger;
use
Define\Core\Router;

ob_start();
session_start();
session_regenerate_id();
define("DIRECT_ACCESS", TRUE);

# set the include path #
# Core classes of framework - Start #
###########################################################################################################################
set_include_path(get_include_path().PATH_SEPARATOR."lib/define/core");
set_include_path(get_include_path().PATH_SEPARATOR."lib/define/dbdrivers");
set_include_path(get_include_path().PATH_SEPARATOR."lib/define/helpers");
set_include_path(get_include_path().PATH_SEPARATOR."lib/define/utilities");
set_include_path(get_include_path().PATH_SEPARATOR."lib/define/traits");
set_include_path(get_include_path().PATH_SEPARATOR."lib/define/exceptions");
set_include_path(get_include_path().PATH_SEPARATOR."lib/vendors/phpmailer");
###########################################################################################################################
# Core classes of framework - End #

# Classes for your application - Start #
###########################################################################################################################
set_include_path(get_include_path().PATH_SEPARATOR."application/controller"); // Controllers for your application goes here
set_include_path(get_include_path().PATH_SEPARATOR."application/model/service"); // Service for your application goes here
set_include_path(get_include_path().PATH_SEPARATOR."application/model/service/impl"); // Service implementation
set_include_path(get_include_path().PATH_SEPARATOR."application/model/dao");
set_include_path(get_include_path().PATH_SEPARATOR."application/model/dao/impl");
set_include_path(get_include_path().PATH_SEPARATOR."application/bean");
###########################################################################################################################
# Classes for your application - End #

# Settings for framework - Start #
###########################################################################################################################
include_once 'configuration/define.inc';
###########################################################################################################################
# Settings for framework - End #

# Settings for Application - Start #
###########################################################################################################################
include_once 'configuration/application.inc';
###########################################################################################################################
# Settings for Application - End #

/**
 * Autoload method for dynamically loading classes.
 *
 * @param object $object Name of Class
 * @return void
 */
function __autoload($object) {
   
$split = explode("\\", $object);
   
$className = end($split);
    require_once(
"{$className}.php");
}

$container = ObjectContainer::getInstance();
$container->offsetSet('FRAMEWORK', Framework::getInstance()); // Create the instance of framework and let your handlers initialized.
$container->offsetSet('SESSION', Session::getInstance());
$container->offsetSet('MYSQLI', new DatabaseBean("MYSQLI", "localhost", "root", "nitesha", "phpmyadmin", 3306));
//$container->offsetSet('ORACLE', new DatabaseBean("ORACLE", "localhost", "root", "nitesha", "thebookmarker", "3306"));
$container->offsetSet('LOGGER', Logger::getInstance());

//$container->offsetSet('MYSQLI-2', new DatabaseBean("MYSQLI", "localhost", "root", "nitesha", "musicplus", "3306")); // another mysql database
//$container->offsetSet('PDO', new DatabaseBean("mysql", "localhost", "root", "nitesha", "musicplus", "3306"));

# Do this when site is in maintenance or offline - Start #
###########################################################################################################################

/* $default = array(
 'controller' => 'Error',
 'action' => 'default',
 'params' => array('408')
 ); */

###########################################################################################################################
# Do this when site is in maintenance or offline - End #

$default = array();
$container->offsetGet('FRAMEWORK')->init(Router::getInstance(), $default);
?>


Details

Define MVC

Define MVC is a Front Controller based MVC framework for developing web based applications. It is an open source and will always remain.

The name Define because you can define it the way you want. I have tried to keep everything configurable.

IMPORTANT: While developing this framework, I had a virtual host created for it. Request you guys to do the same. Probably it will not work if you try to access it like htt://localhost/define-mvc/

Contribute

Please feel free to contribute. But try to keep the implementation simple so that a developer working for first time shouldn't find it difficult to understand and use it.

How to use it

Since it is a Front Controller based MVC, the URL should be in the following pattern:

http://www.domain.com/controller/action/param1-param2/

So, if the URL is http://www.example.com/user/profile/33-90/ then:

<pre> <code>

class UserController extends ApplicationController {

public function profileAction($param1, $param2) {
	// logic goes here
}

} </code> </pre>

Check IndexController inside application/controller to get an idea.

All the view files will be inside 'application/view/' folder.

You can add display value in view by using View object. For example:

<pre> <code> class UserController extends ApplicationController {

public function profileAction($param1, $param2) {
	$this->view->addObject("msg", "I am the value to be displayed.");
	$this->view->render('user');
}

} </code> </pre>

In 'view' folder, create a file named 'user.php', and put the following code:

<pre> <code> echo $msg </code> </pre>

All the files related to your project will be inside 'application' folder. However, you can change the configurations defined in 'configuration/define.inc'.

To test after importing the project in your local server, try accessing the following:

http://www.domain.com/

http://www.domain.com/index/default/me-you/

http://www.domain.com/index/test-from-service/

http://www.domain.com/index/test-from-dao/

where domain.com is your local server.

Configuration

Define MVC is completely configurable.

For example, you want your UserController to be UserXYZ go to 'configuration/define.inc' and change CONTROLLER_SUFFIX to XYZ. Similarly, you can change other configuration properties.

API Documentation

Check docs/index.html for API documentation.

TODO

// More documentation to come. However, it's open for contribution.


  Files folder image Files (206)  
File Role Description
Files folder imageapplication (5 directories)
Files folder imageconfiguration (2 files)
Files folder imagedbscripts (6 files)
Files folder imagedocs (117 files, 1 directory)
Files folder imagelib (2 directories)
Files folder imagelogs (1 file)
Accessible without login Plain text file .htaccess Data Auxiliary data
Accessible without login Plain text file bootstrap.php Example Example script
Accessible without login Plain text file LICENSE Lic. License
Accessible without login Plain text file README.md Doc. Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:272
This week:0
All time:7,703
This week:455Up