本文整理汇总了PHP中Tpl::assign方法的典型用法代码示例。如果您正苦于以下问题:PHP Tpl::assign方法的具体用法?PHP Tpl::assign怎么用?PHP Tpl::assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tpl
的用法示例。
在下文中一共展示了Tpl::assign方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_buildurl
/**
*
* 链接构造函数
*
* @param array $params
* @param Tpl $tpl
*/
function smarty_function_buildurl($params, &$tpl)
{
$urls = array();
$as = $tpl->getArg($params, 'as', 'query');
unset($params['as']);
$prefix = $tpl->getArg($params, 'prefix', '/');
unset($params['prefix']);
$hides = $tpl->getArg($params, 'hide', null);
unset($params['hide']);
if (!empty($hides)) {
$hides = explode(',', $hides);
$hides = array_map('trim', $hides);
}
if (!empty($params)) {
foreach ($params as $key => $val) {
if (strlen($val) == 0) {
continue;
}
if (!$hides || !in_array($key, $hides)) {
$urls[] = urlencode($key);
}
$urls[] = urlencode($val);
}
}
if (!empty($urls)) {
$tpl->assign($as, $prefix . join('/', $urls));
} else {
$tpl->assign($as, null);
}
}
示例2: render
/**
* render a .tpl
*/
public function render($tpl, $parames = array())
{
parent::$compile_dir = SlightPHP::$appDir . DIRECTORY_SEPARATOR . "templates_c";
parent::$template_dir = SlightPHP::$appDir . DIRECTORY_SEPARATOR . "templates";
parent::assign($parames);
return parent::fetch("{$tpl}");
}
示例3: display
/**
* like as render except delimiter
*/
public function display($tpl, $parames = array())
{
parent::$compile_dir = SlightPHP::$appDir . DIRECTORY_SEPARATOR . "templates_c";
parent::$template_dir = SlightPHP::$appDir . DIRECTORY_SEPARATOR . "templates";
parent::$left_delimiter = '<{';
parent::$right_delimiter = '}>';
parent::assign($parames);
return parent::fetch("{$tpl}");
}
示例4: smarty_function_newsView
/**
* 单信息显示
* @param type $params
* @param Tpl $tpl
* @return type
*/
function smarty_function_newsView($params, &$tpl)
{
$values = array();
$types = array();
/* @var $acStr ZeActiveString */
$acStr = new ZeActiveString();
$acStr->putAll(array('select' => 'SELECT
`id`,`title`,`category`
,`detail`,`create_time`,`edit_time`
FROM `news_e` news
WHERE 1=1
', 'where.id' => 'AND `id` = :id ', 'where.next' => 'AND `id` > :id ', 'where.category' => 'AND `category` = :category ', 'where.category.set' => 'AND FIND_IN_SET(`category`,:category) > 0 ', 'where.search' => 'AND (`title` LIKE "%" || :search || "%"
OR `detail` LIKE "%" || :search || "%") ', 'limit' => 'LIMIT 1 '));
$acStr->active('select');
$acStr->active('limit');
$id = $tpl->getArg($params, 'id', null);
if (is_numeric($id) && $id > 0) {
$values['id'] = intval($id);
$types['id'] = PDO::PARAM_INT;
$acStr->active('where.id');
}
$next = $tpl->getArg($params, 'next', null);
if (is_numeric($next) && $next > 0) {
$values['id'] = intval($next);
$types['id'] = PDO::PARAM_INT;
$acStr->active('where.next');
}
/* todo prev */
/* @var $recorder ZeRecorder */
$recorder = new ZeRecorder(Conn::getConn());
/* @var $pageSet ZePageSet */
$pageSet = $tpl->getPageSet($params);
$as = $tpl->getArg($params, 'as', 'news');
$sql = $acStr->toString();
$row = $recorder->query($sql)->bind($values, $types)->fetch();
$tpl->assign($as, $row);
}
示例5: OutputPage
/**
* Function to output the templates
* @param array $templates The collection of templates with their associated variables
*
*/
function OutputPage($templates = array())
{
if (sizeof($templates) == 0) {
trigger_error("Templates not configured properly", E_USER_ERROR);
}
// Define a set of common variables which plugin to the structure template.
$page = new Tpl();
$body = '';
// Loop through the templates array to dynamically create objects and assign variables to them.
/// XXX: this is not a common way to use our template class, but I didn't want to rewrite
/// the whole setup only to change the templating engine
foreach ($templates as $name => $module) {
foreach ($module['vars'] as $var_name => $value) {
$page->assign($var_name, $value);
}
if ($name == 'structure') {
$page->assign('body', $body);
$page->display('structure.tpl');
} else {
$body .= $page->fetch($module['template']);
}
}
}
示例6: getContent
/**
* Outputs the content by finding the correct template
* and view file, if needed.
*/
public function getContent()
{
$tplDir = $this->isView ? $this->view->tpl : Config::$template;
$config = array('base_url' => null, 'tpl_dir' => array(APP . 'template/' . $tplDir . '/'), 'cache_dir' => APP . 'tmp/', 'debug' => true, 'php_enabled' => true, 'tpl_ext' => 'php');
Tpl::configure($config);
$tpl = new Tpl();
$tpl->assign('isView', $this->isView);
$tpl->assign('title', Config::$data->title);
if ($this->isView) {
$vars = $this->view->getVars();
if (!empty($vars)) {
foreach ($vars as $key => $value) {
$tpl->assign($key, $value);
}
}
$sep = DIRECTORY_SEPARATOR;
$view = '..' . $sep . '..' . $sep . APP . 'view/' . $this->view->path;
} else {
$view = $this->view;
if ($this->isJson === true) {
echo $view;
exit;
}
}
try {
File::get(APP . 'template/' . $tplDir . '/template.php');
if (class_exists('Template\\Model\\Template')) {
$tpl_class = new Template\Model\Template();
$tpl->assign('template', $tpl_class);
}
} catch (Exception $e) {
}
$tpl->assign('view', $view);
$tpl->draw('index');
}
示例7: dirname
$db->dbOpenFast($conf['database']);
$webdir = dirname(htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'utf-8'));
$baseurl = rtrim(Flyspray::absoluteURI($webdir), '/\\') . '/';
// ---------------------------------------------------------------------
// Application Web locations
// ---------------------------------------------------------------------
$fs = new Flyspray();
define('APPLICATION_SETUP_INDEX', Flyspray::absoluteURI());
define('UPGRADE_VERSION', Flyspray::base_version($fs->version));
define('DOMAIN_HASH', md5($_SERVER['SERVER_NAME'] . (int) $_SERVER['SERVER_PORT']));
define('CACHE_DIR', Flyspray::get_tmp_dir() . DIRECTORY_SEPARATOR . DOMAIN_HASH);
// Get installed version
$sql = $db->Query('SELECT pref_value FROM {prefs} WHERE pref_name = ?', array('fs_ver'));
$installed_version = $db->FetchOne($sql);
$page = new Tpl();
$page->assign('title', 'Upgrade ');
$page->assign('short_version', UPGRADE_VERSION);
if (!isset($conf['general']['syntax_plugin']) || !$conf['general']['syntax_plugin'] || $conf['general']['syntax_plugin'] == 'none') {
$page->assign('ask_for_conversion', true);
} else {
$page->assign('ask_for_conversion', false);
}
//cleanup
//the cache dir
@rmdirr(sprintf('%s/cache/dokuwiki', APPLICATION_PATH));
// ---------------------------------------------------------------------
// Now the hard work
// ---------------------------------------------------------------------
// Find out which upgrades need to be run
$folders = glob_compat(BASEDIR . '/upgrade/[0-9]*');
usort($folders, 'version_compare');
示例8: die
require_once OBJECTS_PATH . '/class.database.php';
@(require_once OBJECTS_PATH . '/class.tpl.php');
define('CONFIG_PATH', Flyspray::get_config_path(BASEDIR . '/../'));
$conf = @parse_ini_file(CONFIG_PATH, true) or die('Cannot open config file at ' . CONFIG_PATH);
$db = NewDatabase($conf['database']);
$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE);
// ---------------------------------------------------------------------
// Application Web locations
// ---------------------------------------------------------------------
$fs = new Flyspray();
define('APPLICATION_SETUP_INDEX', Flyspray::absoluteURI());
define('UPGRADE_VERSION', Flyspray::base_version($fs->version));
// Get installed version
$installed_version = $db->x->GetOne('SELECT pref_value FROM {prefs} WHERE pref_name = ?', null, 'fs_ver');
$page = new Tpl();
$page->assign('title', 'Upgrade ');
$page->assign('short_version', UPGRADE_VERSION);
// ---------------------------------------------------------------------
// Now the hard work
// ---------------------------------------------------------------------
// Find out which upgrades need to be run
$folders = glob_compat(BASEDIR . '/upgrade/[0-9]*');
$folders = array_map('basename', $folders);
usort($folders, 'version_compare');
// start with lowest version
$done = true;
if (Post::val('upgrade')) {
$db->supports('transactions') && $db->beginTransaction();
foreach ($folders as $folder) {
if (version_compare($installed_version, $folder, '<=')) {
// example: we upgrade from 0.9.9(final) to 1.0. In this case we want to start at 0.9.9.2
示例9: smarty_function_newsList
/**
*
* 新闻列表调用函数
*
* @param array $params
* @param Tpl $tpl
* @param bool $repeat
*/
function smarty_function_newsList($params, &$tpl)
{
$values = array();
$types = array();
/* @var $acStr ZeActiveString */
$acStr = new ZeActiveString();
$acStr->putAll(array('select' => 'SELECT
`id`,`title`,`category`
,`detail`,`create_time`,`edit_time`
FROM news_e news ', 'count' => 'SELECT count(1) FROM news_e news ', 'where' => 'WHERE 1=1 ', 'where.category' => 'AND `category` = :category ', 'where.category.set' => 'AND FIELD(`category`,:categorys) > 0 ', 'where.search' => 'AND (`title` LIKE "%" || :search || "%"
OR `detail` LIKE "%" || :search || "%") ', 'order' => 'ORDER BY ', 'order.id.desc' => '`id` DESC ', 'order.id.asc' => '`id` ASC ', 'order.editTime.desc' => '`edit_time` DESC ', 'order.editTime.asc' => '`edit_time` ASC ', 'limit' => 'LIMIT :offset,:pageSize '));
$acStr->active('count');
$acStr->active('where');
/* @var $category Integer 分类编号 */
$category = $tpl->getArg($params, 'category', null);
$category = !is_null($category) ? $category : $tpl->getVar('info.category');
/* 默认分类选择到的是 0 ,有时需要仅调用默认分类信息,所以将-1指定为所有分类 */
if ($category > -1) {
if (strpos($category, ',') === FALSE) {
$values['category'] = $category;
$types['category'] = PDO::PARAM_INT;
$acStr->active('where.category');
} else {
$values['categorys'] = $category;
$types['categorys'] = PDO::PARAM_STR;
$acStr->active('where.category.set');
}
}
/* @var $search string 搜索 标题,内容 */
$search = $tpl->getArg($params, 'search');
$search = $search = $search ? $search : $tpl->getVar('info.search');
if (!empty($search)) {
$values['search'] = $search;
$types['search'] = PDO::PARAM_STR;
$acStr->active('where.search');
}
/* @var $recorder ZeRecorder */
$recorder = new ZeRecorder(Conn::getConn());
/* @var $pageSet ZePageSet */
$pageSet = $tpl->getPageSet($params);
/* @var $pageAs String */
$pageAs = $tpl->getArg($params, 'pageAs', null);
if (!is_null($pageAs)) {
$sql = $acStr->toString();
$recordCount = $recorder->query($sql)->bind($values, $types)->getInt();
$pageSet->setRecordCount($recordCount);
$tpl->assign($pageAs, $pageSet);
}
$acStr->update('count', 'select');
/**
* order
*/
$order = $tpl->getArg($params, 'order');
$order = $order ? $order : $tpl->getVar('info.order', 'editTime.desc');
if (!empty($order) && in_array($order, array('id.desc', 'id.asc', 'editTime.desc', 'editTime.asc'))) {
$acStr->active('order');
$acStr->active('order.' . $order);
}
/**
* limit
*/
$acStr->active('limit');
$values['offset'] = $pageSet->getOffset();
$types['offset'] = PDO::PARAM_INT;
$values['pageSize'] = $pageSet->getPageSize();
$types['pageSize'] = PDO::PARAM_INT;
$sql = $acStr->toString();
$list = $recorder->query($sql)->bind($values, $types)->fetchAll();
$as = $tpl->getArg($params, 'as', 'news_list');
$tpl->assign($as, $list);
}