本文整理匯總了PHP中News::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP News::save方法的具體用法?PHP News::save怎麽用?PHP News::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類News
的用法示例。
在下文中一共展示了News::save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: admin_news_create
function admin_news_create()
{
if (isset($_REQUEST['create'])) {
$news = new News();
$news->title = $_REQUEST['title'];
$news->content = $_REQUEST['content'];
$news->tags = $_REQUEST['tags'];
$news->protected = $_REQUEST['protected'];
$news->custom_sidebar = $_POST['custom_sidebar'];
if ($_POST['start_date_check'] == 1) {
$news->start_date = strtotime($_POST['start_date']['year'] . "-" . $_POST['start_date']['month'] . "-" . $_POST['start_date']['day'] . " " . str_pad($_POST['start_date']['hour'], 2, "0", STR_PAD_LEFT) . ":" . str_pad($_POST['start_date']['minute'], 2, "0", STR_PAD_LEFT) . "" . $_POST['start_date']['meridiem']);
} else {
$news->start_date = 0;
}
if ($_POST['end_date_check'] == 1) {
$news->end_date = strtotime($_POST['end_date']['year'] . "-" . $_POST['end_date']['month'] . "-" . $_POST['end_date']['day'] . " " . str_pad($_POST['end_date']['hour'], 2, "0", STR_PAD_LEFT) . ":" . str_pad($_POST['end_date']['minute'], 2, "0", STR_PAD_LEFT) . "" . $_POST['end_date']['meridiem']);
} else {
$news->end_date = 0;
}
$news->save();
$news->created_on = date("Y-m-d H:i:s", strtotime($_POST['created_on']['year'] . "-" . $_POST['created_on']['month'] . "-" . $_POST['created_on']['day'] . " " . str_pad($_POST['created_on']['hour'], 2, "0", STR_PAD_LEFT) . ":" . str_pad($_POST['created_on']['minute'], 2, "0", STR_PAD_LEFT) . "" . $_POST['created_on']['meridiem']));
$news->save();
render('news_list');
return true;
}
render();
}
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'update' page.
*/
public function actionCreate()
{
$model = new News();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
// set attributes from get
if (isset($_GET['News'])) {
$model->attributes = $_GET['News'];
}
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
if (isset($_FILES)) {
$model->image = "jpeg";
}
if ($model->save()) {
if (isset($_FILES)) {
move_uploaded_file($_FILES["images"]["tmp_name"], Yii::getPathOfAlias('webroot') . "/../uploads/filestorage/news/elements/" . $model->id . '.jpeg');
$this->chgImg(Yii::getPathOfAlias('webroot') . "/../uploads/filestorage/news/elements/", $model->id . '.jpeg', "small-" . $model->id . '.jpeg');
}
$url = isset($_POST['go_to_list']) ? $this->listUrl('index') : $this->itemUrl('update', $model->id);
$this->redirect($url);
}
}
$this->render('create', array('model' => $model));
}
示例3: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate($idTree)
{
$modelTree = Tree::model()->find('id=:id AND module=:module AND organization=:organization', array(':id' => $idTree, ':module' => 'news', ':organization' => Yii::app()->session['code_no']));
if ($modelTree === null) {
throw new CHttpException(404, 'Страница не найдена.');
}
if (!(Yii::app()->user->admin || Access::model()->checkAccessUserForTree($idTree))) {
throw new CHttpException(403, 'Доступ запрещен.');
}
$model = new News();
$model->id_tree = $idTree;
$model->flag_enable = true;
$model->date_start_pub = date('d.m.Y');
$model->date_end_pub = date('01.m.Y', PHP_INT_MAX);
$model->author = Yii::app()->user->name;
$model->general_page = 0;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
$model->log_change = LogChange::setLog($model->log_change, 'создание');
if ($model->save()) {
// сохраняем файлы
$model->saveFiles($model->id, $idTree);
// сохраняем изображения
$model->saveImages($model->id, $idTree);
// сохраняем миниатюра изображения
$model->saveThumbailForNews($model);
$this->redirect(array('view', 'id' => $model->id, 'idTree' => $idTree));
}
}
$this->render('create', array('model' => $model, 'idTree' => $idTree));
}
示例4: actionCreates
public function actionCreates()
{
$model = new News();
$file = new File();
$model->member_id = Yii::app()->user->id;
$model->create_at = date('Y-m-d H:i:s');
$model->update_at = date('Y-m-d H:i:s');
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['News']) && isset($_POST['File'])) {
$model->attributes = $_POST['News'];
$file->attributes = $_POST['File'];
$model->pic = 'noimage.jpg';
$model->validate();
$file->validate();
if ($model->getErrors() == null && $file->getErrors() == null) {
$file->file = CUploadedFile::getInstance($file, 'file');
if ($file->file != null) {
$filename = time() . '.' . $file->file->getExtensionName();
$file->file->saveAs(Yii::app()->params['pathUpload'] . $filename);
$model->pic = $filename;
} else {
$model->pic = 'noimage.jpg';
}
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->news_id));
}
}
}
$this->render('create', array('model' => $model, 'file' => $file));
}
示例5: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new News();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
if ($model->save()) {
if (!empty($model->img)) {
$photo = $model->img;
$img = Yii::app()->image->load($_SERVER['DOCUMENT_ROOT'] . '/userfiles/editor/images/' . $photo);
$pname = 'news_' . $model->id . '_' . $photo;
$img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/original/' . $pname);
$img->resize(600, 600);
$img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/large/' . $pname);
$img->resize(200, 200);
$img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/medium/' . $pname);
$img->resize(100, 100);
$img->save($_SERVER['DOCUMENT_ROOT'] . '/userfiles/small/' . $pname);
$model->img = $pname;
$model->update();
}
if (isset($_POST['savebutton'])) {
$this->redirect($this->createUrl('index', array('News_page' => $_GET['News_page'], 'msg' => '[!] Новость успешно создана', 'msgtype' => 'success')));
} else {
$this->redirect($this->createUrl('update', array('id' => $model->id, 'msg' => '[!] Новость успешно создана', 'msgtype' => 'success')));
}
} else {
$model->date = $model->viewDate();
}
}
$this->render('create', array('model' => $model));
}
示例6: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return void
*/
public function actionCreate()
{
$model = new News();
if (($data = Yii::app()->getRequest()->getPost('News')) !== null) {
$model->setAttributes($data);
if ($model->save()) {
Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('NewsModule.news', 'News article was created!'));
$this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create']));
}
}
$languages = $this->yupe->getLanguagesList();
//если добавляем перевод
$id = (int) Yii::app()->getRequest()->getQuery('id');
$lang = Yii::app()->getRequest()->getQuery('lang');
if (!empty($id) && !empty($lang)) {
$news = News::model()->findByPk($id);
if (null === $news) {
Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('NewsModule.news', 'Targeting news was not found!'));
$this->redirect(['/news/newsBackend/create']);
}
if (!array_key_exists($lang, $languages)) {
Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('NewsModule.news', 'Language was not found!'));
$this->redirect(['/news/newsBackend/create']);
}
Yii::app()->getUser()->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('NewsModule.news', 'You inserting translation for {lang} language', ['{lang}' => $languages[$lang]]));
$model->setAttributes(['lang' => $lang, 'slug' => $news->slug, 'date' => $news->date, 'category_id' => $news->category_id, 'title' => $news->title]);
} else {
$model->setAttributes(['date' => date('d-m-Y'), 'lang' => Yii::app()->getLanguage()]);
}
$this->render('create', ['model' => $model, 'languages' => $languages]);
}
示例7: add_news
public function add_news()
{
$this->_checkPermission();
$data = $_POST['news'];
Flash::set('postdata', $data);
$image = $_POST['upload'];
$path = str_replace('..', '', $image['path']);
$overwrite = false;
// verification
if (empty($data['title'])) {
Flash::set('error', __('You have to specify a news title!'));
redirect(get_url('news/create'));
}
// if (empty($data['url'])){
// Flash::set('error', __('You have to specify the URL!'));
// redirect(get_url('news/create'));
// }
if (isset($_FILES)) {
// no image file selected
if (empty($_FILES['upload_file']['name'])) {
Flash::set('error', __('You have to select a image to be uploaded!'));
redirect(get_url('news/create'));
}
} else {
Flash::set('error', __('You have to select a image to be uploaded!'));
redirect(get_url('news/create'));
}
$news = new News($data);
$news->created_by_id = AuthUser::getId();
$news->created_on = date('Y-m-d H:i:s');
if (!$news->save()) {
Flash::set('error', __('Promo is not added!'));
redirect(get_url('news/create'));
} else {
if (isset($_FILES)) {
$news_id = $news->lastInsertId();
$file = $this->upload_file($_FILES['upload_file']['name'], FILES_DIR . '/promo/images/', $_FILES['upload_file']['tmp_name'], $overwrite, $news_id);
if ($file === false) {
Flash::set('error', __('Promo image has not been uploaded!'));
}
//Add Image to database
$data = $_POST['news'];
Flash::set('post_data', (object) $data);
$news = Record::findByIdFrom('News', $news_id);
if (!$news->update('News', array('filename' => $file), 'id=' . $news_id)) {
Flash::set('error', __('Image has not been updated.'));
} else {
Flash::set('success', __('Promo has been updated!'));
if (isset($_POST['commit'])) {
redirect(get_url('news'));
} else {
redirect(get_url('news/view/' . $news->id));
}
}
}
Flash::set('success', __('Promo has been added!'));
}
redirect(get_url('news'));
}
示例8: actionAddRandomNews
public function actionAddRandomNews()
{
$news = new News();
$news->title = "Item #" . rand(1, 10000);
$news->created_on = time();
$news->save();
echo "OK";
}
示例9: addNew
static function addNew($titre, $image, $texte)
{
$new = new News();
$new->titre = $titre;
$new->image = "Vue/Image/" . $image;
$new->contenu = $texte;
$new->date = date("Y-m-d H:i:s");
$new->save();
}
示例10: actionAdd
protected function actionAdd()
{
$addart = new View('view/forms.php');
$addart->display();
if (isset($_POST['text']) && isset($_POST['title'])) {
$article = new News();
$article->title = $_POST['title'];
$article->text = $_POST['text'];
$article->save();
}
}
示例11: testUniqueTitle
public function testUniqueTitle()
{
$news = new News();
$news->title = 'News';
$news->body = 'FooBar';
$this->assertTrue($news->save());
$news = new News();
$news->body = 'Ananas';
$news->title = 'News';
$this->assertFalse($news->save());
}
示例12: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new News();
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
if ($model->save()) {
Yii::app()->user->setFlash('success', '創建成功');
$this->redirect(array('update', 'id' => $model->n_id));
}
}
$this->render('create', array('model' => $model));
}
示例13: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new News();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例14: run
public function run()
{
DB::table('news')->delete();
$user = User::all()->first();
$news = new News();
$news->title = "The first discount";
$news->description = "Neque molestiae nobis ex sint incidunt animi. Ipsa eum repellat quisquam quasi dolorem sapiente porro repellat. Praesentium non enim quod corrupti maxime impedit illum. Minus ea quo labore et. Quas quia laudantium fuga est. Nihil exercitationem nam incidunt rerum animi repellat. Sit sapiente temporibus voluptate in. Rerum consequatur non sed delectus pariatur harum accusantium sint. Repellendus explicabo sapiente itaque ipsum. Saepe ipsum assumenda voluptatem aut. Ut rerum enim qui facere. Et quod ipsam id amet. Error id molestiae aut ut sit ducimus.";
$news->save();
$news = new News();
$news->title = "The second discount";
$news->description = "Neque molestiae nobis ex sint incidunt animi. Ipsa eum repellat quisquam quasi dolorem sapiente porro repellat. Praesentium non enim quod corrupti maxime impedit illum. Minus ea quo labore et. Quas quia laudantium fuga est. Nihil exercitationem nam incidunt rerum animi repellat. Sit sapiente temporibus voluptate in. Rerum consequatur non sed delectus pariatur harum accusantium sint. Repellendus explicabo sapiente itaque ipsum. Saepe ipsum assumenda voluptatem aut. Ut rerum enim qui facere. Et quod ipsam id amet. Error id molestiae aut ut sit ducimus.";
$news->save();
}
示例15: create
/**
* @test
*/
public function create()
{
$model = News::model();
$this->assertInstanceOf('News', $model);
$model = new News();
$model->attributes = array('category_id' => 1, 'enabled' => true);
$this->assertFalse($model->save());
$model = new News();
$model->attributes = array('event_date' => '2013-08-21', 'category_id' => 1);
$this->assertFalse($model->save());
$model = new News();
$model->attributes = array('event_date' => '2013-08-21', 'category_id' => 1, 'enabled' => true);
$this->assertTrue($model->save());
}