2012-04-27 16:28:25 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* MiniMVC
|
|
|
|
*
|
|
|
|
* Convention-based micro-framework for PHP
|
|
|
|
*
|
|
|
|
* @package miniMVC
|
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2011 - 2012
|
|
|
|
* @link https://github.com/timw4mail/miniMVC
|
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base Controller Class
|
|
|
|
*
|
|
|
|
* @package miniMVC
|
|
|
|
* @subpackage System
|
|
|
|
*/
|
|
|
|
class MM_Controller extends miniMVC {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instance of Page class
|
|
|
|
*
|
|
|
|
* @var Page
|
|
|
|
*/
|
2012-05-01 16:39:14 -04:00
|
|
|
protected $page;
|
2012-04-27 16:28:25 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the controller object
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
2012-05-01 15:22:29 -04:00
|
|
|
// Create the page object
|
2012-04-27 16:28:25 -04:00
|
|
|
$this->page = new MM_Page($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function for loading a model into the current class
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @param array $args
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function load_model($file, $args=array())
|
|
|
|
{
|
2012-05-01 15:22:29 -04:00
|
|
|
// The module is set via the router
|
2012-05-01 16:39:14 -04:00
|
|
|
$module = strtolower(MM_MOD);
|
2012-05-01 15:22:29 -04:00
|
|
|
$path = MM_MOD_PATH . "{$module}/models/{$file}.php";
|
|
|
|
|
2012-05-01 16:39:14 -04:00
|
|
|
if (is_file($path))
|
2012-04-27 16:28:25 -04:00
|
|
|
{
|
|
|
|
require_once($path);
|
|
|
|
}
|
|
|
|
|
2012-05-01 16:39:14 -04:00
|
|
|
if ( ! empty($args))
|
2012-04-27 16:28:25 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
$this->$file = new $file($args);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->$file = new $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function for loading a view
|
|
|
|
*
|
|
|
|
* @param string $file
|
|
|
|
* @param array $data
|
|
|
|
* @param bool $return
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function load_view($file, array $data=array(), $return=FALSE)
|
|
|
|
{
|
|
|
|
$path = "";
|
|
|
|
|
2012-05-01 16:39:14 -04:00
|
|
|
// The module is set via the router
|
|
|
|
$module = strtolower(MM_MOD);
|
|
|
|
$path = MM_MOD_PATH . "{$module}/views/{$file}.php";
|
2012-04-27 16:28:25 -04:00
|
|
|
|
|
|
|
// If it's not a module, or doesn't exist in the module view folder
|
|
|
|
// look in the app view folder
|
2012-05-03 13:26:09 -04:00
|
|
|
if ( ! is_file($path))
|
2012-04-27 16:28:25 -04:00
|
|
|
{
|
|
|
|
$path = MM_APP_PATH . "views/{$file}.php";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Contain the content for buffering
|
|
|
|
ob_start();
|
|
|
|
|
|
|
|
// Extract the data array
|
|
|
|
extract($data);
|
|
|
|
|
|
|
|
// Include the file
|
|
|
|
include($path);
|
|
|
|
|
|
|
|
$buffer = ob_get_contents();
|
|
|
|
ob_end_clean();
|
|
|
|
|
2012-05-03 13:26:09 -04:00
|
|
|
if ($return == TRUE)
|
2012-04-27 16:28:25 -04:00
|
|
|
{
|
|
|
|
return $buffer;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->output->append_output($buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of controller.php
|