I work on a project which is recently updated to Laminas and PHP 8.1 from Zend3 and PHP 7.4.
in config/autoload/global.php
'caches' => require __DIR__ . '/caches.php',
and this is caches.php
$cacheDefault = [
'adapter' => [
'name' => 'Memcached',
'options' => [
'servers' => Module::isRunningOnVM()
? ['127.0.0.1:11211']
: Module::getMemcachedServersFromEnvironment(),
],
],
];
return [
'cache_instrument_manager_search' => array_merge_recursive(
$cacheDefault,
[
'adapter' => [
'options' => [
'namespace' => 'instrument_manager_search',
'ttl' => 20,
],
],
]
),
'cache_weekly' => array_merge_recursive(
$cacheDefault,
[
'adapter' => [
'options' => [
'namespace' => 'weekly',
'ttl' => 604800, // whole week
],
],
]
),
];
It worked well in zend 3. but after updating to Laminas and PHP8.1 I got this error
Laminas\ServiceManager\Exception\ServiceNotCreatedException
File:
/project/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:620
Message:
Service with name "cache_instrument_manager_search" could not be created. Reason: Configuration must contain a "adapter" key.
I have changed it to
return [
'cache_instrument_manager_search' => [
'adapter' => 'Memcached',
'options' => ['ttl' => 3600],
'plugins' => [
[
'name' => 'exception_handler',
'options' => [
'throw_exceptions' => false,
],
],
],
]
];
But Still has this error
Laminas\ServiceManager\Exception\ServiceNotFoundException
File:
/project/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:557
Message:
Unable to resolve service "Memcached" to a factory; are you certain you provided it during configuration?
I need help. I read documents in Laminas but still could not solve this.
I'm using Redis Cache and I had to add:
'Laminas\Cache\Storage\Adapter\Redis'
to my modules.config.php file
Related
I have three type of content elements (tt_content|types) which all use an image-column with each one FAL-relations for one image.
I'd like to use for 2 content elements the type = 'imageManipulation' (Docs) with 2 different configurations and for one just the image as it is.
Since the type = 'imageManipulation' is defined normally for sys_file_reference, so for all usages.
Is it possible with TCA overrides to archive different configurations for different content elements?
I tried a combination of columnsOverrides and overrideChildTca, but this doesn't work in the moment:
<?php
defined('TYPO3_MODE') or die();
(function () {
if (is_array($GLOBALS['TCA']['tt_content']['types']['mask_teaser_hero'])) {
$GLOBALS['TCA']['tt_content']['types']['mask_teaser_hero']['columnsOverrides'] = [
'tx_maskproject_teaserimage' => [
'config' => [
'overrideChildTca' => [
'columns' => [
'crop' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.crop',
'config' => [
'type' => 'imageManipulation',
'cropVariants' => [
'mobile' => [
'title' => 'Mobile',
'selectedRatio' => '4:3',
'allowedAspectRatios' => [
'4:3' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
'value' => 4 / 3
],
],
],
'desktop' => [
'title' => 'Desktop',
'selectedRatio' => '16:9',
'allowedAspectRatios' => [
'16:9' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
'value' => 16 / 9
],
],
],
]
],
],
]
],
]
]
];
}
})();
I first thought about Typoscript TCEFORM:
https://metinyilmaz.de/artikel/typo3-image-cropvariants/
But this would also appear in each content element.
I found the mistake. The TCA override is correct. But the type was not.
I use EXT:mask_export for the content elements. In the example from the question I override the content elements which EXT:mask adds. But the exported content elements are different content elements.
The correct one is:
<?php
defined('TYPO3_MODE') or die();
(function () {
if (is_array($GLOBALS['TCA']['tt_content']['types']['myextname_teaser_hero'])) {
$GLOBALS['TCA']['tt_content']['types']['myextname_teaser_hero']['columnsOverrides'] = [
'tx_myextname_teaserimage' => [
'config' => [
'overrideChildTca' => [
'columns' => [
'crop' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.crop',
'config' => [
'type' => 'imageManipulation',
'cropVariants' => [
'mobile' => [
'title' => 'Mobile',
'selectedRatio' => '4:3',
'allowedAspectRatios' => [
'4:3' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.4_3',
'value' => 4 / 3
],
],
],
'desktop' => [
'title' => 'Desktop',
'selectedRatio' => '16:9',
'allowedAspectRatios' => [
'16:9' => [
'title' => 'LLL:EXT:lang/Resources/Private/Language/locallang_wizards.xlf:imwizard.ratio.16_9',
'value' => 16 / 9
],
],
],
]
],
],
]
],
]
]
];
}
})();
I'm pretty new to ZF and have a question regarding translator configuration. I have an application with the following translator configuration inside the module.cofig file:
'translator' => [
'locale' => 'ru_RU',
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
],
[
'type' => 'phparray',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.php',
],
],
'cache' => \Zend\Cache\StorageFactory::factory(
[
'adapter' => [
'name' => 'Filesystem',
'options' => [
'cache_dir' => APPLICATION_LOAD_PATH . '/data/cache',
'ttl' => '3600',
],
],
'plugins' => [
[
'name' => 'serializer',
'options' => [],
],
'exception_handler' => [
'throw_exceptions' => true,
],
],
]
),
],
This configuration works fine, but I want to know if is it possible to move this code inside Module.php trough the getTranslatorPluginConfig() . What I've tried is to use this method and return this same config:
public function getTranslatorPluginConfig(){
return [
'translator' => [
'locale' => 'ru_RU',
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => __DIR__ . '/language',
'pattern' => '%s.mo',
],
[
'type' => 'phparray',
'base_dir' => __DIR__ . '/language',
'pattern' => '%s.php',
],
],
'cache' => \Zend\Cache\StorageFactory::factory(
[
'adapter' => [
'name' => Filesystem::class,
'options' => [
'cache_dir' => APPLICATION_LOAD_PATH . '/data/cache',
'ttl' => '3600',
],
],
'plugins' => [
[
'name' => 'serializer',
'options' => [],
],
'exception_handler' => [
'throw_exceptions' => true,
],
],
]
),
],
];
}
As you can see I haven't changed anything (except base_dir path). I don't get any errors, but the translator is not working at all. If you can tell me what are the steps I need to take to make this configuration work from the Module file and if this is possible at all, I'll be grateful. I don't expect plain code, but just a guidance/suggestion of what could be done, since all I find in the Zend documentation is related with making this configuration inside module.config. Thanks in advance.
When implementing the access control on the backend, I would like to redirect disallowed users to the frontend error page (instead of the backend error page).
The backend controller:
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => ['admin'],
],
backend/config/main.php
'components'=>[
'errorHandler' => [
'errorAction' => 'site/error',
],
How do I redirect non-admin users to frontend/site/error? Everything I try results in an error.
Many thanks
if I understand correctly you want the frontend user if logged in and tries to access the backend's modules or controllers he/she should not be allowed to do so, This was a Session Sharing bug reported earlier, and this was added into Yii 2.0.9 milestones and is already integrated since 2016.
If you are working on an existing Yii2 project with an older version and haven't migrated or upgraded to the latest version, I would suggest you do the following settings
/backend/config/main.php:
return [
'id' => 'app-backend',
// ...
'components' => [
'user' => [
'identityClass' => 'common\models\Admin',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_backendUser', // unique for backend
]
],
'session' => [
'name' => 'PHPBACKSESSID',
'savePath' => sys_get_temp_dir(),
],
// ..
];
/frontend/config/main.php:
return [
'id' => 'app-frontend',
'components' => [
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
'identityCookie' => [
'name' => '_frontendUser',
]
],
'session' => [
'name' => 'PHPFRONTSESSID',
'savePath' => sys_get_temp_dir(),
],
///...
]
];
I am working on api up to now it has only been tested in Postman so cors wasnt an issue. However now developing the front end and when it comes to custom Yii actions they are failing the preflight request. I solved this by adding these lines to url-manager config:
[
'class' => 'yii\rest\UrlRule',
'controller' => ['v1/call-rates'],
'pluralize' => false,
'extraPatterns' => [
'OPTIONS' => 'options',
'GET all-resellers' => 'all-resellers',
'POST updatefromcsv' => 'updatefromcsv',
'OPTIONS all-resellers' => 'options',
'OPTIONS updatefromcsv' => 'options',
// other end points....
],
So every custom action has to have a corresponding OPTIONS pattern. I have seen on a similar question that it is possible to apply the OPTIONS pattern to all custom actions in one line like so:
[
'class' => 'yii\rest\UrlRule',
'controller' => [
'v1/call-rates',
// rest of controllers...
],
'pluralize' => false,
'extraPatterns' => [
'OPTIONS <action:\w+>' => 'options',
],
],
However that is not working. I have also tried with a token like this:
[
'class' => 'yii\rest\UrlRule',
'controller' => [
'v1/call-rates'
],
'tokens' => [
'{action}' => '<action:\\w+>',
],
'pluralize' => false,
'extraPatterns' => [
'OPTIONS {action}' => 'options',
],
],
But again no luck. Any help would be appreciated. Thank you in advance.
Solved by adding the following in to urlmanager config:
[
'class' => 'yii\rest\UrlRule',
'controller' => [
'v1/call-rates',
'v1/call-recordings',
],
'tokens' => [
'{action}' => '<action:[a-zA-Z0-9\\-]+>',
],
'pluralize' => false,
'extraPatterns' => [
'OPTIONS {action}' => 'options',
'OPTIONS' => 'options'
],
],
Because my custom actions were named like:
public function actionGetResellers
The Url would be get-resellers so the pattern was incorrect as it didn't accept -'s. So now what whatever controller I add it will add OPTIONS pattern for every custom action
I use Regular Expression <action:\w+-\w+>. Here is the solution:
[
'class' => 'yii\rest\UrlRule', //
'controller' => 'v1/content/my',
'pluralize' => false,
'extraPatterns' => [
'OPTIONS <action:\w+-\w+>' => 'options',
'GET foot-print' => 'foot-print',
'GET my-courses' => 'my-courses',
]
Yii2 REST query
I found this for using custom action in the controller for that i added the extrapattern mentioned in the above link
And its working fine when we search .but cant use the normal actions for the controller
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => 'v1/country',
'extraPatterns' => [
'GET search' => 'search'
],
'tokens' => [
'{id}' => '<id:\\w+>'
]
]
],
]
Regards
Thanks all
this solved my problem after lots of trying..
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => 'v1/country',
'extraPatterns' => [
'GET search' => 'search'
],
],
[
'class' => 'yii\rest\UrlRule',
'controller' => 'v1/country',
'tokens' => [
'{id}' => '<id:\\w+>'
]
],
],