yii2 imperavi widget settings in config file - yii2

How to set yii2-imperavi-widget (vova07) settings in config/web.php? In 'components' or in 'modules' array?
try in 'components':
'imperavi' => [
'class' => 'vova07\imperavi\Widget',
'settings' => [
'lang' => 'ru',
'removeWithoutAttr' => [],
'minHeight' => 300,
'pastePlainText' => true,
'buttonSource' => true,
'replaceDivs' => false,
'plugins' => [
'clips',
'fullscreen',
'fontfamily',
'fontsize',
'fontcolor',
'video',
'table'
],
],
],
doesn't work.

Related

Yii2 advanced - enable pretty URL in module

I am learning how modules work in Yii2 and now I created the following module: gdpr. I can access the following route: /index.php?r=gdpr/user/index. However, I want to access the route like this: /gdpr/user/index. How can I achieve that?
config.php:
<?php
return [
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'modules\gdpr\default'],
['class' => 'yii\rest\UrlRule', 'controller' => 'modules\gdpr\user'],
],
],
],
'params' => [
// list of parameters
],
];
You need to configure controllers in this way:
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => ['gdpr/default', 'gdpr/user'],
],
],
],
],
See https://www.yiiframework.com/doc/api/2.0/yii-rest-urlrule#$controller-detail

RBAC Routes add default route of module to all the routes of project?

If I add this configuration of the cms module to the config file
'cms' => [
'class' => 'yii2mod\cms\Module',
'controllerNamespace' => 'backend\controllers',
'defaultRoute' => '',
'froalaEditorOptions' => [
'clientOptions' => [
'heightMin' => 300,
'theme' => 'dark',
'imageUploadURL' => 'upload-image',
'imageManagerDeleteURL' => 'delete-image',
'imageManagerDeleteMethod' => 'POST',
'imageManagerLoadURL' => 'images'
],
'excludedPlugins' => [
'file',
'emoticons'
]
],
'enableMarkdown' => false
]
It adds the default route of this module to all the routes like this
/cms/site/login /cms/site/index /cms/site/error. Why this is happening and how i can remove this?
If you want to remove the /cms module prefix by default, you can add a global route to backend/config/main.php(If you use advanced templates): '<controller:[\w-]+>/<action:[\w-]+>' =>'cms/<controller>/<action>'.
for example:
// backend/config/main.php
return [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:[\w-]+>/<action:[\w-]+>' =>'cms/<controller>/<action>'
],
],
];
Access in your bowser: www.xxx.com/site/index, it is forwarded to: /cms/site/index

Codeception Object configuration must be an array

I am trying to run basic codeception test but what I get is the error bellow:
Backend\tests.functional Tests (1) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
E LoginCest: Login user (0.01s)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1) LoginCest: Login user
Test tests/functional/LoginCest.php:loginUser
[yii\base\InvalidConfigException] Object configuration must be an array containing a "class" element.
Scenario Steps:
1. $I->amOnPage("/admin/user/login") at tests/functional/LoginCest.php:18
#1 /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/BaseYii.php:353
#2 /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/base/Module.php:427
#3 /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/base/Module.php:586
#4 /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/base/Module.php:522
#5 /home/projects/toma/toma-coreshop/vendor/yiisoft/yii2/web/Application.php:103
#6 /home/projects/toma/toma-coreshop/vendor/symfony/browser-kit/Client.php:351
#7 Codeception\Lib\InnerBrowser->amOnPage
#8 /home/projects/toma/toma-coreshop/backend/tests/_support/_generated/FunctionalTesterActions.php:526
#9 /home/projects/toma/toma-coreshop/backend/tests/functional/LoginCest.php:18
#10 backend\tests\functional\LoginCest->loginUser
Time: 251 ms, Memory: 16.00MB
There was 1 error:
---------
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
The errors flows one by one on every step whit those tests. My configuration file looks like (backend\codeception.yml):
namespace: backend\tests
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
modules:
config:
Yii2:
configFile: 'config/test.php'
In my test.php I have:
<?php
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/main.php'),
require(__DIR__ . '/main-local.php'),
[
'id' => 'app-backend-test',
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=coreshop',
'username' => '*****',
'password' => '*****',
'charset' => 'utf8',
//'enableSchemaCache' => true,
],
]
]
);
return $config;
And finally my LoginCest.php:
/**
* Class LoginCest
*/
class LoginCest
{
/**
* #param FunctionalTester $I
*/
public function loginUser(FunctionalTester $I)
{
$I->amOnPage('/admin/user/login');
$I->fillField('Username', '***');
$I->fillField('Password', '***');
$I->click('Вход');
}
}
I followed the instruction given on the codeception site for the Yii2-advanced template. I am trying to test on old project so it is not newly installed Yii2-advanced if that matters in this case. Thank you!
EDIT
Main.php:
$params = array_merge(
require(__DIR__ . '/../../common/config/params.php'),
require(__DIR__ . '/../../common/config/params-local.php'),
require(__DIR__ . '/params.php'),
require(__DIR__ . '/params-local.php')
);
return [
'id' => 'app-backend',
'name' => 'Online Shop Admin',
'homeUrl' => '/admin',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'language' => 'bg-BG',
'bootstrap' => [
[
'class' => 'app\components\LanguageSelector',
'supportedLanguages' => [],
],
'log',
'devicedetect'
],
'modules' => [
'user' => [
'controllerMap' => [
'security' => 'backend\controllers\user\SecurityController',
'admin' => 'backend\controllers\user\AdminController',
],
'modelMap' => [
'User' => 'backend\models\User',
'SettingsForm' => 'backend\models\SettingsForm',
'Profile' => 'backend\models\Profile',
/*'UserSearch' => 'backend\models\UserSearch',*/
],
'rememberFor' => 1209600,
],
'statistics' => [
'class' => 'backend\modules\statistics\Module',
],
'catalogue' => [
'class' => 'backend\modules\catalogue\Module',
],
'news' => [
'class' => 'backend\modules\news\Module',
],
'sales' => [
'class' => 'backend\modules\sales\Module',
],
'wasteManagment' => [
'class' => 'backend\modules\wasteManagment\WasteManagment',
],
'help' => [
'class' => 'backend\modules\help\HelpInfo',
],
'marketing' => [
'class' => 'backend\modules\marketing\Module',
],
'translation' => [
'class' => 'backend\modules\translation\Module',
],
'gii' => [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.33.1'], // adjust this to your needs
'generators' => [
'crud' => [
'class' => 'backend\templates\crud_v1\Generator',
'templates' => ['mycrud' => '#backend/templates/crud_v1/default']
],
'model' => [
'class' => 'backend\templates\model_v1\Generator',
'templates' => ['mymodel' => '#backend/templates/model_v1/default']
],
/*'crud' => [
'class' => 'backend\templates\crud_module_v1\Generator',
'templates' => ['mycrudmodule' => '#backend/templates/crud_module_v1/default']
],
'model' => [
'class' => 'backend\templates\model_module_v1\Generator',
'templates' => ['mymodelmodule' => '#backend/templates/model_module_v1/default']
],*/
],
],
],
'components' => [
'assetManager' => [
'bundles' => [
'yii\bootstrap\BootstrapAsset' => [
'css' => [],
],
'yii\bootstrap\BootstrapPluginAsset' => [
'js' => []
],
'yii\web\JqueryAsset' => [
'js' => []
],
'wbraganca\dynamicform\DynamicFormAsset' => [
'js' => [
'/admin/dist/js/yii2-dynamic-form.js'
]
],
],
],
'urlManagerBackend' => [
'class' => 'yii\web\urlManager',
'baseUrl' => (isset($_SERVER['HTTPS']) ? "https" : 'http') . "://toma-coreshop.webbuild.com/admin",
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'request' => [
'baseUrl' => '/admin',
'cookieValidationKey' => 'sew4789vb7834tvnv78',
'csrfParam' => '_backendCSRF',
],
'user' => [
'identityClass' => 'backend\models\User',
'enableAutoLogin' => true,
'loginUrl' => [ 'user/login'],
'identityCookie' => [
'name' => '_backendUser', // unique for backend
]
],
/*'session' => [
'name' => '_backendSessionId',
'savePath' => __DIR__ . '/../runtime/sessions',
],*/
'view' => [
'theme' => [
'pathMap' => [
'#dektrium/user/views' => '#backend/views/user',
'#dektrium/rbac/views' => '#backend/views/rbac',
],
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
],
'translate' => [
'class' => 'backend\components\Translate'
],
'tabSettings' => [
'class' => 'backend\components\TabSettings'
],
'system' => [
'class' => 'backend\components\System'
],
'moneyConvertor' => [
'class' => 'backend\components\MoneyConvertor'
],
'moneyWords' => [
'class' => 'backend\components\MoneyWords'
],
'OutData' => [
'class' => 'backend\components\OutData'
],
'MakeURL' => [
'class' => 'backend\components\MakeURL'
],
'makeUrl' => [
'class' => 'frontend\components\MakeURL'
],
'image' => [
'class' => 'backend\components\Image'
],
'formatter' => [
'class' => 'yii\i18n\Formatter',
'nullDisplay' => '',
],
'devicedetect' => [
'class' => 'alexandernst\devicedetect\DeviceDetect'
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'profile' => 'user/settings/profile',
],
],
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/messages',
'sourceLanguage' => 'bg',
'fileMap' => [
'app' => 'app.php',
],
],
'help*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/modules/help/messages',
'sourceLanguage' => 'bg',
'fileMap' => [
'help' => 'help.php',
],
],
'sales*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/modules/sales/messages',
'sourceLanguage' => 'bg',
'fileMap' => [
'catalogue' => 'sales.php',
],
],
'statistics*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/modules/statistics/messages',
'sourceLanguage' => 'bg',
'fileMap' => [
'catalogue' => 'statistics.php',
],
],
'catalogue*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/modules/catalogue/messages',
'sourceLanguage' => 'bg',
'fileMap' => [
'catalogue' => 'catalogue.php',
],
],
'marketing*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/modules/marketing/messages',
'sourceLanguage' => 'bg',
'fileMap' => [
'catalogue' => 'news.php',
],
],
'news*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/modules/news/messages',
'sourceLanguage' => 'bg',
'fileMap' => [
'catalogue' => 'news.php',
],
],
'message*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/modules/translation/messages',
'sourceLanguage' => 'bg',
'fileMap' => [
'message' => 'message.php',
],
],
'kvgrid*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/messages/kvgrid',
'sourceLanguage' => 'bg',
'fileMap' => [
'kvgrid' => 'kvgrid.php',
],
],
],
],
],
'params' => $params,
];
Main-local.php:
$config = [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'ud_6581BcmdaOC-RoK4LznBhsD7W4pyU',
],
],
'container' => [
'definitions' => [
kartik\grid\GridView::class => [
'krajeeDialogSettings' => ['overrideYiiConfirm' => false],
'responsiveWrap' => false,
'bordered' => false,
'tableOptions' => [
'class' => 'table full-color-table full-dark-table hover-table',
],
'resizableColumns' => true,
'hover' => true,
'layout' => "{items}\n{summary}\n{pager}",
'rowOptions' => function ($model) {
if(!empty($model->id))
return ['data-id' => $model->id];
else
return;
},
],
],
],
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['modules']['debug']['allowedIPs'] = ['*'];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
$config['modules']['gii']['allowedIPs'] = ['*'];
}
return $config;

Pretty URL in Yii2 LinkPager with custom params

I need LinkPager to create page URL like /site/page/1/job/2/order-price/3/order-exp/4/.
The route works fine with the URL manager, but LinkPager ignores this route and creates URL with ?foo=bar parameters.
$rules = [
'site/page/<page:\d+>/job/<job_id:\d+>/order-price/<min_price:\d+>/order-exp/<experience:\d+>/' => 'site/index'
];
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'suffix' => '/',
'rules' => $rules,
],
]
$pagination = [
'pageSize' => 1,
'forcePageParam' => true,
'pageSizeParam' => false,
'params' => [
'page' => $this->page,
'job' => $this->job_id,
'order-price' => $this->min_price,
'order-exp' => $this->experience
],
];
You're using incorrect parameters names. If your pattern is site/page/<page:\d+>/job/<job_id:\d+>/order-price/<min_price:\d+>/order-exp/<experience:\d+>/ then parameter names are:
page,
job_id,
min_price,
experience.
You should either change your rule to:
site/page/<page:\d+>/job/<job:\d+>/order-price/<order-price:\d+>/order-exp/<order-exp:\d+>/
Or adjust param names in pagination config:
[
'pageSize' => 1,
'forcePageParam' => true,
'pageSizeParam' => false,
'params' => [
'page' => $this->page,
'job_id' => $this->job_id,
'min_price' => $this->min_price,
'experience' => $this->experience,
],
];

PendalF89/yii2-filemanager upload error. (Call to a member function saveAs() on null)

getting
Call to a member function saveAs() on null
error from ajax request while uploading image via filemanager.
Config:
...
'modules' => [
'site' => [
'class' => 'app\modules\site\Module',
],
'user' => [
'class' => 'app\modules\user\Module',
'controllerNamespace' => 'app\modules\user\controllers\frontend',
'viewPath' => '#app/modules/user/views/frontend',
],
'admin' => [
'class' => 'app\modules\admin\Module',
'layout' => '#app/views/layouts/admin',
'modules' => [
'user' => [
'class' => 'app\modules\user\Module',
'controllerNamespace' => 'app\modules\user\controllers\backend',
'viewPath' => '#app/modules/user/views/backend',
],
'pages' => [
'class' => 'bupy7\pages\Module',
'controllerNamespace' => 'bupy7\pages\controllers\backend',
'controllerMap' => [
'manager' => [
'class' => 'bupy7\pages\controllers\backend\ManagerController',
],
],
],
'gallery' => [
'class' => 'sadovojav\gallery\Module',
'basePath' => '#webroot/galleries',
],
'filemanager' => [
'class' => 'pendalf89\filemanager\Module',
// Upload routes
'routes' => [
// Base absolute path to web directory
'baseUrl' => '',
// Base web directory url
'basePath' => '#webroot',
// Path for uploaded files in web directory
'uploadPath' => 'uploads',
],
// Thumbnails info
'thumbs' => [
'small' => [
'name' => 'Small',
'size' => [100, 100],
],
'medium' => [
'name' => 'Medium',
'size' => [300, 200],
],
'large' => [
'name' => 'Big',
'size' => [500, 400],
],
],
],
],
],
...
actionUpload() in Controller
public function actionUpload()
{
$model = new Mediafile();
$routes = $this->module->routes;
$rename = $this->module->rename;
$model->saveUploadedFile($routes, $rename);
Yii::$app->response->format = Response::FORMAT_JSON;
$tagIds = Yii::$app->request->post('tagIds');
if ($tagIds !== 'undefined') {
$model->setTagIds(explode(',', $tagIds));
}
$bundle = FilemanagerAsset::register($this->view);
if ($model->isImage()) {
$model->createThumbs($routes, $this->module->thumbs);
}
$response['files'][] = [
'url' => $model->url,
'thumbnailUrl' => $model->getDefaultThumbUrl($bundle->baseUrl),
'name' => $model->filename,
'type' => $model->type,
'size' => $model->file->size,
'deleteUrl' => Url::to(['file/delete', 'id' => $model->id]),
'deleteType' => 'POST',
];
return $response;
}
Checked in the model,
$this->file = UploadedFile::getInstance($this, 'file');
in saveUploadedFile() returns null instead of object.
The problem is that the function saveUploadedFile() is been executed, the file is saved and the record is created in the database, but it returns error.