miniMVC/sys/core/Controller.php

96 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2012-05-22 11:11:36 -04:00
<?php
/**
* MiniMVC
*
* Convention-based micro-framework for PHP
*
* @package miniMVC
* @author Timothy J. Warren
* @copyright Copyright (c) 2011 - 2012
2012-05-23 12:01:13 -04:00
* @link https://github.com/aviat4ion/miniMVC
* @license http://philsturgeon.co.uk/code/dbad-license
2012-05-22 11:11:36 -04:00
*/
// --------------------------------------------------------------------------
namespace miniMVC;
/**
* Base Controller Class
*
* @package miniMVC
* @subpackage System
*/
class Controller {
2012-05-22 11:11:36 -04:00
/**
* Instance of Page class
*
* @var Page
*/
protected $page;
/**
* Create the controller object
*
* @return void
*/
public function __construct()
{
2012-09-13 11:52:36 -04:00
if (is_null($this->page))
{
$this->page = new Page();
}
2012-05-22 11:11:36 -04:00
}
2012-05-22 11:11:36 -04:00
// --------------------------------------------------------------------------
2012-05-22 11:11:36 -04:00
/**
* 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-22 11:11:36 -04:00
{
$segments = explode('\\', $file);
$file_name = end($segments);
2012-05-22 11:11:36 -04:00
// The module is set via the router
$module = strtolower(MM_MOD);
$path = MM_MOD_PATH . "{$module}/models/{$file_name}.php";
2012-05-22 11:11:36 -04:00
if (is_file($path))
{
require_once($path);
}
2012-05-22 11:11:36 -04:00
if ( ! empty($args))
{
$this->$file_name = new $file($args);
2012-05-22 11:11:36 -04:00
}
else
{
$this->$file_name = new $file;
2012-05-22 11:11:36 -04:00
}
}
2012-05-22 11:11:36 -04:00
// --------------------------------------------------------------------------
2012-05-22 11:11:36 -04:00
/**
* 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)
2012-05-22 11:11:36 -04:00
{
return $this->page->load_view($file, $data, $return);
2012-05-22 11:11:36 -04:00
}
}
// End of controller.php