MVC/lib/Core/Controller.php
2024-08-23 14:41:51 +09:00

39 lines
855 B
PHP

<?php
namespace lib\Core;
abstract class Controller
{
private $_models = [];
private $_view = null;
private $_datas = [];
protected function __construct()
{
$this->_view = new View();
} //
final public function __get($name)
{
return array_key_exists($name, $this->_datas) ? $this->_datas[$name] : null;
}
final public function __set($name, $value)
{
$this->_datas[$name] = $value;
}
//Model
final public function getModel($name)
{
if (!array_key_exists($name, $this->_models)) {
$className = MODEL . $name;
$this->_models[$name] = new $className();
}
return $this->_models[$name];
}
final public function view($file, array $datas = [])
{
return $this->_view->render($file, $datas);
}
} //Class