本文整理汇总了PHP中common\models\Product::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::load方法的具体用法?PHP Product::load怎么用?PHP Product::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Product
的用法示例。
在下文中一共展示了Product::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product(['scenario' => 'create']);
$model->date = date('Y-m-d H:i');
if ($model->load(Yii::$app->request->post())) {
$model->image = UploadedFile::getInstance($model, 'image');
$model->images = UploadedFile::getInstances($model, 'images');
if ($model->validate() && $model->save() && $model->image) {
// Working directory
$dir = Yii::getAlias('@frontend/web/uploads/product/' . $model->id);
FileHelper::createDirectory($dir);
// Save main image
$model->image->saveAs($dir . '/main.jpg');
// Save images
if ($model->images) {
foreach ($model->images as $image) {
$imageModel = new Image();
$imageModel->model_id = $model->id;
$imageModel->save();
$image->saveAs($dir . '/' . $imageModel->id . '.jpg');
}
}
}
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', ['model' => $model]);
}
示例2: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product();
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 Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', 'Товар успешно создан!');
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例4: actionCreate
public function actionCreate()
{
$model = new Product();
if ($model->load(\Yii::$app->request->post())) {
if ($model->validate() && $model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('form', ['model' => $model]);
}
示例5: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$categories = Category::find()->all();
$model = new Product();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'categories' => $categories]);
}
}
示例6: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product();
$categoryModel = new CategoryProduct();
$treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all());
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model, 'treeParents' => $treeParents]);
}
}
示例7: insert
public function insert(ProductDto $productDto)
{
$product = new Product();
if ($product->load(['Product' => ArrayHelper::toArray($productDto)])) {
$product->type = ArrayUtil::arrayToInt($productDto->type);
$product->save();
return ArrayHelper::toArray($product);
} else {
return [];
}
}
示例8: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$currUser = Yii::$app->user->getIdentity();
$currMb = MerchantBrand::find()->where(['merchant_brand_id' => $currUser->username])->one();
$mbFk = $currMb->_id;
$model = new Product();
$model->merchant_brand_fk = $mbFk;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => (string) $model->_id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例9: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
//if(!Yii::$app->user->can('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
$model = new Product();
$model->loadDefaultValues();
if ($model->load(Yii::$app->request->post())) {
$model->type = ProductType::arrayToInt($model->type);
if ($model->save()) {
return $this->redirect(['update', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model]);
}
示例10: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product();
if (!is_numeric($model['agreement_id'])) {
$agreement = Agreement::find()->where(["default_flag" => 1])->asArray()->one();
$model['agreement_id'] = $agreement['id'];
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$redirect = yii::$app->request->post('goto') == 'list' ? ['index'] : ['update', 'id' => $model->id];
return $this->redirect($redirect);
}
return $this->render('create', ['model' => $model]);
}
示例11: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product();
$categoryModel = new ProductCategory();
$companyModel = new ProductCompany();
$treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all());
$treeCompany = ArrayHelper::map($companyModel->findAll(['status' => 10]), 'id', 'title');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model, 'treeParents' => $treeParents, 'treeCompany' => $treeCompany]);
}
}
示例12: actionProducts
/**
* Экшен '/admin/catalog/products' - список товаров
* @return string
* @throws InvalidParamException
*/
public function actionProducts()
{
$filterModel = new Product();
$filterModel->scenario = 'search';
$filterModel->load(Yii::$app->request->get());
$dataProvider = $filterModel->search();
if ($filterModel->parents === 0) {
$category = new Category();
$category->title = 'Все товары';
} else {
$category = Category::findOne($filterModel->parents);
}
return $this->render('products', ['category' => $category, 'dataProvider' => $dataProvider, 'filterModel' => $filterModel]);
}
示例13: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product();
if ($model->load(Yii::$app->request->post())) {
$imageName = $model->product_name;
$path = Yii::getAlias('@common') . '/web/uploads/';
$model->file = UploadedFile::getInstance($model, 'file');
$model->file->saveAs($path . $imageName . '.' . $model->file->extension);
$model->product_main_picture = $path . $imageName . '.' . $model->file->extension;
$model->admin_id = Yii::$app->user->getId();
$model->product_created_date = date('Y-m-d');
$model->save();
return $this->redirect(['view', 'id' => $model->product_id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例14: actionCreate
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product();
$parents = [];
$root = Category::findOne(['parent_id' => null, 'title' => 'product', 'module' => 'product']);
if (empty($root)) {
throw new NotFoundHttpException('Module không tồn tại');
}
$parents = $root->children()->all();
$parent_id = $this->buildTree($parents);
if ($model->load(Yii::$app->request->post())) {
$model['slug'] = $this->slugAlias($model);
if ($model->save()) {
return $this->redirect(['index']);
}
} else {
return $this->render('create', ['model' => $model, 'parent_id' => $parent_id, 'statestock' => $this->getStateStock(), 'hotline' => $this->getHotline(), 'state' => $this->getStatus()]);
}
}
示例15: actionCreate
/**
* Creates a new EntpProduct model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Product();
if ($model->load(Yii::$app->request->post())) {
$model->loadDefaultValues();
$model->save();
if ($model->save()) {
$produk = new EntpProduct();
$produk->product_id = $this->id;
$produk->entrepreneur_user_id = Yii::$app->user->id;
$produk->link('product', $model);
}
Yii::$app->session->setFlash('success', 'Create New Product Success');
return $this->redirect(['index']);
//return $this->redirect(['view', 'entrepreneur_id' => $model->entrepreneur_id, 'product_id' => $model->product_id]);
} else {
return $this->render('create', ['model' => $model]);
}
}