Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用smarty设置slim的默认分配_Php_Smarty_Slim_Assign - Fatal编程技术网

Php 使用smarty设置slim的默认分配

Php 使用smarty设置slim的默认分配,php,smarty,slim,assign,Php,Smarty,Slim,Assign,我将要转换一个站点以使用带有Smarty模板引擎的Slim框架。 在当前站点上,我已经分配了一些默认的smarty变量,但我不确定如何使用Slim框架设置它们,因此它们只设置了一次 他们现在是这样的: $smarty->assign("fid", $user_profile["id"]); $smarty->assign("fid_name", $user_profile["name"]); $smarty->assign("fid_email", $user_profile[

我将要转换一个站点以使用带有Smarty模板引擎的Slim框架。 在当前站点上,我已经分配了一些默认的smarty变量,但我不确定如何使用Slim框架设置它们,因此它们只设置了一次

他们现在是这样的:

$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());
这是我的to be 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);
}
通过使用

$app->hook('slim.before.dispatch', function () use ($app) {
});