本文整理汇总了PHP中Content::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Content::save方法的具体用法?PHP Content::save怎么用?PHP Content::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Content
的用法示例。
在下文中一共展示了Content::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveContent
/**
* コンテンツデータを登録する
* コンテンツデータを次のように作成して引き渡す
* array('Content' =>
* array( 'model_id' => 'モデルでのID'
* 'category' => 'カテゴリ名',
* 'title' => 'コンテンツタイトル', // 検索対象
* 'detail' => 'コンテンツ内容', // 検索対象
* 'url' => 'URL',
* 'status' => '公開ステータス'
* ))
*
* @param Model $model
* @param array $data
* @return boolean
* @access public
*/
public function saveContent(Model $model, $data)
{
if (!$data) {
return;
}
$data['Content']['model'] = $model->alias;
// タグ、空白を除外
$data['Content']['detail'] = str_replace(array("\r\n", "\r", "\n", "\t", "\\s"), '', trim(strip_tags($data['Content']['detail'])));
// 検索用データとして保存
$id = '';
$this->Content = ClassRegistry::init('Content');
if (!empty($data['Content']['model_id'])) {
$before = $this->Content->find('first', array('fields' => array('Content.id', 'Content.category'), 'conditions' => array('Content.model' => $data['Content']['model'], 'Content.model_id' => $data['Content']['model_id'])));
}
if ($before) {
$data['Content']['id'] = $before['Content']['id'];
$this->Content->set($data);
} else {
if (empty($data['Content']['priority'])) {
$data['Content']['priority'] = '0.5';
}
$this->Content->create($data);
}
$result = $this->Content->save();
// カテゴリを site_configsに保存
if ($result) {
return $this->updateContentMeta($model, $data['Content']['category']);
}
return $result;
}
示例2: actionAdd
public function actionAdd()
{
$this->layout = '//layouts/admin';
$this->pageTitle = 'Новая страница';
$this->breadcrumbs = array('Страницы контента' => array('/admin/content'), 'Новая страница');
$success = false;
if (isset($_POST['data'])) {
$model = new Content();
$dataArray = $_POST['data'];
$dataArray['timestamp'] = time();
$dataArray['views_count'] = 0;
$dataArray['is_active'] = isset($_POST['data']['is_active']) && $_POST['data']['is_active'] == 1 ? 1 : 0;
$model->setAttributes($dataArray);
if ($model->save()) {
$success = true;
if (isset($_FILES['anons_pic']) && $_FILES["anons_pic"]["name"] || isset($_FILES['content_pic']) && $_FILES["content_pic"]["name"]) {
$uploaddir = 'images/upload/' . date("d.m.Y", time());
if (!is_dir($uploaddir)) {
mkdir($uploaddir);
}
if (isset($_FILES['anons_pic'])) {
$tmp_name = $_FILES["anons_pic"]["tmp_name"];
$name = $_FILES["anons_pic"]["name"];
if ($name) {
$uploadfile = $uploaddir . '/na_' . $model->id . '_' . md5(basename($name) . time()) . "." . end(explode(".", $name));
if (move_uploaded_file($tmp_name, $uploadfile)) {
$model->setAttributes(array("anons_pic" => "/" . $uploadfile));
if (!$model->save()) {
print_r($model->errors);
die;
}
}
}
}
if (isset($_FILES['content_pic'])) {
$tmp_name = $_FILES["content_pic"]["tmp_name"];
$name = $_FILES["content_pic"]["name"];
if ($name) {
$uploadfile = $uploaddir . '/nc_' . $model->id . '_' . md5(basename($name) . time()) . "." . end(explode(".", $name));
if (move_uploaded_file($tmp_name, $uploadfile)) {
$model->setAttributes(array("content_pic" => "/" . $uploadfile));
$model->save();
}
}
}
}
}
}
if ($success) {
$this->redirect("/admin/content");
}
if (!isset($model) || !is_object($model)) {
$model = new Content();
}
$this->render('add', array("errors" => $model->errors));
}
示例3: afterSave
/**
* After Saving of records of type content, automatically add/bind the
* corresponding content to it.
*
* If the automatic wall adding (autoAddToWall) is enabled, also create
* wall entry for this content.
*
* NOTE: If you overwrite this method, e.g. for creating activities ensure
* this (parent) implementation is invoked BEFORE your implementation. Otherwise
* the Content Object is not available.
*/
public function afterSave()
{
// Auto follow this content
if (get_class($this) != 'Activity') {
$this->follow($this->created_by);
}
if ($this->isNewRecord) {
$this->content->user_id = $this->created_by;
$this->content->object_model = get_class($this);
$this->content->object_id = $this->getPrimaryKey();
$this->content->created_at = $this->created_at;
$this->content->created_by = $this->created_by;
}
$this->content->updated_at = $this->updated_at;
$this->content->updated_by = $this->updated_by;
$this->content->save();
parent::afterSave();
if ($this->isNewRecord && $this->autoAddToWall) {
$this->content->addToWall();
}
// When Space Content, update also last visit
if ($this->content->space_id) {
$membership = $this->content->space->getMembership(Yii::app()->user->id);
if ($membership) {
$membership->updateLastVisit();
}
}
}
示例4: save
/**
* Saves Announcement in database
* @access public
*/
public function save()
{
Logger::log("Enter: Announcement::save_announcement");
Logger::log("Calling: Content::save");
if ($this->content_id) {
parent::save();
//for child class
$data = array();
$update = '';
$field_array = array('announcement_time', 'position', 'status');
foreach ($field_array as $key => $value) {
if ($this->{$value}) {
$update .= ' ' . $value . ' = ?,';
array_push($data, $this->{$value});
}
}
if (!empty($update)) {
$update = substr($update, 0, -1);
$sql = 'UPDATE {announcements} SET ' . $update . ' WHERE content_id = ?';
array_push($data, $this->content_id);
}
$res = Dal::query($sql, $data);
} else {
parent::save();
$sql = "INSERT INTO {announcements} (content_id, announcement_time, position, status, is_active) VALUES (?, ?, ?, ?, ?)";
$data = array($this->content_id, $this->announcement_time, $this->position, $this->status, $this->is_active);
$res = Dal::query($sql, $data);
return array('aid' => $this->content_id);
}
Logger::log("Exit: Image::save_announcement");
return $this->content_id;
}
示例5: save
/**
* Saves blog post in db
* @access public
*/
public function save()
{
Logger::log("Enter: BlogPost::save");
Logger::log("Calling: Content::save");
parent::save();
Logger::log("Exit: BlogPost::save");
return;
}
示例6: ajax_save
public function ajax_save()
{
$id = (int) $this->input->post('id');
$pid = (int) $this->input->post('page_id');
$div = $this->input->post('div');
$title = $this->input->post('title');
$text = $this->input->post('text');
$img = $this->input->post('image');
//file_put_contents('post', json_encode($_POST));die;
$page = Page::factory($pid);
$content = Content::factory()->where('div', $div)->where_related_page('id', $pid)->limit(1)->get();
if (!$content->exists()) {
$content = new Content();
$content->div = $div;
$ctype = ContentType::factory()->where('classname', 'Repeatable')->limit(1)->get();
$content->editor_id = $this->user->id;
$content->save(array($page, $ctype));
} else {
$content->editor_id = $this->user->id;
$content->save();
}
if (empty($id)) {
$item = new RepeatableItem();
$item->timestamp = time();
} else {
$item = RepeatableItem::factory($id);
}
$item->title = $title;
$item->text = $text;
$item->image = trim($img, '/');
if (empty($id)) {
$item->save(array($content, $this->user));
} else {
$item->save();
}
if (empty($id)) {
$msg = __("New item published: \"%s\"", $title);
} else {
$msg = __("Changes saved in \"%s\"", $title);
}
echo json_encode(array('status' => 'OK', 'message' => $msg, 'id' => $item->id));
}
示例7: Setting
function after_content_create($content)
{
$s = new Setting();
$s->where('name', 'uploading_publish_on_captured_date')->get();
if ($s->exists() && $s->value === 'true') {
$fresh = new Content();
$fresh->get_by_id($content['id']);
$fresh->published_on = $content['captured_on']['utc'] ? $content['captured_on']['timestamp'] : 'captured_on';
$fresh->save();
}
}
示例8: save
public function save()
{
if (!$this->validate()) {
return false;
}
$model = new Content();
$model->setAttributes($this->getAttributes());
if (!$model->save()) {
$this->addErrors($model->getErrors());
return false;
}
return true;
}
示例9: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Content();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Content'])) {
$model->attributes = $_POST['Content'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例10: foreach
function save_orderlist($id = FALSE)
{
if ($_POST) {
foreach ($_POST['orderlist'] as $key => $item) {
if ($item) {
$content = new Content(@$_POST['orderid'][$key]);
$content->from_array(array('orderlist' => $item));
$content->save();
}
}
set_notify('success', lang('save_data_complete'));
}
redirect($_SERVER['HTTP_REFERER']);
}
示例11: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$this->addToolbar();
$model = new Content();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Content'])) {
$model->attributes = $_POST['Content'];
$model->title = $model->title;
if ($model->save()) {
$this->redirect(array('index'));
}
}
$this->render('form', array('model' => $model));
}
示例12: post
/**
* Implementation for 'POST' method for Rest API
*
* @param mixed $conCategory, $conParent, $conId, $conLang Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function post($conCategory, $conParent, $conId, $conLang, $conValue)
{
try {
$result = array();
$obj = new Content();
$obj->setConCategory($conCategory);
$obj->setConParent($conParent);
$obj->setConId($conId);
$obj->setConLang($conLang);
$obj->setConValue($conValue);
$obj->save();
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
}
示例13: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aContent !== null) {
if ($this->aContent->isModified() || $this->aContent->isNew()) {
$affectedRows += $this->aContent->save($con);
}
$this->setContent($this->aContent);
}
if ($this->isNew()) {
$this->modifiedColumns[] = DisciplinaPeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = DisciplinaPeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += DisciplinaPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
if ($this->collGradeunits !== null) {
foreach ($this->collGradeunits as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例14: save
public function save()
{
if ($this->perm->can_create == 'y') {
$data = new Content();
if ($_POST['id'] == '') {
$_POST['created_by'] = $this->current_user->id;
$_POST['created'] = date("Y-m-d H:i:s");
} else {
$_POST['updated_by'] = $this->current_user->id;
$_POST['updated'] = date("Y-m-d H:i:s");
}
$data->from_array($_POST);
$data->save();
save_logs($this->menu_id, 'Update', $this->session->userdata("id"), ' Update Explanation ');
}
redirect($_SERVER['HTTP_REFERER']);
}
示例15: actionAdd
public function actionAdd()
{
date_default_timezone_set('Asia/Shanghai');
$model = new Content();
$model->postdate = date("Y-m-d H:i:s");
if (isset($_POST['Content'])) {
$model->attributes = $_POST['Content'];
// validate user input and redirect to the previous page if valid
if ($model->save()) {
$this->redirect(Yii::app()->createURL("manage/index"));
} else {
print_r($model->errors);
exit;
}
}
$this->render('add', array("model" => $model));
}