私はこの質問をどのようにするのかよく分かりません。基本的には、私のビューオブジェクトをSmartyオブジェクトから拡張したシングルトンにしようとしています。私はその後、ビューオブジェクトから自分のコントローラオブジェクトまで拡張することができるようにしたいと考えています。PHP Smartyシングルトンクラスを拡張する
Viewオブジェクトは、私のすべてのコントローラで使用できるテンプレート変数を割り当てます。
私は今何が問題になっているのか知っていますが、誰かが正しい方向に向けることができれば、それはすばらしいでしょう。私はこれを私ができる最高の言葉にしようとしました。
<?php
defined('SITE_ROOT') ? null : define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'].'/mvcsandbox');
require_once('Smarty/Smarty.class.php');
class View extends Smarty {
public static $instance=NULL;
public static function getInstance(){
if (self::$instance === null){
self::$instance = new self();
}
return self::$instance;
}
public function __construct() {
$this->template_dir = SITE_ROOT.'/Library/tmp/';
$this->compile_dir = SITE_ROOT.'/Library/tmp/';
$this->config_dir = SITE_ROOT.'/Library/tmp/';
$this->cache_dir = SITE_ROOT.'/Library/tmp/';
$this->assign("var1", "This is from the view class");
}
public static function output() {
self::display('test.tpl');
}
}
class Controller1 extends View {
public function init() {
$this->assign("var2", "This is from the Controller1 class");
}
}
class Controller1_index extends Controller1 {
public function init() {
$this->assign("var3", "This is from the Controller1_index class");
}
}
//$view = View::getInstance();
$controller1 = Controller1::getInstance();
$controller1_index = Controller1_index::getInstance();
$controller1->init();
//$controller1_index->init();
$controller1->output();
?>
私はあなたが "シングルトン"を意味すると思います:D類推は印象的ですが。 – Halcyon
Smartyを落として[PHPのネイティブ機能](http://codeangel.org/articles/simple-php-template-engine)を使用しようと正直にお勧めしますが、ええ、 "Simpleton" .html)をテンプレート化します。 –