Closed gasserol closed 8 years ago
Hi @gasserol , thanks for your message. Tomorrow I will take a look what going wrong. A few questions:
Please let me know!
@gasserol are you sure you add the "imagemanager" module part in your config? Its required for using the imagepicker. Let me know if it fixed or still not working.
Hi noam148, thanks for your reply and sorry for my long answering time (due to other customer work):
First of all, I get the 404 error only in the modal, the normal [yoururl.com]/imagemanager is working fine. I'm working with the advanced template and my config files are the following: backend/config/main.php:
'modules' => [
'user' => [
// following line will restrict access to profile, recovery, registration and settings controllers from backend
//'as backend' => 'dektrium\user\filters\BackendFilter',
'admins' => ['admin'],
],
'rbac' => 'dektrium\rbac\RbacWebModule',
'imagemanager' => [
'class' => 'noam148\imagemanager\Module',
//add css files (to use in media manage selector iframe)
'cssFiles' => [
'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css',
],
],
],
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
],
/*'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
],*/
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-backend',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
'imagemanager' => [
'class' => 'noam148\imagemanager\components\ImageManagerGetPath',
//set media path (outside the web folder is possible)
'mediaPath' => 'media',
//if run the component from the frontend and you wan't to reach the file from the backend. Set the path (optional)
//'baseUrlPublishedMedia' => 'http://localhost/visioMarketing3/backend',
],
],
common/models/brand.php looks like:
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "brand".
*
* @property integer $id
* @property string $title
* @property string $description
* @property integer $logoid
*/
class Brand extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'brand';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['title'], 'required'],
[['description'], 'string'],
[['logoid'], 'integer'],
[['title'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'title' => Yii::t('app', 'Title'),
'description' => Yii::t('app', 'Description'),
'logoid' => Yii::t('app', 'Logoid'),
];
}
}
backend/views/brand/create looks like:
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Brand */
$this->title = Yii::t('app', 'Create Brand');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Brands'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="brand-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>
backend/views/brand/_form.php looks like:
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use noam148\imagemanager\Module;
/* @var $this yii\web\View */
/* @var $model common\models\Brand */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="brand-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'description')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'logoid')->widget(\noam148\imagemanager\components\ImageManagerInputWidget::className(), [
'aspectRatio' => (16/9), //set the aspect ratio
'showPreview' => true, //false to hide the preview
]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
and backend/controllers/BrandController.php looks like:
<?php
namespace backend\controllers;
use Yii;
use common\models\Brand;
use common\models\BrandSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* BrandController implements the CRUD actions for Brand model.
*/
class BrandController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Brand models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new BrandSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Brand model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Brand model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Brand();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing Brand model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Brand model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Brand model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Brand the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Brand::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
* Show all brands of this user
*
* @return string*
*/
public function actionShowbrands()
{
// return all customers in an array indexed by customer IDs
// SELECT * FROM `customer`
$query = Brand::find();
$brands = $query->orderBy('title')->all();
return $this->render('showbrands', [
'brands' => $brands,
]);
}
}
`
The 404 error shows when creating a new brand and clicking on the folder icon given from your module to pass over to imagemanager
Many thanks for your precious help, Oliver
Hi Gasserol, i've copy your code in a own envoirment but it seems that everything works okay here.
So maybe the url in the modal iframe is generate wrong.
Can you send me the src attribute url from the modal iframe on the create and the update page? See below:
body > div#modal-imagemanager > div.modal-dialog > div.modal-content > div.modal-body > iframe
H noam148,
the iframe src is :
<iframe src="/visioMarketing3/backend/web/index.php?r=imagemanager%2Fmanager?view-mode=iframe&input-id=brand-logoid&aspect-ratio=1.7777777777778&crop-view-mode=1"></iframe>
Here is an printscreen from my system.
Thanks for your help and time!
Thanks gasserol, can you send me also the iframe url on the update page?
Sorry, update iframe url is:
<iframe src="/visioMarketing3/backend/web/index.php?r=imagemanager%2Fmanager?view-mode=iframe&input-id=brand-logoid&aspect-ratio=1.7777777777778&crop-view-mode=1&image-id=9"></iframe>
I found a bug. When I disable enablePrettyUrl in the urlManager component I get the samen 404 error. Tomorrow I searching for a solution!
Hi @gasserol I found the issue, fix it and update the module. Can you get the last version and check the image picker works (don't forget clear the assets folder after updating te module)?
Hi @noam148, thanks a lot for your help, now it works perfectly. Excellent module! I will publish a small note to make you publicity on yii2 facebook group!
Thanks @gasserol for your feedback and help to find the bug! Let me know if you find someting else or if you got any suggestion for improvement.
Hi, thanks for this very good module. Unfortunately I have a small problem with image picker, using as in your description it gives a 404 page not found error on create action in a form when clicking on the folder icon to select an image. If I manually insert the picture id in the corresponding field in database, it shows the preview. Any idea where this is coming from? Many thanks for your help and best regards, Oliver