I have yii2 installed with Elasticsearch, Logstash, Kibana. The set-up is working well except for the interaction with YII2.
Below is the contents for ./config/db.php
<?php
return [
'components' => [
'db' => [
'class' => 'yii\elasticsearch\Connection',
'user' => 'admin',
'password' => 'admin',
'nodes' => [ ['http_address' => '127.0.0.1:9200'],
// configure more hosts if you have a cluster
],
],
]
];
This configuration is not working, below are the first lines of the error.
Invalid Configuration – yii\base\InvalidConfigException
The configuration for the "db" component must contain a "class"
element.
in /var/www/hostings/yiiphp/tools/vendor/yiisoft/yii2/di/ServiceLocator.php
.....
I fail o find relevant information to fix this. What am i doing wrong ?
file ./config/db.php should be included by the main config file, named web in your case (it seems that you are using basic app template)
Another words - look at file ./config/web.php then find the line:
'db' => ... and replace it with 'db' => require(__DIR__ . '/db.php'),
Finally, your db.php should be like this:
<?php
return [
'class' => 'yii\elasticsearch\Connection',
'user' => 'admin',
'password' => 'admin',
'nodes' => [ ['http_address' => '127.0.0.1:9200'] ]
];
It is also seems strange to me, that you want to use elastic component as a db component, but its up to you, of course.
Related
This project has been ported over manually from Zend Frame work 2 to Laminas. The issue here is that the module.config.php has been set up in the same way as other modules that are working. However I am encountering this error. I have checked the usually culprits such as files spelling or missing, no other modules are using the same route name. Is there another part of Laminas that would affect the view manager?
The modul.config.php setup is below.
'''
namespace ProjectTaskDocument;
use Laminas\Router\Http\Segment;
return [
'router' => [
'routes' => [
'project-task-document' => [
'type' => Segment::class,
'options' => [
'route' => '/task-document[/:action][/:id]',
'constraints' => [
'action' => 'index|add|download|view-all|delete'
],
'defaults' => [
'controller' => Controller\ProjectTaskDocumentController::class,
'action' => 'index'
]
]
]
]
],
'view_manager' => [
'template_path_stack' => [
'ProjectTaskDocument' => __DIR__ . '/../view'
],
]
];
'''
The module folder structure
Realised my mistake, during my port process another module was using the same Key identifier for the view_manager->template_path_stack. I feel pretty damn dumb for missing this.
Hy,
I would like to use this module (https://github.com/phly/phly-expressive-oauth2clientauthentication)in my expressive application.
I read this documentation https://phly.github.io/phly-expressive-oauth2clientauthentication
here is what I did :
in my config/autoload folder i add a oauth2clientauthentication.global.php with this array :
'oauth2clientauthentication' => [
'routes' => [
'production' => '/(:provider)(/oauth2callback)',
],
],
in my pipeline.php file i add
use Phly\Expressive\OAuth2ClientAuthentication\OAuth2CallbackMiddleware;
$app->pipe('/auth', OAuth2CallbackMiddleware::class);
in my ConfigProvider.php file i add a route with this config (I use slim router with https://github.com/acelaya/expressive-slim-router:
[
'name' => 'admin',
'path' => '/admin',
'allowed_methods' => ['GET'],
'middleware' => [
SessionMiddleware::class,
AuthenticationMiddleware::class,
Action\AdminAction::class,
],
When i tried this url : 'http://blog/admin', i get my unauthenticated page with github button. But when i click on the button the url is : 'http://blog/auth/github?redirect=http://blog/admin' and get an error :
Unable to resolve service "Zend\Expressive\Delegate\NotFoundDelegate"
I do not understand where is the problem, anyone have an idea to solve this?
It looks like you upgraded your Expressive installation without going through the migration guide.
Check your config/autoload/dependencies.global.php. It should contain something like this:
use Zend\Expressive\Container\NotFoundDelegateFactory;
use Zend\Expressive\Delegate\NotFoundDelegate;
return [
'dependencies' => [
'aliases' => [
'Zend\Expressive\Delegate\DefaultDelegate' => NotFoundDelegate::class,
],
'factories' => [
NotFoundDelegate::class => NotFoundDelegateFactory::class,
],
],
];
I am using Yii2 to work on a project that needs to be translated into various languages. I am using the advanced template and set up my common/main.php like so
return [
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'language' => 'en',
'sourceLanguage' => 'en',
'components' => [
'i18n' => [
'translations' => [
'app' => [
'class' => 'yii\i18n\DbMessageSource',
'sourceLanguage' => 'en',
],
],
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
'as beforeRequest' => [
'class' => 'common\components\CheckLanguage',
],
];
I have added the required database tables source_message and message. Now each text in the website that I need to have translated I use the Yii::t($category,$message) function.
My question is; How can I get a list of all text in my website that needs to be translated into the database? Do I have to manually scan my site for all Yii::t($category,$message) function calls?
Thanks in advance for your time and input
There is console command provided for this scan functionality.
./yii message
See the documentation in the Guide.
Generate configuration file for the scanner:
./yii message/config-template your/path/to/saving/config.php
Adjust the newly created config.php to your needs.
Run the command:
./yii message path/to/config.php
I am currently building a second system with yii2. It will use some tables from a Yii1 database for translation. The Yii1 project was originally translated using files but this has now been moved to the db. All the translations of the Yii1 system use one of three categories app,flash,email of which the vast majority use app.
In the Yii2 project I have the following in the web.php config file.
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\DbMessageSource',
'db' => 'cdb',
'sourceMessageTable' => 'translation_source',
'messageTable' => 'translation',
'forceTranslation'=>true,
],
],
],
All of the translations on the system that use app are not translated, however, all other categories are. If I change the above code to
'i18n' => [
'translations' => [
'app*' => [
Then I get an error for other categories but not app and the app strings are translated as expected. The error I get is
Unable to locate message source for category 'flash'.
If however I change my config to the following, this works for all translations.
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\DbMessageSource',
'db' => 'cdb',
'sourceMessageTable' => 'translation_source',
'messageTable' => 'translation',
'forceTranslation' => true,
],
'app*' => [
'class' => 'yii\i18n\DbMessageSource',
'db' => 'cdb',
'sourceMessageTable'=>'translation_source',
'messageTable' => 'translation',
'forceTranslation' => true,
],
],
],
It just seems odd that I am having to include effectively the same code block twice. Can anyone tell me how I can achieve this in one array or is this the expected behaviour?
** Update **
I do see some mention of * in the docs Docs. I also see some mention of this in the Forum
Module section config
'user' => [
'class' => 'dektrium\user\Module',
'modelMap' => [
'User' => 'app\models\DL\User',
'registrationForm' => 'app\models\DL\registrationForm',
],
'controllerMap' => [
/*'registration' => 'app\controllers\user\RegistrationController',
'admin' => 'app\controllers\user\AdminController'*/
],
'layout' => '#app/views/layouts/container',
'defaultRoute' => 'profile',
'admins' => ['admin'],
'enableFlashMessages' => false,
'params' => [
'menuItems' => [
'label' => 'Users',
'url' => ['/user/admin']
]
]
],
Yii console application (./yii) showing me error
'Calling unknown method:
app\controllers\user\AdminController::getHelpSummary()'
If I uncomment the controllerMap section, I can't understand why it autoloads in console app if my AdminController extends web controller not console.
This is commands from user module.
Do you really need the user module in console?
Yii2 console and web applications have separated configuration files by default. If you changed this default and use the same config for both of them, you must take care about consistency.
You can check the list of loaded configs in ./yii.
You need to specify a valid defaultRoute for the console application.
With 'defaultRoute' => 'profile', ./yiimay try to load a Controller which requires the user module.
Try adding it in the console configuration.