B-Teck!

お仕事からゲームまで幅広く

【PHP】XAMPPにZendFramework(1.x)とSmartyをインストール

家のXAMPPにZFとSmartyを入れて動くようになったのでメモ。


①ZendFrameworkインストール
XAMPPにZend Framworkをインストール - Geekな日記

Smartyインストール
WindowsのXAMPPでSmartyを使ってみた その1 - ケーズメモ

③ZendFrameworkのプロジェクト生成
Zend_Toolを使ってプロジェクトの雛形を作成する IT Tips

④ZendFrameworkとSmartyを連携させる
第12回 Smartyとフレームワーク(その2:Zend Framework編) - Smarty講座

上記を踏まえて、とりあえずindex.php内にこんな感じで書いてみた。
※Zend_View_Smarty.class.phpはリファレンスのものをそのまま使ってます。

<?php
require_once 'Smarty/Smarty.class.php';
require_once 'Zend/Controller/Front.php';
require_once 'Zend/Controller/Action/Helper/ViewRenderer.php';

// アプリケーションパス設定
define('ROOT_PATH', 'D:/xampp/htdocs/Scheduler/');
define('APP_PATH', ROOT_PATH . 'application/');
define('LIB_PATH', ROOT_PATH . 'library/');

// Smartyパス設定
define('SMARTY_PATH', APP_PATH . 'smarty/');
define('SMARTY_TEMPLATES_DIR', SMARTY_PATH . 'templates/');
define('SMARTY_COMPIlE_DIR', SMARTY_PATH . 'templates_c/');
define('SMARTY_CACHE_DIR', SMARTY_PATH . 'chache/');

require_once ('Smarty/Smarty.class.php');    // Smarty本体を読み込み
require_once (LIB_PATH . 'Zend_View_Smarty.class.php');    // ラッパークラスを読み込み

$front = Zend_Controller_Front::getInstance();

$view = new Zend_View_Smarty(
    SMARTY_TEMPLATES_DIR, array(
        'template_dir'=> SMARTY_TEMPLATES_DIR,
        'compile_dir' => SMARTY_COMPIlE_DIR,
        'cache_dir'   => SMARTY_CACHE_DIR,
    )
);
$render = new Zend_Controller_Action_Helper_ViewRenderer($view);
$render->setViewBasePathSpec(SMARTY_TEMPLATES_DIR);
$render->setViewScriptPathSpec(':controller/:action.:suffix');
$render->setViewScriptPathNoControllerSpec(':action.:suffix');
$render->setViewSuffix('tpl');
Zend_Controller_Action_HelperBroker::addHelper($render);
Zend_Controller_Front::run(APP_PATH.'controllers');

上記手順で一応smartyは動くように。
Smartyの設定なんかはBootstrap.php内に移動してもいいかもしれないなぁ。