本文整理汇总了PHP中TemplateEngine::setVariable方法的典型用法代码示例。如果您正苦于以下问题:PHP TemplateEngine::setVariable方法的具体用法?PHP TemplateEngine::setVariable怎么用?PHP TemplateEngine::setVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TemplateEngine
的用法示例。
在下文中一共展示了TemplateEngine::setVariable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderTree
/**
* renders tree into menu template
* @return object
*/
public function renderTree()
{
if (!$this->getConfig()->template_menu) {
return;
}
if (!$this->tree) {
return;
}
$template = new TemplateEngine($this->templatePath . $this->getConfig()->template_menu);
$template->setCacheable(true);
$cache = Cache::getInstance();
if (!$cache->isCached('submenu')) {
$childs = array();
$childlist = $this->tree->getChildList($this->tree->getCurrentId());
foreach ($childlist as $item) {
if (isset($item['visible']) && !$item['visible']) {
continue;
}
$item['path'] = $this->tree->getPath($item['id']);
$childs[] = $item;
}
$template->setVariable('submenu', $childs, false);
$cache->save(serialize($childs), 'submenu');
} else {
$template->setVariable('submenu', unserialize($cache->getCache('submenu')), false);
}
// check if template is in cache
if ($template->isCached()) {
return $template;
}
$menu = $this->tree->getRootList();
// get selected main menu item
$firstNode = $this->tree->getFirstAncestorNode($this->tree->getCurrentId());
$firstId = $firstNode ? $firstNode['id'] : 0;
foreach ($menu as &$item) {
$item['path'] = isset($item['external']) && $item['external'] ? $item['url'] : $this->tree->getPath($item['id']);
$item['selected'] = $item['id'] == $firstId;
}
$template->setVariable('menu', $menu, false);
$auth = Authentication::getInstance();
$template->setVariable('loginName', $auth->getUserName(), false);
return $template;
}
示例2: handleDeletePost
private function handleDeletePost()
{
$request = Request::getInstance();
$values = $request->getRequest(Request::POST);
try {
$key = $this->getKey();
$this->delete($key);
viewManager::getInstance()->setType(NewsLetter::VIEW_PLUGIN_OVERVIEW);
$plugin = $this->plugin->getObject(NewsLetter::TYPE_PLUGIN);
$plugin->handleHttpGetRequest();
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleDeleteGet();
}
}
示例3: handleTreeDeletePost
private function handleTreeDeletePost()
{
$request = Request::getInstance();
$values = $request->getRequest(Request::POST);
try {
if (!$request->exists('id')) {
throw new Exception('Post ontbreekt.');
}
$id = $request->getValue('id');
$key = array('id' => $id);
$this->delete($key);
viewManager::getInstance()->setType(Calendar::VIEW_COMMENT_OVERVIEW);
$this->handleHttpGetRequest();
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleTreeDeleteGet();
}
}
示例4: handleUserPost
private function handleUserPost()
{
$request = Request::getInstance();
$user = new NewsLetterUser($this->plugin);
$usr_used = $request->getValue('usr_used');
if (!$usr_used) {
$usr_used = array();
}
try {
if (!$request->exists('id')) {
throw new Exception('User group is missing.');
}
$id = intval($request->getValue('id'));
$key = array('id' => $id);
$this->removeUser($key);
foreach ($usr_used as $item) {
$user->addGroup(array('id' => $item), $key);
}
viewManager::getInstance()->setType(NewsLetter::VIEW_GROUP_OVERVIEW);
$this->handleOverview();
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleUserGet(false);
}
}
示例5: handleAdminSubLinks
/**
* handle navigation for sub classes / pages
*/
public function handleAdminSubLinks($keyName, $title, $addBreadcrumb = false)
{
$request = Request::getInstance();
$view = ViewManager::getInstance();
$template = new TemplateEngine();
if (!$request->exists('nl_id')) {
return;
}
$nl_id = $request->getValue('nl_id');
$newsLetterName = $this->getName(array('id' => $nl_id));
$template->setVariable('pageTitle', $newsLetterName, false);
$tree_id = $request->getValue('tree_id');
$tag = $request->getValue('tag');
$template->setVariable('tree_id', $tree_id, false);
$template->setVariable('tag', $tag, false);
$template->setVariable('nl_id', $nl_id, false);
if (!$addBreadcrumb) {
return;
}
$url = new Url(true);
$url->setParameter('tree_id', $tree_id);
$url->setParameter('tag', $tag);
$url->setParameter('id', $nl_id);
$url->setParameter($view->getUrlId(), ViewManager::TREE_EDIT);
$breadcrumb = array('name' => $newsLetterName, 'path' => $url->getUrl(true));
$this->addBreadcrumb($breadcrumb);
}
示例6: handleImportPost
private function handleImportPost()
{
$request = Request::getInstance();
$template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
$tree_id = intval($request->getValue('tree_id'));
$nl_id = intval($request->getValue('nl_id'));
$tag = $request->getValue('tag');
$this->handleTreeSettings($template);
try {
$debug = $this->import($tree_id, $tag, $nl_id, false);
$template->setVariable('debug', $debug, false);
$this->template[$this->director->theme->getConfig()->main_tag] = $template;
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleImportGet();
}
}
示例7: handleConfEditGet
/**
* handle conf edit
*/
private function handleConfEditGet($retrieveFields = true)
{
viewManager::getInstance()->setType(ViewManager::CONF_EDIT);
$template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
$template->setVariable('pageTitle', $this->description, false);
$this->template[$this->director->theme->getConfig()->main_tag] = $template;
}
示例8: handleMovePost
private function handleMovePost()
{
$request = Request::getInstance();
try {
$key = $this->getKey();
if (!$request->exists('newtag')) {
throw new Exception("Destination tag cannot be empty");
}
$sqlParser = clone $this->sqlParser;
$sqlParser->parseCriteria($key, false);
$this->parseCriteria($sqlParser, $key);
$sqlParser->setFieldValue('nl_tag', $request->getValue('newtag'));
$query = $sqlParser->getSql(SqlParser::MOD_UPDATE_FIELDS);
$db = $this->getDb();
$res = $db->query($query);
if ($db->isError($res)) {
throw new Exception($res->getDebugInfo());
}
viewManager::getInstance()->setType(NewsLetter::VIEW_PLUGIN_OVERVIEW);
$this->handleOverview();
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleMoveGet();
}
}
示例9: handleAdminOverviewPost
private function handleAdminOverviewPost()
{
$request = Request::getInstance();
$values = array_merge($request->getRequest(Request::POST), $request->getRequest(Request::FILES));
try {
$this->install($values);
viewManager::getInstance()->setType(self::VIEW_SUCCESS);
$this->handleAdminOverviewGet();
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleAdminOverviewGet();
}
}
示例10: renderSiteGroup
private function renderSiteGroup()
{
$template = new TemplateEngine($this->getPath() . "templates/sitegroup.tpl");
$siteGroup = $this->getSiteGroup();
$id = $siteGroup->getCurrentId();
$url = new Url();
$url->useCurrent(false);
$grouplist = $siteGroup->getList();
//if($grouplist['totalItems'] < 2) return;
foreach ($grouplist['data'] as &$item) {
$url->setParameter(SystemSiteGroup::CURRENT_ID_KEY, $item['id']);
$item['href_detail'] = $url->getUrl(true);
$item['selected'] = $item['id'] == $id;
}
$template->setVariable('sitegroup', $grouplist, false);
// add link to sitegroup to add / modify / delete websites
$admin = $this->director->adminManager;
$admintree = $admin->tree;
$sitegroupPath = $admintree->getPath($admintree->getIdFromClassname('SiteGroup'));
$template->setVariable('href_sitegroup', $sitegroupPath, false);
return $template;
}
示例11: handleImportPost
private function handleImportPost()
{
$request = Request::getInstance();
$values = array_merge($request->getRequest(Request::POST), $request->getRequest(Request::FILES));
$grp_used = $request->getValue('grp_used');
if (!$grp_used) {
$grp_used = array();
}
try {
require_once DIF_ROOT . "utils/CsvFile.php";
// check if import file is uploaded
if (!array_key_exists('import_file', $values) && !is_array($values['import_file'])) {
throw new Exception('No import file set');
}
// validate file is really a uploaded file
$file = $values['import_file'];
if (!array_key_exists('tmp_name', $file) || !is_uploaded_file($file['tmp_name'])) {
throw new Exception('wrong file.');
}
$csvFile = new CsvFile();
$records = $csvFile->import($file['tmp_name']);
// check fields
$fields = array_intersect($csvFile->getFields(), $this->exportColumns);
if (!$fields || !in_array('username', $fields)) {
throw new Exception("Username is not present in import file");
}
$db = $this->getDb();
// create temporary table
$query = "create temporary table userimport like " . $this->sqlParser->getTable();
$res = $db->query($query);
if ($db->isError($res)) {
throw new Exception($res->getDebugInfo());
}
// filter and insert records
$fieldNames = array_intersect($this->sqlParser->getFieldNames(), $fields);
ksort($fieldNames);
$query = "insert into userimport(" . join(",", array_keys($fieldNames)) . ") values ";
$recordFields = array();
foreach ($fieldNames as $name) {
$recordFields[$name] = $name;
}
$rows = array();
foreach ($records as $record) {
$record = array_intersect_key($record, $recordFields);
if (!$record) {
next;
}
ksort($record);
if (array_key_exists('role', $record) && $record['role']) {
$record['role'] = $this->getRoleId($record['role']);
}
foreach ($record as &$item) {
//if(!$item) $item = "NULL";
$item = addslashes($item);
}
$rows[] = "('" . join("','", $record) . "')";
}
$query .= join(",", $rows);
$res = $db->query($query);
if ($db->isError($res)) {
throw new Exception($res->getDebugInfo());
}
// update records
$update = array();
$insert = array();
foreach ($fieldNames as $key => $value) {
$insert[] = "a.{$key}";
// skip username and password
if ($key == 'username' || $key == 'password') {
continue;
}
$update[] = "a.{$key} = b.{$key}";
}
$tablename = $this->sqlParser->getTable();
$query = sprintf("update %s as a inner join userimport as b on a.usr_username = b.usr_username set %s", $tablename, join(",", $update));
$res = $db->query($query);
if ($db->isError($res)) {
throw new Exception($res->getDebugInfo());
}
// insert records
$query = sprintf("insert into %s (%s,usr_create) select %s, now() from userimport as a left join %s as b on a.usr_username = b.usr_username where b.usr_id is NULL", $tablename, join(",", array_keys($fieldNames)), join(",", $insert), $tablename);
$res = $db->query($query);
if ($db->isError($res)) {
throw new Exception($res->getDebugInfo());
}
// update group
foreach ($grp_used as $grp_id) {
$query = sprintf("insert into usergroup (usr_id, grp_id) \n\t\t\t\t\t\t\t\t\t\t\t\t\tselect a.usr_id, %d \n\t\t\t\t\t\t\t\t\t\t\t\t\tfrom %s as a \n\t\t\t\t\t\t\t\t\t\t\t\t\tinner join userimport as b \n\t\t\t\t\t\t\t\t\t\t\t\t\ton a.usr_username = b.usr_username \n\t\t\t\t\t\t\t\t\t\t\t\t\tleft join usergroup as c \n\t\t\t\t\t\t\t\t\t\t\t\t\ton a.usr_id = c.usr_id and c.grp_id = %d \n\t\t\t\t\t\t\t\t\t\t\t\t\twhere c.usr_id is NULL", $grp_id, $this->sqlParser->getTable(), $grp_id);
$res = $db->query($query);
if ($db->isError($res)) {
throw new Exception($res->getDebugInfo());
}
}
viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW);
$this->handleAdminOverview();
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleImportGet();
}
//.........这里部分代码省略.........
示例12: handleAdminDeletePost
private function handleAdminDeletePost()
{
$request = Request::getInstance();
try {
if (!$request->exists('id')) {
throw new Exception('Gebruikersgroep ontbreekt.');
}
$id = intval($request->getValue('id'));
$this->delete(array('id' => $id));
viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW);
$this->handleAdminOverview();
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleAdminDeleteGet();
}
}
示例13: fetch
public function fetch()
{
$includeFile = is_file($this->getSource());
$template = new TemplateEngine($this->getSource(), $includeFile);
$template->setVariable($this->vars, null, false);
return $template->fetch();
}
示例14: handleLoginGet
private function handleLoginGet($referer = '')
{
$request = Request::getInstance();
if (!$referer) {
$tree = $this->director->tree;
//$referer = $tree->getPath($tree->getFirstNodeId());
$referer = $request->getUrl();
}
// clear login state
$autentication = Authentication::getInstance();
if ($autentication->isLogin()) {
$autentication->logout();
header("Location: /" . $request->getRoot());
exit;
}
$template = new TemplateEngine($this->getPath() . "templates/" . $this->templateFile);
$template->setVariable('referer', $referer, false);
$template->setVariable('pageTitle', 'Login', false);
$template->setVariable('dbExists', $this->director->dbExists, false);
$this->template[$this->director->theme->getConfig()->main_tag] = $template;
}
示例15: handleTreeEditPost
private function handleTreeEditPost()
{
$request = Request::getInstance();
$values = $request->getRequest(Request::POST);
try {
if (!$request->exists('tree_id')) {
throw new Exception('Node ontbreekt.');
}
if (!$request->exists('tag')) {
throw new Exception('Tag ontbreekt.');
}
$tree_id = intval($request->getValue('tree_id'));
$tag = $request->getValue('tag');
$key = array('tree_id' => $tree_id, 'tag' => $tag);
if ($this->exists($key)) {
$this->update($key, $values);
} else {
$this->insert($values);
}
viewManager::getInstance()->setType(ViewManager::ADMIN_OVERVIEW);
$this->referer->handleHttpGetRequest();
} catch (Exception $e) {
$template = new TemplateEngine();
$template->setVariable('errorMessage', $e->getMessage(), false);
$this->handleTreeEditGet(false);
}
}