Просмотр поста

.
Screamer

Создаем в директории module директорий system
И еще три директория с названиями model , view, controller
во все эти директорий можно закинуть htaccess со строчкой Deny From All
Рассморим файлы директория system

storage.php - будет выполнять роль реестра
Выполним его с помощью магии

class Storage {

    protected $storage = array();

    public function __construct(array $storage)
    {


        $this->storage = $storage;

    }

    public function __set($name, $value)
    {

        if (!empty($name)) {

            if (is_array($value))
            {

                $value = new Storage($value);

            }

            $this->storage[$name] = $value;

        }

    }

    public function __get($name)
    {

        return isset($this->storage[$name]) ? $this->storage[$name] : NULL;

    }

    public function __isset($name)
    {

        return isset($this->storage[$name]);

    }

    public function __unset($name)
    {

        if (isset($this->storage[$name]))
        {

            unset($this->storage[$name]);

        }

    }

}

controller.php
Ну тут думаю все ясно.
abstract class Controller_Base extends Storage {

    protected $tpl;

    public function __construct(array $storage)
    {

        parent::__construct($storage);
        $variables = array(
            'set' => core::$system_set,
            'lng' => core::$lng,
            'set_user' => core::$user_set,
            'login' => isset(core::$user_data['name']) ? core::$user_data['name'] : FALSE,
            'user_id' => core::$user_id,
            'act' => $storage['act'],
            'datauser' => core::$user_data,
            'agn' => core::$user_agent,
            'ban' => core::$user_ban

        );
        $this->tpl = new Template($variables);
        unset($storage, $variables);

    }

    abstract public function _index();

}

model.php
и здесь без комментариев
class Model_Base extends Storage {

    public function __construct($storage)
    {

        parent::__construct($storage);

    }

}

Ну и template.php - шаблонизатор
class Template {

    protected $path = '';
    /* Переменные для файлов движка */
    protected $variables = array();
    /* Шаблоны с переменными для них */
    protected $templates = array();

    public function __construct(array $variables = array())
    {

        $this->variables = $variables;
        $this->path = CURRENTDIR . 'view' . DIRECTORY_SEPARATOR;

    }

    /**
     * Загрузка шаблона
     */
    protected function capture($_tplFile, array $data = array())
    {

        ob_start();
        if (is_array($_tplFile))
        {

            foreach ($_tplFile as $_tplData)
            {

                if (!empty($_tplData['data']))
                {

                    extract($_tplData['data'], EXTR_SKIP);

                }

                include_once $_tplData['name'];

            }

        }
        else
        {

            if (!empty($data))
            {

                extract($data, EXTR_SKIP);

            }

            include_once $_tplFile;

        }

        $contents = ob_get_contents();
        ob_end_clean();
        return $contents;

    }

    /**
    * Установка шаблона
    */
    public function setTemplate($name, array $data = array())
    {

        $name = $this->path . $name . '.php';
        if (file_exists($name))
        {

            $this->templates[] = array('name' => $name, 'data' => $data);

        }
        else
        {

            die('Template: ' . $name . ' is not found');

        }


    }

    /**
     * Собираем все в кучу и выводим на экран.
     */
    public function display()
    {

        array_unshift($this->templates, array('name' => INCDIR . 'head.php', 'data' => $this->variables));
        array_push($this->templates, array('name' => INCDIR . 'end.php', 'data' => $this->variables));
        echo $this->capture($this->templates);

    }

}

Вот вроде и все.