Error installation extentions Reportico on Yii 2 - php

I installed the extension reportico through composer and already web.php configuration file, but when I go into Reportico Admin Page error instead. The solution how ?
enter image description here
scrip web.php
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'K1pkkP_iwACp933A03LotJ3AfRsyIb-D',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'reportico' => [
'class' => 'reportico\reportico\Module' ,
'controllerMap' => [
'reportico' => 'reportico\reportico\controllers\ReporticoController',
'mode' => 'reportico\reportico\controllers\ModeController',
'ajax' => 'reportico\reportico\controllers\AjaxController',
]
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;

Move reportico to components array:
'components' => [
//...
'reportico' => [
'class' => 'reportico\reportico\Module' ,
'controllerMap' => [
'reportico' => 'reportico\reportico\controllers\ReporticoController',
'mode' => 'reportico\reportico\controllers\ModeController',
'ajax' => 'reportico\reportico\controllers\AjaxController',
]
]
]

Related

Migration - Failed to instantiate component or class "db" in console Yii2

I am new to Yii2 and need to set up an existing project. I am at the stage where I would like to migrate tables to the database using the console. I have a database connection in Yii, everything in config is specified correctly. However, I get an error in the console when I try to migrate the tables:
Exception 'yiibaseInvalidConfigException' with message 'Failed to instantiate component or class "db".'
I have already searched Google and have not found a solution to this problem.
Here some code:
config/console.php
<?php
use kartik\mpdf\Pdf;
Yii::setAlias('#webdir', realpath(dirname(__FILE__) . '/../../'));
$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');
$config = [
'id' => 'easyads-console',
'basePath' => dirname(__DIR__),
'aliases' => [
'#assets' => realpath('../assets'),
'#webroot' => realpath('../'),
],
'bootstrap' => [
'log',
'app\yii\base\Settings',
],
'on beforeRequest' => ['\app\init\Application', 'consoleBeforeRequest'],
'controllerNamespace' => 'app\commands',
'modules' => [
'admin' => [
'class' => 'app\modules\admin\Module',
'defaultRoute' => 'admin',
],
],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'options' => [
'class' => '\twisted1919\options\Options'
],
'pdf' => [
'mode' => Pdf::MODE_UTF8,
'class' => Pdf::classname(),
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
],
'urlManager' => [
'enablePrettyUrl' => true,
'rules' => [
[
'pattern' => 'listing/index/<slug:[a-z0-9_\-]+>',
'route' => 'listing/index',
]
]
],
'generateInvoicePdf' => [
'class' => 'app\components\GenerateInvoicePdfComponent',
],
'sendInvoice' => [
'class' => 'app\components\SendInvoiceComponent',
],
'mailer' => [
'class' => 'app\yii\swiftmailer\Mailer',
],
'consoleRunner' => [
'class' => 'vova07\console\ConsoleRunner',
'file' => '#app/console.php'
],
'mailQueue' => [
'class' => 'app\components\mail\queue\MailQueueComponent',
],
'twigTemplate' => [
'class' => 'app\components\mail\template\MailTemplateComponent',
],
'mailSystem' => [
'class' => 'app\components\mail\MailSystemComponent',
],
'migration' => [
'class' => 'twisted1919\helpers\Migration',
],
'mutex' => [
'class' => 'yii\mutex\FileMutex',
],
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
if (is_file($file = __DIR__ . "/console-local.php")) {
$config = \yii\helpers\ArrayHelper::merge($config, require $file);
}
return $config;
config/db.php
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=database;port=3306;dbname=db',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'tablePrefix'=> 'ea_',
'on afterOpen' => function($event) {
$event->sender->createCommand('SET time_zone="+00:00"')->execute();
$event->sender->createCommand('SET NAMES utf8')->execute();
$event->sender->createCommand('SET SQL_MODE=""')->execute();
},
];

Yii2 - Working With Multiple backend- session and cookies

Let me tell you the case.
Basically I have separate backend in yii2 advanced template.
Why ? This is the reason
My office have a lot of branch office in a country with a lot of departements of each branch.
This departements, I have interpretation of them as modules.
The departement name is same but sometime, they have a lot of different
behaviours.
As example admin in headquarters can erase employee name in branch
office, but admin branch office , they can not.
So, I choose to separate them into backend folder each like this :
backend (which is portal branch and also super-admin backend)
-modules
-human_resource
backend-jkt (which is Jakarta Indonesia backend)
-modules
-human_resource
My question is :
When user successfully login to backend, then i created a link to backend-jkt, it's automatically login also.
As vice versa,
When people directly to backend-jkt but not logged in to backend, it's automatically redirect to backend's login,
Now my situation is: when user logged in to backend, then click link "Jakarta" as above in image, user have to sign in again.
This is my config in backend
<?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' => 'Backend System',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'modules' => [
'mimin' => [
'class' => '\hscstudio\mimin\Module',
],
'SuperAdmin' => [
'class' => 'backend\modules\super_admin\SuperAdmin',
],
],
'components' => [
'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',
'savePath' => sys_get_temp_dir(),
],
'request' => [
'cookieValidationKey' => 'IkR77lm93Rcb9TCoYTAZ',
'csrfParam' => '_csrf-backend',
],
'assetManager' => [
'bundles' => [
'dmstr\web\AdminLteAsset' => [
],
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'suffix' => '.html',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
'urlManagerBackendJkt' => [
'class' => 'yii\web\urlManager',
'baseUrl' => '/backend-jkt/web/',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'http://jkt.tresnamuda.local/' => '#app/index',
],
],
'authManager' => [
'class' => 'yii\rbac\DbManager', // only support DbManager
],
],
'as access' => [
'class' => '\hscstudio\mimin\components\AccessControl',
'allowActions' => [
// add wildcard allowed action here!
'site/*',
'debug/*',
// 'mimin/*', // only in dev mode
],
],
'params' => $params,
];
And this is the backend-jkt
<?php
$params = array_merge(
require __DIR__ . '/../../backend/config/params.php',
require __DIR__ . '/../../backend/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
return [
'id' => 'app-backend_jkt',
'name' => 'Jkt Backend System',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend_jkt\controllers',
'bootstrap' => ['log'],
'modules' => [
'mimin' => [
'class' => '\hscstudio\mimin\Module',
],
],
'components' => [
'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',
'savePath' => sys_get_temp_dir(),
],
'request' => [
'cookieValidationKey' => 'IkR77lm93Rcb9TCoYTAZ',
'csrfParam' => '_csrf-backend',
],
'assetManager' => [
'bundles' => [
'dmstr\web\AdminLteAsset' => [
],
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'suffix' => '.html',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
'authManager' => [
'class' => 'yii\rbac\DbManager', // only support DbManager
],
],
'as access' => [
'class' => '\hscstudio\mimin\components\AccessControl',
'allowActions' => [
// add wildcard allowed action here!
'site/*',
'debug/*',
// 'mimin/*', // only in dev mode
],
],
'params' => $params,
];
your question about cookies that place in user's browsers seprate by domain and Path , so you have to store it for next domain Path , I recommend to you after clicking Jakarta send user-id and private-key to Jakarta and there force login that user-id by simple command :
if(private-key is Okey and you get $user-id by POST ) {
$user = User::findOne($user-id);
Yii::$app->getUser()->login($user);
}
private-key is simple or advance why that you can increase your security , you may leave it and just check have user-id or not !

Yii2 Unable to verify your data submission in incognito mode

I have separated backend and frontend by using below:
Backend Config/main.php
$config = [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'modules' => [],
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
'cookieValidationKey' => 'sdsdsdsd-e8Fhoa1PdHzzfB2VTON9Nfh',
'class' => 'common\components\Request',
'web'=> '/backend/web',
'adminUrl' => '/cpanel'
],
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'user' => [
'identityClass' => 'common\models\AdminUser',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-project-backend', /*'httpOnly' => true*/],
],
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'project-backend',
'timeout' => 60*60*24*30,
],
],
'params' => $params,
];
Frontend Config/main.php
$config = [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers',
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
'cookieValidationKey' => 'wmWhVSIv-e8Fhoa1PdHzzfB2VTON9Nfh',
'class' => 'common\components\Request',
'web' => '/frontend/web'
],
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity-project-frontend', /*'httpOnly' => true*/],
],
'session' => [
// this is the name of the session cookie used for login on the frontend
'name' => 'project-frontend',
'timeout' => 60*60*24*30,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
],
'params' => $params,
//'defaultRoute' => 'site/index'
];
Now it is working perfectly in normal browser mode. But when ever i am trying to login using incognito mode, on first attempt it gives below error:
Unable to verify your data submission
After that, if i reload the page and try to login again, it works normally.
My form is generated using ActiveForm, so CSRF token is available in login page.
So how to solve this problem?
Yo can specify the validation false in specific controller / actions
include the Yii class
use Yii;
inside the action
Yii::$app->controller->enableCsrfValidation = false;
or inside the controller
$this->enableCsrfValidation = false;
You need to set validation false
Set this code inside the action
Yii::$app->controller->enableCsrfValidation = false;
Set complete controller validation false
$this->enableCsrfValidation = false;
This will work

Setting unknown property: yii\console\ErrorHandler::errorAction on linux server

I just uploaded my yii advanced project to my centos server, but I can't seem to get past the migrate phase. When I try to run yii migrate the following error occurred:
`Setting unknown property: yii\console\ErrorHandler::errorAction'
I have no idea why this happens, because it works fine when I run it locally on my windows computer.
My yii advance project is bit different than a normal Yii advanced. The backend has been separated from the frontend so it just contains the console and frontend directory.
common/config/main.php
$config = require(__DIR__ . '/main-console.php');
array_push($config['bootstrap'], 'site');
$config['components']['errorHandler'] = [
'errorAction' => 'site/error',
];
$config['components']['user'] = [
'identityClass' => 'frontend\models\User',
'enableAutoLogin' => true,
];
$config['components']['session'] = [
'name' => 'PHPFRONTSESSID',
'savePath' => sys_get_temp_dir(),
];
$config['components']['request'] = [
'cookieValidationKey' => 'IBzCJMjLWUaXMZemYUej',
'csrfParam' => '_frontendCSRF',
];
$config['components']['site'] = [
'class' => 'frontend\components\SiteComponent',
];
return $config;
main-console.php
$params = array_merge(
require(__DIR__ . '/params.php')
);
return [
'id' => 'app-frontend',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log','debug'],
'sourceLanguage' => 'en-US',
'controllerNamespace' => 'frontend\controllers',
'aliases' => [
'#local_media' => '#frontend/web/uploads/media',
],
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
],
],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#frontend/messages',
],
],
],
'assetManager' => [
'bundles' => false,
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning', 'trace'],
],
],
],
'defaultRoute' => 'site/view',
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => true,
'enableStrictParsing' => false,
'rules' => require('routes.php'),
],
],
'params' => $params,
];
Can someone give me some advies on how to solve this problem?
You problem is that you specify error action into common/config/main.php. Error action must be used only with web apps, not console. So move this to your frontend and backend configs separately:
$config['components']['errorHandler'] = [
'errorAction' => 'site/error',
];
There is no errorAction attribute in yii\console\ErrorHandler class. There is one in yii\web\ErrorHandler though. I'm not sure why this works on your local machine because it shouldn't. I guess some other configuration is in place there.

The configuration for the "modules" component must contain a "class" element

I have define a module named `admin' in yii2.
I have registered this module in web.php config file.
But when I try to access this I face with an error.
here is my web.php
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'language'=>'fa_ir',
'bootstrap' => ['log'],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'SiMhYyhP2MZ_BAi321KfDHFk5uleQFa9',
],
'jdate' => [
'class' => 'jDate\DateTime'
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'modules' => [
'admin' => [
'class' => 'app\modules\admin\Module',
],
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'pishevaris#gmail.com',
'password' => 'bhtk1368',
'port' => '587',
'encryption' => 'tls',
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
'db' => require(__DIR__ . '/db.php'),
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
here is my Module class:
<?php
namespace app\modules\admin;
class Module extends \yii\base\Module
{
public $controllerNamespace = 'app\modules\admin\controllers';
public function init()
{
parent::init();
// custom initialization code goes here
}
}
but when I try to access mysite/admin/default/index I face The configuration for the "modules" component must contain a "class" element error
Please define module in out side of component. Like
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'language'=>'fa_ir',
'bootstrap' => ['log'],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'SiMhYyhP2MZ_BAi321KfDHFk5uleQFa9',
],
'jdate' => [
'class' => 'jDate\DateTime'
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => 'pishevaris#gmail.com',
'password' => 'bhtk1368',
'port' => '587',
'encryption' => 'tls',
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
'db' => require(__DIR__ . '/db.php'),
],
'modules' => [
'admin' => [
'class' => 'app\modules\admin\Module',
],
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
Modules are different with Components, and you defined your module as a component by adding this to component array. you should write your module after or before component. like below:
['components'] => [],
['modules'] => [],

Categories