i install this plugin for change theme in frontend https://github.com/Singrana/thememanager
install like manual.
in my frontend/config/main.php
'components' => [
'view'=>
[
'theme' =>
[
'class' => 'singrana\thememanager\components\ThemeManager',
'current' => 'siteeee',
'themes' =>
[
'site' =>
[
'pathMap' =>
[
'#app/views' => '#frontend/themes/site',
'#app/views/layouts' => '#frontend/themes/site/layouts',
],
//'defaultLayout' => '//inner',
],
'siteeee' =>
[
'pathMap' =>
[
'#app/views' => '#frontend/themes/siteeee',
'#app/views/layouts' => '#frontend/themes/siteeee/layouts',
],
//'defaultLayout' => '//inner',
],
],
],
],
],
but i need to call \Yii::$app->view->theme->changeTheme('themeName');, like in manual, to change theme , how can i do this in backend side ?
Related
I'm install 2amigos/yii2-usuario:~1.5.1 on a yii2-basic-template, using https://yii2-usuario.readthedocs.io/en/latest/. However, it returns this error (Getting unknown property: Da\User\Module::isGuest yii2-usuario) in any view.
My config/console.php:
'components' => [
...
'authManager' => [
'class'=> 'yii\rbac\DbManager',
],
...
],
'controllerMap' => [
'migrate' => [
'class' => \yii\console\controllers\MigrateController::class,
'migrationPath' => [
'#app/migrations',
'#yii/rbac/migrations', // Just in case you forgot to run it on console (see next note)
],
'migrationNamespaces' => [
'Da\User\Migration',
],
],
],
My config/web.php:
'components' => [
...
'user' => [
'class' => Da\User\Module::class,
'classMap' => [
'User' => app\models\User::class,
],
],
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
'view' => [
'theme' => [
'pathMap' => [
'#Da/User/resources/views' => '#app/views/user'
]
]
]
],
I managed to solve it with help.
Follow the line:
Remove : config/web.php
'user' => [
'identityClass' => 'app\models\Users',
'enableAutoLogin' => true,
'enableSession' => true,
],
'user-management' => [
'class' => 'webvimark\modules\UserManagement\UserManagementModule',
'on beforeAction'=>function(yii\base\ActionEvent $event) {
if ( $event->action->uniqueId == 'user-management/auth/login' ){
$event->action->controller->layout = 'loginLayout.php';
};
},
],
add into config/web.php:
'components' =>[ ...
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
'view' => ['theme' => [ 'pathMap' => ['#Da/User/resources/views' => '#app/views/user']]] //If your view is modified.
]
'modules' => ['user' => [
'class' => \Da\User\Module::class,
'allowAccountDelete' => true,
'enableRegistration' => false,
'administratorPermissionName' => 'user-management']
...]
``
I need to override a view file like ‘pathMap’ => [ ‘#dektrium/user/views’ => ‘#app/views/site’] I followed manual (https://github.com/dektrium/yii2-user/blob/master/docs/overriding-views.md) but all I see is the old view whatever I do. Perhaps something wrong with baseUrl or basePath but I’m not sure what I should do.
frontend/config/main.php:
'components' => [
'request' => [
'csrfParam' => '_csrf-frontend',
'baseUrl' => '/',
],
// .................
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'/' => 'site/index',
'<action:\w+>' => 'site/<action>',
],
],
'view' => [
'class' => 'yii\web\View',
'theme' => [
//'basePath' => '#app/themes/basic',
//'baseUrl' => '#app/views/site',
'pathMap' => [
'#dektrium/user/views' => '#app/views/site'
]
]
]
//.................
]
common/config/main.php:
'modules' => [
'user' => [
'class' => 'dektrium\user\Module',
'admins' => ['admin'],
'modelMap' => [
'User' => 'common\models\User',
],
]
I open page on the address like mydomain.test/user/register (in case it’s somehow matter)
I also tried to put ‘view’ part in components of common/config/main.php and of module. Tried to create themes folder and put new view therein, nothing seems work
ok, I finally fixed it
'view' => [
'class' => 'yii\web\View',
'theme' => [
'basePath' => '#frontend/views/site',
'baseUrl' => '#frontend/views/site',
'pathMap' => [
'#dektrium/user/views/registration' => '#frontend/views/site',
]
]
]
I have been reading through elastic search docs over the last few months and have continued to optimize my query, but I can't seem to get a search query below 500-600ms. Locally with less data I can get responses in ~80-200ms.
To outline what I am trying to accomplish:
I have 12 different models in Laravel that are searchable from a single search bar. As someone types it is searched and returned in a list of results.
Currently, I have this for my search query. Are there any references for how I can improve this? I looked into multi_match, but I was having issues with partial matches and specifying all fields.
$results = $this->elastic->search([
'index' => config('scout.elasticsearch.index'),
'type' => $type ?? implode(',', array_keys($this->permissions, true, true)),
'body' => [
'query' => [
'bool' => [
'must' => [
[
'query_string' => [
'query' => "$searchQuery*",
],
],
],
'filter' => [
[
'term' => [
'account_id' => $accountId,
],
],
],
'should' => [
[
'term' => [
'_type' => [
'value' => 'customers',
'boost' => 1.3,
],
],
],
[
'term' => [
'_type' => [
'value' => 'contacts',
'boost' => 1.3,
],
],
],
[
'term' => [
'_type' => [
'value' => 'users',
'boost' => 1.3,
],
],
],
[
'term' => [
'_type' => [
'value' => 'chart_accounts',
'boost' => 1.2,
],
],
],
],
],
],
'from' => $from,
'size' => $size,
],
]);
I'm trying to translate a constants file located in common/php/ that I use for error messages.
The constants are defined like this:
define("CONSTANT_NAME", Yii::t('common/error', 'Error message'));
I have the following in common/config/main.php:
'i18n' => [
'translations' => [
'backend*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/messages',
'sourceLanguage' => 'it-IT',
'fileMap' => [
'backend' => 'app.php',
],
],
'common*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#common/messages',
'sourceLanguage' => 'it-IT',
'fileMap' => [
'common' => 'app.php',
'common/error' => 'error.php',
],
],
'frontend*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#frontend/messages',
'sourceLanguage' => 'it-IT',
'fileMap' => [
'frontend' => 'app.php',
],
],
],
],
It's working for backend and frontend but it's not working for the constant file located in common. Am I trying to do something that is not possible?
if you are trying to translate from it-IT to en-US then add this to your common/config/main.php:
'sourceLanguage'=>'it-IT',
'language'=>'en-US',
I am currently trying to install a Yii2 extension for implementing an OAuth2 server (https://github.com/Filsh/yii2-oauth2-server). However, I keep running on the error below:
Does anyone have an idea on how to install this extension. I followed the instructions given but there was no mention about that error.
Satya is right. You need to configure oauth2 module as described on repo's description:
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'options' => [
'token_param_name' => 'accessToken',
'access_lifetime' => 3600 * 24
],
'storageMap' => [
'user_credentials' => 'common\models\User'
],
'grantTypes' => [
'client_credentials' => [
'class' => 'OAuth2\GrantType\ClientCredentials',
'allow_public_clients' => false
],
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials'
],
'refresh_token' => [
'class' => 'OAuth2\GrantType\RefreshToken',
'always_issue_new_refresh_token' => true
]
],
]
I've configured this extension successfully and created Yii2 Rest API template with OAuth2 server https://github.com/ikaras/yii2-oauth2-rest-template - feel free to use. Also this code has some demo data (examples of using) and support of scopes for controllers.
Add give 'oauth2' configuration in 'modules' section of config/main.php.
It may work
Use this configuration under your confin/main.php file under modules section.
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'tokenParamName' => 'token',
'tokenAccessLifetime' => '100800', // Expiry Time
'storageMap' => [
'user_credentials' => 'common\models\User', // This Should be your model name
],
'grantTypes' => [
'client_credentials' => [
'class' => 'OAuth2\GrantType\ClientCredentials',
'allow_public_clients' => false,
],
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
'refresh_token' => [
'class' => 'OAuth2\GrantType\RefreshToken',
'always_issue_new_refresh_token' => true,
'refresh_token_lifetime' => '100800',
],
],
];
Found solution my-self on scope issue, maybe it will be useful for someone - marked with ** in config:
'modules' => [
'oauth2' => [
'class' => 'filsh\yii2\oauth2server\Module',
'tokenParamName' => 'accessToken',
'tokenAccessLifetime' => 3600 * 24,
'storageMap' => [
'client_credentials' => 'app\models\User',
'user_credentials' => 'app\models\User',
**'scope' => 'app\models\User',**
],
'grantTypes' => [
'client_credentials' => [
'class' => '\OAuth2\GrantType\ClientCredentials',
'allow_public_clients' => false,
'always_issue_new_refresh_token' => true
],
'user_credentials' => [
'class' => 'OAuth2\GrantType\UserCredentials',
],
'refresh_token' => [
'class' => 'OAuth2\GrantType\RefreshToken',
'always_issue_new_refresh_token' => true
]
]
]
],