В ЧЕМ ПРОБЛЕМА!? УЖЕ второй день не могу понять, вроде все верно..
МОДЕЛЬ:
namespace app\models;
use Yii;
use app\models\ArticleFile;
/**
* This is the model class for table "article".
*
* @property int $id
* @property string $title
* @property string $desc
* @property string $text
* @property string $date
* @property int $category_id
* @property int $status
*
* @property Comment[] $comments
*/
class Article extends \yii\db\ActiveRecord
{
public $imageFile;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'article';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['desc', 'text'], 'string'],
[['date'], 'safe'],
[['category_id', 'status'], 'integer'],
[['title'], 'string', 'max' => 255],
[['imageFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'jpg'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Title',
'desc' => 'Desc',
'text' => 'Text',
'date' => 'Date',
'category_id' => 'Category ID',
'status' => 'Status',
'imageFile' => 'Photos',
];
}
public function upload()
{
if ($this->validate()) {
$this->imageFile->saveAs('2018/allim/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
return true;
} else {
return false;
}
}
/**
* @return \yii\db\ActiveQuery
*/
public function getComments()
{
return $this->hasMany(Comment::className(), ['article_id' => 'id']);
}
}
VIEW
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model app\models\Article */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="article-form">
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'desc')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'text')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'date')->textInput() ?>
<?= $form->field($model, 'category_id')->textInput() ?>
<?= $form->field($model, 'status')->textInput() ?>
<?= $form->field($model, 'imageFile')->fileInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
CONTROLLER:
public function actionCreate()
{
$model = new Article();
if ($model->load(Yii::$app->request->post())) {
$model->imageFile = UploadedFile::getInstance($model, 'imageFile');
if ($model->upload() && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', [
'model' => $model,
]);
}
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Виртуальный выделенный сервер (VDS) становится отличным выбором
Надо найти находится ли объект в поле зренияДля этого можно его вписать в сферу и остаётся только узнать видна ли сфера
Попытки повторить аналог поведения __attribute__ ((alias ("realfunc"))) из GCC в MSVS/MSVC успехом не закончилисьЧто не так? и есть ли решения на базе pragma, macro?