本文整理汇总了PHP中Blog::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Blog::save方法的具体用法?PHP Blog::save怎么用?PHP Blog::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blog
的用法示例。
在下文中一共展示了Blog::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
gateKeeper();
$guid = getInput("guid");
$title = getInput("blog_title");
$description = getInput("description");
$access_id = getInput("access_id");
$container_guid = getInput("container_guid");
$owner_guid = getLoggedInUserGuid();
if ($guid) {
$blog = getEntity($guid);
} else {
$blog = new Blog();
}
$blog->title = $title;
$blog->description = $description;
$blog->access_id = $access_id;
$blog->owner_guid = $owner_guid;
$blog->status = "published";
$blog->container_guid = $container_guid;
$blog->save();
new Activity(getLoggedInUserGuid(), "blog:add", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $blog->getURL(), $blog->title, truncate($blog->description)), "", $access_id);
new SystemMessage("Your blog has been published");
forward("blogs/all_blogs");
}
示例2: addPost
public function addPost()
{
// let's setup some rules for our new data
// I'm sure you can come up with better ones
$rules = array('title' => 'required|min:3|max:128', 'content' => 'required', 'file' => 'mimes:jpg,gif,png');
$pictrue = '';
$title = Input::get('title');
$content = Input::get('content');
$description = Input::get('title');
if (empty($description)) {
$description = substr($content, 0, 120);
}
$author_id = Input::get('author_id');
$tags = Input::get('tags');
if (Input::hasFile('file')) {
$file = Input::file('file');
$ext = $file->guessClientExtension();
$filename = $file->getClientOriginalName();
$file->move(public_path() . '/data', md5(date('YmdHis') . $filename) . '.' . $ext);
$pictrue = md5(date('YmdHis') . $filename) . '.' . $ext;
}
$new_blog = array('title' => $title, 'description' => $description, 'content' => $content, 'author_id' => $author_id, 'views' => 0, 'pictrue' => $pictrue, 'tags' => $tags);
$v = Validator::make($new_blog, $rules);
if ($v->fails()) {
// redirect back to the form with
// errors, input and our currently
// logged in user
return Redirect::to('blog/add')->with('user', Auth::user())->withErrors($v)->withInput();
}
// create the new post
$blog = new Blog($new_blog);
$blog->save();
// redirect to viewing our new post
return Redirect::to('blog/view/' . $blog->id);
}
示例3: __construct
public function __construct($data)
{
if (isset($data['session'])) {
$guid = $data['guid'];
$title = $data['blog_title'];
$description = $data['description'];
$access_id = $data['access_id'];
$user = getUserFromSession($data['session']);
if (!$guid) {
$blog = new Blog();
$blog->owner_guid = $user->guid;
$blog->save();
} else {
$blog = getEntity($guid);
}
if ($blog->owner_guid == $user->guid) {
$blog->title = $title;
$blog->description = $description;
$blog->access_id = $access_id;
$blog->status = "draft";
$guid = $blog->save();
$blog = getEntity($guid);
echo json_encode(array("guid" => $guid, "timeago" => display("output/friendly_time", array("timestamp" => $blog->last_updated))));
}
}
}
示例4: save
/**
* @Acl allow blog-writer
* @Acl allow blog-admin
*/
public function save($title, $text, $tags)
{
$blog = new Blog($title, UserSession::get()->username, $text, CoOrg::getLanguage());
$config = BlogConfig::get();
$blog->commentsAllowed = $config->enableComments;
if ($config->enableCommentsFor)
{
$blog->commentsCloseDate = time()+60*60*24*$config->enableCommentsFor;
}
$blog->tags = $tags;
try
{
$blog->save();
$this->notice(t('Your blog item is saved'));
$year = date('Y', $blog->datePosted);
$month = date('m', $blog->datePosted);
$day = date('d', $blog->datePosted);
$this->redirect('blog/show', $year, $month, $day, $blog->ID);
}
catch (ValidationException $e)
{
$this->blog = $blog;
$this->error(t('Your blog item is not saved'));
$this->render('create');
}
}
示例5: action_add
public function action_add()
{
$method = Request::method();
if ($method == 'POST') {
// let's setup some rules for our new data
// I'm sure you can come up with better ones
$rules = array('title' => 'required|min:3|max:128', 'content' => 'required', 'file' => 'mimes:jpg,gif,png');
//
//Input::upload('picture', 'path/to/pictures', 'filename.ext');
//File::cpdir($directory, $destination);
//File::rmdir($directory);
//echo File::mime('gif'); // outputs 'image/gif'
//if (File::is('jpg', 'path/to/file.jpg'))
//{
//File::extension('picture.png');File::delete('path/to/file');
//File::append('path/to/file', 'appended file content');
//}File::put('path/to/file', 'file contents');$contents = File::get('path/to/file');
// make the validator
// let's get the new post from the POST data
// this is much safer than using mass assignment
$image = Input::file();
$pictrue = '';
$title = Input::get('title');
$content = Input::get('content');
$description = Input::get('title');
if (empty($description)) {
$description = substr($content, 0, 120);
}
$author_id = Input::get('author_id');
$tags = Input::get('tags');
if (!empty($image['file']['name'])) {
$ext = File::extension($image['file']['name']);
//$image['file']['tmp_name']
Input::upload('file', path('public') . 'data', md5(date('YmdHis') . $image['file']['name']) . '.' . $ext);
$pictrue = md5(date('YmdHis') . $image['file']['name']) . '.' . $ext;
}
$new_blog = array('title' => $title, 'description' => $description, 'content' => $content, 'author_id' => $author_id, 'views' => 0, 'pictrue' => $pictrue, 'tags' => $tags);
$v = Validator::make($new_blog, $rules);
if ($v->fails()) {
// redirect back to the form with
// errors, input and our currently
// logged in user
return Redirect::to('blog/add')->with('user', Auth::user())->with_errors($v)->with_input();
}
// create the new post
$blog = new Blog($new_blog);
$blog->save();
// redirect to viewing our new post
return Redirect::to('blog/view/' . $blog->id);
} else {
// get the current user
$user = Auth::user();
// show the create post form, and send
// the current user to identify the post author
return View::make('blog.add')->with('user', $user);
}
}
示例6: actionCreate
/**
* Создает новую модель блога.
* Если создание прошло успешно - перенаправляет на просмотр.
*
* @return nothing
**/
public function actionCreate()
{
$model = new Blog();
if (Yii::app()->getRequest()->getIsPostRequest() && Yii::app()->getRequest()->getPost('Blog') !== null) {
$model->setAttributes(Yii::app()->getRequest()->getPost('Blog'));
if ($model->save()) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('BlogModule.blog', 'Blog was added!'));
$this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', array('create')));
}
}
$this->render('create', array('model' => $model));
}
示例7: register
public function register()
{
$blog = new Blog(_post('blog'));
$blog->trim();
if (!$blog->validate_register()) {
$this->flash->add('message_error', $blog->errors->get_messages());
$this->back();
}
$blog->user_id = User::get_login_id();
$blog->save();
$this->redirect_to('/blog/index');
}
示例8: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Blog();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Blog'])) {
$model->attributes = $_POST['Blog'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例9: translate
public function translate($translator, $title, $text, $language)
{
$translation = new Blog($title, $translator, $text, $language, $this->datePosted);
if (!$this->parentID)
{
$translation->parentID = $this->ID;
$translation->parentLanguage = $this->language;
}
else
{
$translation->parentID = $this->parentID;
$translation->parentLanguage = $this->parentLanguage;
}
$translation->save();
return $translation;
}
示例10: store
public function store()
{
$datas = Input::all();
$blog = new Blog();
if ($datas['title']) {
$blog->title = $datas['title'];
} else {
$blog->title = "Không tiêu đề";
}
$blog->content = $datas['content'];
$blog->user_id = Session::get('user')['id'];
$blog->privacy = $datas['privacy'];
$blog->save();
FEEntriesHelper::save($blog->id, FEEntriesHelper::getId("Blog"), $blog->user_id, $blog->privacy);
return Redirect::back();
}
示例11: executeAdd
public function executeAdd()
{
$this->redirectIf($this->getUser()->isAuthenticated(), 'ucp/index');
if ($this->getRequest()->getMethod() == sfRequest::POST) {
$blog = new Blog();
$blog->setMid($this->getRequestParameter('mid'));
$blog->setEmail($this->getRequestParameter('email'));
$blog->setName($this->getRequestParameter('name'));
$blog->setAuthor($this->getRequestParameter('author'));
$blog->setUrl($this->getRequestParameter('url'));
$blog->setFeed($this->getRequestParameter('feed'));
$blog->setFile(substr(md5(rand()), 0, 16));
$blog->save();
$this->blog = $blog;
return 'Done';
}
return $this->displayAddForm();
}
示例12: post
/**
* Register a new user
*
* @param Request $request
* @param string $params
* @return void
*/
protected static function post($request, $params)
{
try {
try {
User::find(array('username' => $request->get('username')));
static::response(array(), 409, 'User with this username already exists');
} catch (Exception $e) {
$user = new User(array('username' => $request->get('username'), 'password' => password_hash($request->get('password'), PASSWORD_BCRYPT), 'isAdmin' => false));
$user->save();
$blog = new Blog(array('userID' => $user->id, 'name' => $request->get('blogname')));
$blog->save();
$user->blog = $blog;
static::response($user, 201);
}
} catch (Exception $e) {
static::response(array(), 500, $e->getMessage());
}
}
示例13: doSave
/**
* Stores the object 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 Connection $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($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->aBlog !== null) {
if ($this->aBlog->isModified()) {
$affectedRows += $this->aBlog->save($con);
}
$this->setBlog($this->aBlog);
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = PostPeer::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 += PostPeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
if ($this->collPostTags !== null) {
foreach ($this->collPostTags as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例14: edit
private function edit(Blog $model)
{
if (isset($_POST['Blog']) && $_POST['Blog']) {
$model->attributes = $_POST['Blog'];
$image = CUploadedFile::getInstanceByName('upload');
$imageModel = new BlogImage();
$imageModel->image = $image;
if ($imageModel->save()) {
$model->featuredImage = $imageModel->id;
}
if ($model->save()) {
/** @var CWebUser $user */
$user = Yii::app()->user;
$user->setFlash('blog-created', $model->isNewRecord ? 'Post succesfully created' : 'Post updated');
$this->redirect(['blog/update', 'id' => $model->id, 'preview' => isset($_POST['preview'])]);
}
}
$this->render('edit', compact('model'));
}
示例15: doSave
/**
* Form for POST save the specified resource.
*
* @param int $id
* @return Response
*/
public function doSave()
{
$validator = Validator::make(Input::all(), Blog::$rules);
if ($validator->passes()) {
$id = Input::get('id');
if (isset($id) && $id > 0) {
$blog = Blog::find($id);
} else {
$blog = new Blog();
}
$blog->title = Input::get('title');
$blog->description = Input::get('description');
$blog->tags = Input::get('tags');
$blog->user_id = Auth::user()->id;
$blog->save();
return Redirect::route('blog-list')->with('message', 'Blog was changed successfully.');
} else {
return Redirect::route('blog-edit')->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
}
}