本文整理汇总了PHP中app\models\Article::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::load方法的具体用法?PHP Article::load怎么用?PHP Article::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Article
的用法示例。
在下文中一共展示了Article::load方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
if ($model->load(Yii::$app->request->post())) {
$photo = UploadedFile::getInstances($model, 'photo');
$images = UploadedFile::getInstances($model, 'images');
$model->url = $this->SlugHelperUrl($model->title);
$model->created = date('Y-m-d H:i:s');
if ($photo) {
$photo[0]->saveAs('web/upload/article/' . Yii::$app->user->identity->id . '_' . time() . '.' . $photo[0]->extension);
$model->photo = Yii::$app->user->identity->id . '_' . time() . '.' . $photo[0]->extension;
} else {
Yii::trace($photo->errors);
}
if ($images) {
$images[0]->saveAs('web/upload/article/' . Yii::$app->user->identity->id . '_' . time() . '.' . $images[0]->extension);
$model->images = Yii::$app->user->identity->id . '_im' . time() . '.' . $images[0]->extension;
} else {
Yii::trace($photo->errors);
}
if ($model->photo != '' && !file_exists(__DIR__ . '/../../../web/upload/300_174/300_174_' . $model->photo) && file_exists(__DIR__ . '/../../../web/upload/article/' . $model->photo)) {
$thumb = new Imagick(__DIR__ . '/../../../web/upload/article/' . $model->photo);
$thumb->resizeImage(300, 174, Imagick::FILTER_LANCZOS, 1);
$thumb->writeImage(__DIR__ . '/../../../web/upload/300_174/300_174_' . $model->photo);
$thumb->destroy();
}
$model->save();
return $this->redirect(['update', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例2: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例3: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$this->layout = 'admin';
$model = new Article();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['browse']);
} else {
return $this->render('create', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all()]);
}
}
示例4: actionUpdate
public function actionUpdate($id = null)
{
$model = new Article();
if ($model->load(Yii::$app->request->post())) {
$request = Yii::$app->request->post('Article');
$id = $request['id'];
if ($id) {
$model = Article::findOne($id);
$model->attributes = $request;
}
if ($model->save()) {
$this->updateOrder('cid=' . $model->cid, '&langs=' . $model->langs);
$files = \yii\web\UploadedFile::getInstances($model, 'upload_files');
if (isset($files) && count($files) > 0) {
$mPath = \Yii::getAlias('@webroot') . '/images/article/news_' . $model->id;
if (!is_dir($mPath)) {
\yii\helpers\BaseFileHelper::createDirectory($mPath);
}
foreach ($files as $file) {
if ($request['cid'] == '12') {
$mPic = $file->baseName . '.' . $file->extension;
} else {
$mPic = 'nkc_' . substr(number_format(time() * rand(), 0, '', ''), 0, 14) . '.' . $file->extension;
}
//Upload Images
if ($file->saveAs($mPath . '/' . $mPic)) {
$image = \Yii::$app->image->load($mPath . '/' . $mPic);
$image->resize(1024, 1024);
$image->save($mPath . '/' . $mPic);
//resize images thumb
$image = \Yii::$app->image->load($mPath . '/' . $mPic);
$image->resize(250, 250);
$mThumb = $mPath . '/thumb/';
if (!is_dir($mThumb)) {
\yii\helpers\BaseFileHelper::createDirectory($mThumb);
}
$image->save($mThumb . $mPic);
}
}
}
return $this->redirect(array('index'));
} else {
print_r($model->getErrors());
exit;
}
}
if ($id) {
$model = Article::findOne($id);
} else {
$sess = Yii::$app->session->get('sessArticle');
$model->langs = $sess['langs'];
$model->cid = $sess['cid'];
}
return $this->render('update', ['model' => $model]);
}
示例5: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
$tourtype = new Tourtype();
$small = new FileUpload();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'tourtype' => $tourtype, 'small' => $small]);
}
}
示例6: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
if ($model->load(Yii::$app->request->post())) {
$model->preview_input = UploadedFile::getInstance($model, 'preview_input');
if (!empty($model->preview_input)) {
$model->preview_picture = 'preview/' . $model->preview_input->baseName . '.' . $model->preview_input->extension;
}
if ($model->save()) {
Yii::warning("Article changed. Attributes = " . print_r($model->attributes));
return $this->redirect(['index']);
}
}
return $this->render('create', ['model' => $model]);
}
示例7: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
$uploader = new Uploader();
if (Yii::$app->request->isPost) {
$uploader->imageFile = UploadedFile::getInstance($uploader, 'imageFile');
$model->user_id = Yii::$app->user->identity->id;
$model->date = date("Y-m-d H:i:s");
$model->image_tag = $uploader->imageFile->basename;
$model->image_extension = $uploader->imageFile->extension;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($uploader->upload($model->id)) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
}
return $this->render('create', ['model' => $model]);
}
示例8: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
$model->user_id = Yii::$app->user->id;
if (Yii::$app->user->can('createArticle', ['model' => $model])) {
// Check permission before process acction
if ($model->load(Yii::$app->request->post())) {
$this->Uploads(false);
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
$model->ref = substr(Yii::$app->getSecurity()->generateRandomString(), 10);
}
return $this->render('create', ['model' => $model]);
} else {
throw new ForbiddenHttpException('ขอแสดงความเสียใจอย่างสุดซื้ง!, คุณไม่ได้รับอนุญาตให้เข้าใช้งาน');
}
/*if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$model->thumbnail = $model->uploadThumbnail($model,'thumbnail');
$model->photos = $model->uploadMultipleImg($model,'photos');
$model->files = $model->uploadMultipleFiles($model,'files');
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}*/
/*
if ($model->load(Yii::$app->request->post()) && $model->save())
{
return $this->redirect(['view', 'id' => $model->id]);
}
else
{
return $this->render('create', [
'model' => $model,
]);
}
*/
}
示例9: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
if ($model->load(Yii::$app->request->post())) {
$categories = new ArticleCategories();
$model->psychologist_id = Yii::$app->user->id;
$model->is_owner = 1;
if ($model->save()) {
$articleCategories = Yii::$app->request->post('categories');
if ($categories->saveArticleCategories($model->id, $articleCategories)) {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model, 'articleCategories' => ArticleCategories::find()->all()]);
}
/*if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}*/
} else {
return $this->render('create', ['model' => $model, 'articleCategories' => ArticleCategories::find()->all()]);
}
}