0
我即將轉換站點以使用Slim框架與Smarty模板引擎。 在當前網站上我已經分配了一些默認的smarty變量,但我不確定如何使用Slim框架設置它們,因此它們只設置一次。使用smarty設置默認分配與苗條
這是他們現在是如何:
$smarty->assign("fid", $user_profile["id"]);
$smarty->assign("fid_name", $user_profile["name"]);
$smarty->assign("fid_email", $user_profile["email"]);
$smarty->assign('postzip', $users->find_zip_or_post_new($user_profile["id"]));
$smarty->assign('userzip', $users->find_my_zip_code($user_profile["id"]));
$smarty->assign('url', $url);
$smarty->assign('catlist', $adverts->getcategories());
這是我將要的index.php
/***
* This is the script that will generate the complete site
*/
include_once("includes/classes/class.config.php"); //Configuration file
/*
* Include the Slim framework
*/
require 'libs/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
use Slim\Slim;
/*
* Include the Smarty template view
*/
require 'libs/Slim/Extras/Views/Smarty.php';
/*
* Set new Slim object
*/
$app = new Slim(array(
'view' => new \Slim\Extras\Views\SmartyView(),
'debug' => true,
'log.enable' => true,
'log.path' => 'logs/',
'log.level' => 4,
'mode' => 'development'
));
//Ad view
$app->get('/', function() use ($app) {
$adverts = new Adverts();
$view = $app->view();
$app->render(
'index.tpl',
array(
'adverts' => $adverts->listadverts()
)
);
});
$app->run();
我應該將它們設置在SmartyView渲染功能
public function render($template) {
$instance = self::getInstance();
$instance->assign($this->data);
return $instance->fetch($template);
}