本文整理汇总了PHP中app\models\News::load方法的典型用法代码示例。如果您正苦于以下问题:PHP News::load方法的具体用法?PHP News::load怎么用?PHP News::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\News
的用法示例。
在下文中一共展示了News::load方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
if (!\Yii::$app->user->isGuest) {
$model = new News();
$max = NewsSearch::find()->select('max(id_new)')->scalar() + 1;
if ($model->load(Yii::$app->request->post())) {
if ($model->file = UploadedFile::getInstance($model, 'file')) {
$model->file->saveAs('images/new-' . $max . '.' . $model->file->extension);
$model->smallimg_new = '/images/new-' . $max . '.' . $model->file->extension;
}
$model->save();
return $this->redirect(['view', 'id' => $model->id_new]);
} else {
return $this->render('create', ['model' => $model]);
}
}
$model = new LoginForm();
if ($model->load(\Yii::$app->request->post()) && $model->login()) {
$searchModel = new NewsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
} else {
return $this->render('login', ['model' => $model]);
}
}
示例2: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
$loaded = $model->load(Yii::$app->request->post());
if ($loaded) {
if ($model->is_published) {
$model->published = date('Y-m-d H:i:s');
}
}
if ($loaded && $model->save()) {
$model->upload();
$category_relations = $_POST['News']['categories'];
foreach ($category_relations as $cat_id) {
$category_relation = new CategoryRelations();
$category_relation->news_id = $model->id;
$category_relation->category_id = $cat_id;
$category_relation->save();
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
$categories_arr = Category::find()->asArray()->all();
foreach ($categories_arr as &$cat) {
$categories[$cat['id']] = $cat['name'];
}
$model->is_published = 1;
return $this->render('create', compact('model', 'categories'));
}
}
示例3: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post())) {
$model->load($_POST);
//Дата создания
$model->date = date('Y-m-d');
$model->file = UploadedFile::getInstance($model, 'file');
$filename = Yii::$app->security->generateRandomString() . '.' . $model->file->extension;
$model->img = $filename;
$model->file->saveAs(Yii::getAlias('@app') . '/web/img/' . $filename);
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例4: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例5: actionSuggest
public function actionSuggest()
{
$model = new News(['status' => News::STATUS_DRAFT, 'scenario' => News::SCENARIO_SUGGEST]);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('news.news_successfully_added');
return $this->redirect(['index']);
}
return $this->render('suggest', ['model' => $model]);
}
示例6: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return Json::encode(['success' => true, 'message' => 'Created!']);
} else {
return Json::encode(['success' => false, 'content' => $this->renderPartial('_form', ['model' => $model])]);
}
}
示例7: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post())) {
$model->addedat = date("Y-m-d H:i:s");
$model->addedby = Yii::$app->user->identity->username;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例8: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post())) {
if ($model->imageFile = UploadedFile::getInstance($model, 'imageFile')) {
$model->upload();
}
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model]);
}
示例9: actionCreate
public function actionCreate()
{
$model = new News();
$login = new login();
$imgLoad = new imgLoad();
if (Yii::$app->user->identity->level > 1) {
if ($model->load(Yii::$app->request->post()) && $model->create()) {
if ($imgLoad->load(Yii::$app->request->post())) {
if ($imgLoad->file = UploadedFile::getInstance($imgLoad, 'file')) {
$imgLoad->img_load($model->id);
$model->save_id_img($imgLoad->id);
}
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['login' => $login, 'model' => $model, 'imgLoad' => $imgLoad]);
}
}
}
示例10: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post())) {
$model->url = UrlHelp::translateUrl($model->name);
if ($model->validate()) {
$model->imageFile = UploadedFile::getInstance($model, 'imageFile');
if ($model->imageFile) {
if ($imgName = $model->upload($model->url)) {
$model->img = $imgName;
}
}
$model->imageFile = null;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model]);
}
示例11: actionCreate
public function actionCreate()
{
$model = new News();
// автоматически сохраняем id автора
$model->author_id = Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post())) {
$model->file = \yii\web\UploadedFile::getInstance($model, 'file');
if ($model->file) {
$imagePath = 'uploads/';
$model->image = $imagePath . $model->file->name;
}
if ($model->save()) {
if ($model->file) {
$model->file->saveAs($model->image);
}
// отправляем письмо модератору с ссылкой на новую статью
Yii::$app->mailer->compose()->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' Отправлено роботом'])->setTo('galina-sil55@yandex.ru')->setTextBody('Ссылка: http://localhost' . Yii::$app->request->BaseUrl . '/news/' . $model->id)->setSubject('Новая статья')->send();
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model]);
}
}