本文整理汇总了PHP中Template::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Template::save方法的具体用法?PHP Template::save怎么用?PHP Template::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Template
的用法示例。
在下文中一共展示了Template::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* 新建模板
* @author yongze
*/
public function actionCreate($id)
{
$dsModel = $this->loadModel((int) $id, 'ds');
$dbModel = $this->loadModel((int) $dsModel->database_id, 'db');
$model = new Template('Create');
$data = array();
if (isset($_POST['Template'])) {
if (isset($_POST['Template']['type'])) {
$_POST['Template']['type'] = (int) $_POST['Template']['type'];
}
$model->attributes = $_POST['Template'];
$model->dataset_id = (int) $dsModel->id;
$model->dataset_name = $dsModel->name;
if ($model->save()) {
$this->addLog('template', $model->id, '添加新模板“' . $model->tpname . '”');
Yii::app()->user->setFlash("success", "新建 <b>{$model->tpname}</b> 模板成功!");
} else {
$errorMsg = '';
$errorErr = $model->getErrors();
foreach ($errorErr as $value) {
$errorMsg .= "\t" . $value[0];
}
$errorMsg = trim($errorMsg, ',');
Yii::app()->user->setFlash("error", $errorMsg);
}
$this->redirect(array('/Template/Index/' . $dsModel->id));
}
$data['dbModel'] = $dbModel;
$data['dsModel'] = $dsModel;
$data['model'] = $model;
$data['datasetId'] = $id;
$this->_getFieldsInfos($data['_txtfiled'], $id);
$this->render('edit', $data);
}
示例2: getAdminInterface
/**
* Build and return admin interface
*
* Any module providing an admin interface is required to have this function, which
* returns a string containing the (x)html of it's admin interface.
* @return string
*/
function getAdminInterface()
{
$this->addCSS('/modules/Templater/css/templates.css');
$templates = Template::getAllTemplates();
if (!isset($_REQUEST['template_id'])) {
$this->smarty->assign('curtemplate', $templates[0]);
} else {
if (isset($_REQUEST['save'])) {
$t = new Template($_REQUEST['template_id']);
$t->setData(u($_REQUEST['editor']));
$t->setTimestamp(date('Y-m-d H:i:s'));
$t->setId(null);
$t->save();
$this->smarty->assign('curtemplate', $t);
$templates = Template::getAllTemplates();
} else {
if (isset($_REQUEST['switch_template'])) {
$this->smarty->clear_assign('curtemplate');
$this->smarty->assign('curtemplate', new Template($_REQUEST['template']));
} else {
if (isset($_REQUEST['switch_revision'])) {
$this->smarty->clear_assign('curtemplate');
$this->smarty->assign('curtemplate', new Template($_REQUEST['revision']));
} else {
$this->smarty->assign('curtemplate', new Template($_REQUEST['template_id']));
}
}
}
}
$this->smarty->assign('templates', $templates);
return $this->smarty->fetch('admin/templates.tpl');
}
示例3: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int|null|void
*/
public function execute(InputInterface $input, OutputInterface $output)
{
parent::bootstrapProcessWire($output);
$name = $input->getArgument('name');
$fields = explode(",", $input->getOption('fields'));
if (wire("templates")->get("{$name}")) {
$output->writeln("<error>Template '{$name}' already exists!</error>");
exit(1);
}
$fieldgroup = new \Fieldgroup();
$fieldgroup->name = $name;
$fieldgroup->add("title");
if ($input->getOption('fields')) {
foreach ($fields as $field) {
$this->checkIfFieldExists($field, $output);
$fieldgroup->add($field);
}
}
$fieldgroup->save();
$template = new \Template();
$template->name = $name;
$template->fieldgroup = $fieldgroup;
$template->save();
if (!$input->getOption('nofile')) {
$this->createTemplateFile($name);
}
$output->writeln("<info>Template '{$name}' created successfully!</info>");
}
示例4: parse
public static function parse($raw_template)
{
//High-level blocks
$blocks = preg_split('/\\-\\-\\-(\\w+)\\-\\-\\-/', $raw_template, -1, PREG_SPLIT_DELIM_CAPTURE);
$trimmed_blocks = array_map('trim', $blocks);
$tp = new Template();
$tp->title = $trimmed_blocks[2];
$blocks = array_slice($trimmed_blocks, 4);
$section_type = "deliverable";
$ord = 0;
$vars = array();
foreach ($blocks as $block) {
if ($block == "REQUIREMENTS") {
$section_type = "requirement";
continue;
}
$bits = preg_split('/(^#|[\\r\\n]+#)\\s/', $block, -1, PREG_SPLIT_NO_EMPTY);
foreach ($bits as $bit) {
$ts = new TemplateSection();
$sec_bits = preg_split('/[\\r\\n]#{2,3}/', $bit);
$ts->title = trim($sec_bits[0]);
$ts->section_type = $section_type;
if (count($sec_bits) < 3) {
//no help text
$ts->help_text = '';
$ts->body = trim($sec_bits[1]);
} else {
$ts->help_text = trim($sec_bits[1]);
$ts->body = trim($sec_bits[2]);
}
$ts->display_order = $ord;
preg_match_all('/\\{\\{\\s*([^\\}]*)\\}\\}/', $ts->body, $variables);
foreach ($variables[1] as $var) {
$var_bits = explode("|", $var);
$var_name = trim(isset($var_bits[0]) ? $var_bits[0] : $var);
//avoid dupes
if (!array_key_exists($var_name, $vars)) {
$vars[$var_name] = array();
}
if (count($var_bits) > 1) {
$vars[$var_name]['name'] = trim($var_bits[1]);
}
if (count($var_bits) > 2) {
$vars[$var_name]['help_text'] = trim($var_bits[2]);
}
}
$sections[] = $ts;
$ord++;
}
}
$tp->variables = $vars;
$tp->save();
$tp->template_sections()->save($sections);
return $tp;
}
示例5: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Template();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Template'])) {
$model->attributes = $_POST['Template'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例6: upload
public function upload()
{
$input = Input::all();
$validation = Validator::make($input, Template::$rules);
if ($validation->passes()) {
$file = Input::file('image');
// your file upload input field in the form should be named 'file'
$css = Input::file('css');
$destinationPath = app_path() . '/views/uploads/layouts';
$csspath = public_path() . '/assets/css';
$thumbdestination = public_path() . '/assets/thumb';
$name = Input::get('name');
$newname = str_replace(' ', '_', $name);
$filename = $file->getClientOriginalName();
//$extension =$file->getClientOriginalExtension();
//if you need extension of the file
$uploadSuccess = Input::file('image')->move($destinationPath, $filename);
$extension = Input::file('thumbnail')->getClientOriginalExtension();
$uploadthumbnail = Input::file('thumbnail')->move($thumbdestination, $newname . '.' . $extension);
$uploadcss = Input::file('css')->move($csspath, $css . '.css');
$input = Input::all();
if ($uploadSuccess && $uploadthumbnail) {
//return Response::json('success', 200); // or do a redirect with some message that file was uploaded
$this->template->name = Input::get('name');
$this->template->file = $filename;
$this->template->css = $css;
$this->template->save();
$id = DB::getPdo()->lastInsertId();
$thumb = new Image_thumbnail();
$thumb->img = $newname . '.' . $extension;
$thumb->title = $name;
$thumb->t_id = $id;
$thumb->save();
return Redirect::route('templates.definefields', array('id' => $id));
}
}
return Redirect::route('templates.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
}
示例7: save
public function save()
{
if ($this->html) {
$body = '{if !$html}' . "\n" . $this->body . "\n" . '{/if}{*html*}' . "\n" . '{if $html}' . "\n" . $this->html . "\n" . '{/if}{*html*}';
} else {
$body = $this->body;
}
if ($this->isFragment()) {
$this->code = $body;
} else {
$this->code = $this->subject . "\n" . $body;
}
return parent::save();
}
示例8: envTemplate
protected function envTemplate()
{
$template = new Template();
$template->color = '1';
$template->layout = '1';
$template->user_id = 1;
$template->save();
$template2 = new Template();
$template2->color = '1';
$template2->layout = '1';
$template2->user_id = 2;
$template2->save();
$template3 = new Template();
$template3->color = '1';
$template3->layout = '1';
$template3->user_id = 3;
$template3->save();
}
示例9: createNewsletter
/**
* @before _secure, _admin
*/
public function createNewsletter()
{
$this->seo(array("title" => "Create Newsletter", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView()));
$view = $this->getActionView();
$groups = \Group::all(array(), array("name", "id"));
if (count($groups) == 0) {
$this->_createGroup(array("name" => "All", "users" => json_encode(array("*"))));
$groups = \Group::all(array(), array("name", "id"));
}
if (RequestMethods::post("action") == "createNewsletter") {
$message = new Template(array("subject" => RequestMethods::post("subject"), "body" => RequestMethods::post("body")));
$message->save();
$newsletter = new Newsletter(array("template_id" => $message->id, "group_id" => RequestMethods::post("user_group"), "scheduled" => RequestMethods::post("scheduled")));
$newsletter->save();
$view->set("success", TRUE);
}
$view->set("groups", $groups);
}
示例10: update
/**
* Create a template
* Add a fieldgroup with the 'title' field
* @todo add all global fields instead
*/
public function update()
{
$t = new Template();
$t->name = $this->getTemplateName();
$fg = new Fieldgroup();
$fg->name = $this->getTemplateName();
foreach ($this->fields as $field) {
// add global fields
if (!($field->flags & Field::flagGlobal)) {
continue;
}
$fg->add($field);
}
$fg->save();
$t->fieldgroup = $fg;
$t->fieldgroup->save();
$t->save();
$this->templateSetup($t);
$t->fieldgroup->save();
$t->save();
return $t;
}
示例11: executeAdd
/**
* Add
*/
public function executeAdd()
{
if ($this->isGET()) {
return $this->renderJson(array("success" => false, "info" => "POST Only."));
} else {
$template = new Template();
$template->setName($this->getRequestParameter('name'));
$template->setType($this->getRequestParameter('type'));
$template->save();
foreach ($this->getRequestParameter('record') as $data) {
$record = new TemplateRecord();
$record->setTemplateId($template->getId());
$record->setName($data['name']);
$record->setType($data['type']);
$record->setContent($data['content']);
$record->setTtl($data['ttl']);
if ($data['type'] == 'MX') {
$record->setPrio($data['prio']);
}
$record->save();
}
return $this->renderJson(array("success" => true, "info" => "Template added."));
}
}
示例12: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Template();
$model->companyId = Yii::app()->user->getState('selectedCompanyId');
$model->allowFreeTextField = 1;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Template'])) {
$model->attributes = $_POST['Template'];
$model->companyId = Yii::app()->user->getState('selectedCompanyId');
if ($model->save()) {
if ($this->updateRows($model)) {
if (isset($_POST['AddRow']) || isset($_POST['deleterow'])) {
$this->redirect(array('update', 'id' => $model->id));
} else {
$this->redirect(array('admin'));
}
}
}
}
$model->dateChanged = User::getDateFormatted(date('Y-m-d'));
$this->render('create', array('model' => $model, 'update' => false));
}
示例13: catch
}
// if we got here, we're golden.
} catch (CmsEditContentException $e) {
$error .= "<li>" . $e->getMessage() . "</li>";
$validinfo = false;
}
}
if ($validinfo) {
$newtemplate = new Template();
$newtemplate->name = $template;
$newtemplate->content = $content;
//$newtemplate->stylesheet = $stylesheet;
$newtemplate->active = $active;
$newtemplate->default = 0;
Events::SendEvent('Core', 'AddTemplatePre', array('template' => &$newtemplate));
$result = $newtemplate->save();
if ($result) {
Events::SendEvent('Core', 'AddTemplatePost', array('template' => &$newtemplate));
// put mention into the admin log
audit($newtemplate->id, 'HTML-template: ' . $template, 'Added');
redirect($from);
return;
} else {
$error .= "<li>" . lang('errorinsertingtemplate') . "{$query}</li>";
}
}
}
}
include_once "header.php";
if (!$access) {
//echo "<div class=\"pageerrorcontainer\"><p class=\"pageerror\">".lang('noaccessto', array(lang('addtemplate')))."</p></div>";
示例14: doPopulateDatabase
function doPopulateDatabase()
{
// Check for a config file, if it doesn't exist go through the steps to create it.
if (!file_exists(dirname(__FILE__) . '/config.php')) {
header("Location: " . $_SERVER["SCRIPT_NAME"] . "?do=step1");
return;
}
require_once dirname(__FILE__) . "/config.php";
require_once dirname(__FILE__) . "/fwork/lib/Doctrine/Doctrine.php";
spl_autoload_register(array("Doctrine", "autoload"));
Doctrine_Manager::connection($config["database"]["dsn"]);
Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_TBLNAME_FORMAT, $config["database"]["prefix"] . "%s");
Doctrine::createTablesFromModels(dirname(__FILE__) . "/models");
$time = date("Y-m-d H:i:s");
// roles
$role_admin = new Role();
$role_admin->name = "Admin";
$role_admin->auth = 0xffffffff;
$role_admin->created = $time;
$role_admin->save();
$role_staff = new Role();
$role_staff->name = "Staff";
$role_staff->auth = 0x7c700;
$role_staff->created = $time;
$role_staff->save();
$role_guest = new Role();
$role_guest->name = "Guest";
$role_guest->auth = 0x0;
$role_guest->created = $time;
$role_guest->save();
// staff
$staff = new Staff();
$staff->nickname = "admin";
$staff->setPassword("admin");
$staff->Role = $role_admin;
$staff->admin = true;
$staff->comment = "Administrator";
$staff->created = $time;
$staff->save();
// task types
$tasktypes = array('Raw Cap', 'Translate', 'Time', 'Translation Check', 'Typeset', 'Edit', 'Encode', 'Quality Check', 'Karaoke', 'Miscellaneous', 'Translate Signs', 'Release');
foreach ($tasktypes as $key => $name) {
$tasktype = new TaskType();
$tasktype->name = $name;
$tasktype->created = $time;
$tasktype->save();
$tasktypes[$key] = $tasktype;
}
// template
$template = new Template();
$template->name = "Default";
$template->model = $tasktypes[0]->id . ":0->" . $tasktypes[1]->id . ":0; " . $tasktypes[0]->id . ":0->" . $tasktypes[10]->id . ":0; " . $tasktypes[10]->id . ":0->" . $tasktypes[4]->id . ":0; " . $tasktypes[4]->id . ":0->" . $tasktypes[3]->id . ":0; " . $tasktypes[1]->id . ":0->" . $tasktypes[2]->id . ":0; " . $tasktypes[1]->id . ":0->" . $tasktypes[3]->id . ":0; " . $tasktypes[3]->id . ":0->" . $tasktypes[5]->id . ":0; " . $tasktypes[5]->id . ":0->" . $tasktypes[6]->id . ":0; " . $tasktypes[6]->id . ":0->" . $tasktypes[7]->id . ":0; " . $tasktypes[7]->id . ":0->" . $tasktypes[11]->id . ":0; " . $tasktypes[2]->id . ":0->" . $tasktypes[5]->id . ":0; ";
$template->created = $time;
$template->save();
// settings
$settings = array('site.gzip' => true, 'site.gentime' => true);
foreach ($settings as $name => $value) {
$setting = new Setting();
$setting->name = $name;
$setting->value = $value;
$setting->save();
unset($setting);
}
echo <<<EOS
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
\t<title>Frac :: Install</title>
\t<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
\t<h2>Frac Installer</h2>
\t<p>Table data populated successfully. You may now proceed to your <a href="./">Frac installation</a>. The username and password are "admin".</p>
</body>
</html>
EOS;
}
示例15: importTemplates
/**
* @return array Errors Import Template information
*/
public static function importTemplates($root, $companyId, &$errors)
{
$nodeTemplates = $root->getElementsByTagName('template');
foreach ($nodeTemplates as $nodeTemplate) {
if ($root->getAttribute('version') > 1.0) {
$errors[] = '*TemplateVersion*' . Yii::t('lazy8', 'There maybe problems because this is a file version greater then this programs version');
$errors[] = Yii::t('lazy8', 'Select a file and try again');
}
$modelTemplate = new Template();
$modelTemplate->companyId = $companyId;
$modelTemplate->name = $nodeTemplate->getAttribute('name');
$modelTemplate->desc = $nodeTemplate->getAttribute('desc');
$modelTemplate->sortOrder = $nodeTemplate->getAttribute('sortorder');
$modelTemplate->allowAccountingView = $nodeTemplate->getAttribute('allowaccountingview') == '1' ? 1 : 0;
$modelTemplate->allowFreeTextField = $nodeTemplate->getAttribute('allowfreetextfield') == '1' ? 1 : 0;
$modelTemplate->freeTextFieldDefault = $nodeTemplate->getAttribute('freetextfielddefault');
$modelTemplate->allowFilingTextField = $nodeTemplate->getAttribute('allowfilingtextfield') == '1' ? 1 : 0;
$modelTemplate->filingTextFieldDefault = $nodeTemplate->getAttribute('filingtextfielddefault');
$modelTemplate->forceDateToday = $nodeTemplate->getAttribute('forcedatetoday');
if (!$modelTemplate->save()) {
$errors[] = Yii::t('lazy8', 'Could not create the modelTemplate, bad paramters') . ';name=' . $modelTemplate->name . ';' . serialize($modelTemplate->getErrors());
return $errors;
}
$nodesTemplateRows = $nodeTemplate->getElementsByTagName('templaterow');
foreach ($nodesTemplateRows as $nodesTemplateRow) {
$modelTemplateRow = new TemplateRow();
$modelTemplateRow->templateId = $modelTemplate->id;
$modelTemplateRow->name = $nodesTemplateRow->getAttribute('name');
$modelTemplateRow->desc = $nodesTemplateRow->getAttribute('desc');
$modelTemplateRow->sortOrder = $nodesTemplateRow->getAttribute('sortorder');
$modelTemplateRow->isDebit = $nodesTemplateRow->getAttribute('isdebit') == '1' ? 1 : 0;
$modelTemplateRow->defaultAccountId = Template::FindAccountId($nodesTemplateRow->getAttribute('defaultaccount'), $modelTemplate->companyId);
$modelTemplateRow->defaultValue = $nodesTemplateRow->getAttribute('defaultvalue');
$modelTemplateRow->allowMinus = $nodesTemplateRow->getAttribute('allowminus') == '1' ? 1 : 0;
$modelTemplateRow->phpFieldCalc = $nodesTemplateRow->getAttribute('phpfieldcalc');
$modelTemplateRow->allowChangeValue = $nodesTemplateRow->getAttribute('allowchangevalue') == '1' ? 1 : 0;
$modelTemplateRow->allowRepeatThisRow = $nodesTemplateRow->getAttribute('allowrepeatthisrow') == '1' ? 1 : 0;
$modelTemplateRow->allowCustomer = $nodesTemplateRow->getAttribute('allowcustomer') == '1' ? 1 : 0;
$modelTemplateRow->allowNotes = $nodesTemplateRow->getAttribute('allownotes') == '1' ? 1 : 0;
$modelTemplateRow->isFinalBalance = $nodesTemplateRow->getAttribute('isfinalbalance') == '1' ? 1 : 0;
if (!$modelTemplateRow->save()) {
$modelTemplate->delete();
$errors[] = Yii::t('lazy8', 'Could not create the TemplateRow, bad paramters') . ';' . serialize($modelTemplateRow->getErrors());
return;
}
$nodesTemplateRowAccounts = $nodesTemplateRow->getElementsByTagName('templaterowaccount');
foreach ($nodesTemplateRowAccounts as $nodesTemplateRowAccount) {
$modelTemplateRowAccount = new TemplateRowAccount();
$modelTemplateRowAccount->templateRowId = $modelTemplateRow->id;
$modelTemplateRowAccount->accountId = Template::FindAccountId($nodesTemplateRowAccount->getAttribute('code'), $modelTemplate->companyId);
if ($modelTemplateRowAccount->accountId != 0) {
if (!$modelTemplateRowAccount->save()) {
$modelTemplate->delete();
$errors[] = Yii::t('lazy8', 'Could not create the TemplateRowAccount, bad paramters') . ';' . serialize($modelTemplateRowAccount->getErrors());
return;
}
} else {
$errors[] = Yii::t('lazy8', 'Could not create the Account, bad account number') . ';' . $nodesTemplateRowAccount->getAttribute('code');
}
}
}
}
}