当前位置: 首页>>代码示例>>PHP>>正文


PHP ContentModel::save方法代码示例

本文整理汇总了PHP中ContentModel::save方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentModel::save方法的具体用法?PHP ContentModel::save怎么用?PHP ContentModel::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContentModel的用法示例。


在下文中一共展示了ContentModel::save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: QuickDraftSave

 /**
  * Form Handler to save a content quick create.
  *
  * @param Form $form
  *
  * @return string|bool
  */
 public static function QuickDraftSave(Form $form)
 {
     if (!$form->getElementValue('title')) {
         \Core\set_message('All pages must have titles.', 'error');
         return false;
     }
     /** @var $model ContentModel */
     $model = new ContentModel();
     /** @var $page PageModel Page object for this model, already linked up! */
     $page = $model->getLink('Page');
     // The content nickname is derived from the page title.
     $model->set('nickname', $form->getElementValue('title'));
     $model->save();
     $ins = new InsertableModel();
     $ins->set('site', $page->get('site'));
     $ins->set('baseurl', '/content/view/' . $model->get('id'));
     $ins->set('name', 'body');
     $ins->set('value', '<p>' . nl2br($form->getElementValue('content')) . '</p>');
     $ins->save();
     $page->set('title', $form->getElementValue('title'));
     $page->set('published_status', 'draft');
     $page->set('editurl', '/content/edit/' . $model->get('id'));
     $page->set('deleteurl', '/content/delete/' . $model->get('id'));
     $page->set('component', 'content');
     $page->save();
     return true;
 }
开发者ID:nicholasryan,项目名称:CorePlus,代码行数:34,代码来源:ContentAdminWidget.php

示例2: update

 public function update()
 {
     $content = new ContentModel();
     $id = $_POST['id'];
     if ($id != '') {
         $data['id'] = $id;
         $data['title'] = $_POST['title'];
         $data['content'] = $_POST['content'];
         if ($content->save($data)) {
             $this->assign("jumpUrl", "__URL__/index");
             $this->success("更新数据成功!");
         } else {
             $this->assign("jumpUrl", "__URL__/index");
             $this->success("更新数据失败!");
         }
     } else {
         echo "保存数据失败!";
     }
 }
开发者ID:highestgoodlikewater,项目名称:class-website,代码行数:19,代码来源:IndexAction.class.php

示例3: createContentElements

 protected function createContentElements(&$objItem)
 {
     if ($objItem->tl_content) {
         // need to wrap <p> around text for contao
         $tidyConfig = array('enclose-text' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'quote-ampersand' => true, 'clean' => false, 'wrap-attributes' => false, 'wrap' => 500);
         $bodyText = '<!DOCTYPE html><head><title></title></head><body>' . $objItem->tl_content . '</body></html>';
         //			$bodyText = $this->convert_external_link_tags($bodyText);
         //			$bodyText = $this->convert_internal_link_tags($bodyText);
         $bodyText = $this->nl2p($bodyText);
         $tidy = new \tidy();
         $tidy->parseString($bodyText, $tidyConfig, $GLOBALS['TL_CONFIG']['dbCharset']);
         $body = $tidy->body();
         $objContent = new \ContentModel();
         $objContent->text = urldecode($objContent->text);
         // decode, otherwise link and email regex wont work
         $objContent->text = trim(str_replace(array('<body>', '</body>'), '', $body));
         $objContent->text = preg_replace("/<img[^>]+\\>/i", "", $objContent->text);
         // strip images
         // remove inline styles
         $objContent->text = preg_replace('#(<[a-z ]*)(style=("|\')(.*?)("|\'))([a-z ]*>)#', '\\1\\6', $objContent->text);
         // remove white space from empty tags
         $objContent->text = preg_replace('#(<[a-z]*)(\\s+)>#', '$1>', $objContent->text);
         // create links from text
         $objContent->text = preg_replace('!(\\s|^)((https?://|www\\.)+[a-z0-9_./?=&-]+)!i', ' <a href="http://$2" target="_blank">$2</a>', $objContent->text);
         // replace <b> by <strong>
         $objContent->text = preg_replace('!<b(.*?)>(.*?)</b>!i', '<strong>$2</strong>', $objContent->text);
         // replace plain email text with inserttags
         $objContent->text = preg_replace('/([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\\.([A-Z]{2,4})(\\((.+?)\\))?(?![^<]*>)(?![^>]*<)/i', "{{email::\$1@\$2.\$3}}", $objContent->text);
         // replace email links with inserttags
         $objContent->text = preg_replace('/<a.*href=[\'|"]mailto:([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\\.([A-Z]{2,4})(\\((.+?)\\))?[\'|"].*>(.*)<\\/a>/i', "{{email::\$1@\$2.\$3}}", $objContent->text);
         // strip not allowed tags
         $objContent->text = strip_tags($objContent->text, \Config::get('allowedTags'));
         $objContent->text = $this->stripAttributes($objContent->text, array('style', 'class', 'id'));
         $objContent->ptable = $this->dbTargetTable;
         $objContent->pid = $objItem->id;
         $objContent->sorting = 16;
         $objContent->tstamp = time();
         $objContent->type = 'text';
         $objContent->save();
     }
 }
开发者ID:heimrichhannot,项目名称:contao-entity_import,代码行数:41,代码来源:NewsImporter.php

示例4: createElement

 /**
  * Create a new wrapper element.
  *
  * @param \Model $parent  The parent element.
  * @param int    $sorting The sorting index.
  * @param string $type    The wrapper type.
  *
  * @return \ContentModel
  */
 protected function createElement($parent, &$sorting, $type = Helper::TYPE_SEPARATOR)
 {
     $model = new \ContentModel();
     if ($type == Helper::TYPE_START) {
         $sorting = $sorting - 2;
     } else {
         $sorting = $sorting + 2;
         $model->bootstrap_parentId = $parent->id;
     }
     $model->tstamp = time();
     $model->pid = $parent->pid;
     $model->ptable = $parent->ptable;
     $model->type = $this->wrapper->getTypeName($type);
     $model->sorting = $sorting;
     $model->save();
     return $model;
 }
开发者ID:contao-bootstrap,项目名称:core,代码行数:26,代码来源:Wrapper.php

示例5: createContentElements

 protected function createContentElements(&$objItem)
 {
     if ($objItem->tl_content) {
         // need to wrap <p> around text for contao
         $tidyConfig = array('enclose-text' => true, 'drop-font-tags' => true, 'drop-proprietary-attributes' => true, 'quote-ampersand' => true, 'clean' => false);
         $bodyText = '<!DOCTYPE html><head><title></title></head><body>' . $objItem->tl_content . '</body></html>';
         //			$bodyText = $this->convert_external_link_tags($bodyText);
         //			$bodyText = $this->convert_internal_link_tags($bodyText);
         $bodyText = $this->nl2p($bodyText);
         $tidy = new \tidy();
         $tidy->parseString($bodyText, $tidyConfig, $GLOBALS['TL_CONFIG']['dbCharset']);
         $body = $tidy->body();
         $objContent = new \ContentModel();
         $objContent->text = trim(str_replace(array('<body>', '</body>'), '', $body));
         $objContent->text = preg_replace("/<img[^>]+\\>/i", "", $objContent->text);
         // strip images
         // create links from text
         $objContent->text = preg_replace('!(\\s|^)((https?://|www\\.)+[a-z0-9_./?=&-]+)!i', ' <a href="http://$2" target="_blank">$2</a>', $objContent->text);
         // replace <b> by <strong>
         $objContent->text = preg_replace('!<b(.*?)>(.*?)</b>!i', '<strong>$2</strong>', $objContent->text);
         // replace emails with inserttags
         $objContent->text = preg_replace('/([A-Z0-9._%+-]+)@([A-Z0-9.-]+)\\.([A-Z]{2,4})(\\((.+?)\\))?/i', "{{email::\$1@\$2.\$3}}", $objContent->text);
         // strip not allowed tags
         $objContent->text = strip_tags($objContent->text, \Config::get('allowedTags'));
         $objContent->text = $this->stripAttributes($objContent->text, array('style', 'class', 'id'));
         $objContent->ptable = static::$strTable;
         $objContent->pid = $objItem->id;
         $objContent->sorting = 16;
         $objContent->tstamp = time();
         $objContent->type = 'text';
         $objContent->save();
     }
 }
开发者ID:heimrichhannot,项目名称:contao-newsport,代码行数:33,代码来源:NewsImporter.php

示例6: ModelFactory

//}
$fac = new ModelFactory('BlogArticleModel');
foreach ($fac->get() as $model) {
    /** @var BlogArticleModel $model */
    /** @var PageModel $page */
    $page = $model->getLink('Page');
    $page->setMeta('description', $model->getTeaser());
    $page->setMeta('image', $model->get('image'));
    $page->set('published_status', $model->get('status'));
    $page->set('published', $model->get('published'));
    // Clone this to a content page.
    $content = new ContentModel();
    $content->set('nickname', $model->get('title'));
    $content->set('created', $model->get('created'));
    $content->set('updated', $model->get('updated'));
    $content->save();
    $page->set('component', 'content');
    $page->set('baseurl', '/content/view/' . $content->get('id'));
    $page->set('editurl', '/content/edit/' . $content->get('id'));
    $page->set('deleteurl', '/content/delete/' . $content->get('id'));
    $page->set('page_template', 'blog-article.tpl');
    $page->save();
    $insertable = new InsertableModel();
    $insertable->set('site', $page->get('site'));
    $insertable->set('baseurl', '/content/view/' . $content->get('id'));
    $insertable->set('name', 'body');
    $insertable->set('value', $model->get('body'));
    $insertable->save();
    $model->resetLink('Page');
    $model->delete();
}
开发者ID:nicholasryan,项目名称:CorePlus,代码行数:31,代码来源:next_page_updates.php


注:本文中的ContentModel::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。