How to create custom urls with dashes in Yii2? - url

I am working with advanced project application and trying to add URL rules in Yii2 to handle custom URLs with dashes.
What I want to do is to change the URL from
http://www.example.com/post/details?url=example-post-title
To
http://www.example.com/example-post-title
I have below configuration which works fine when the URL parameter does not have dash (exampleposttitle).
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
// ...
'<url:\w+>' => 'post/details',
],
],

You need to fix your regexp, since \w+ does not allow dashes:
'<url:[\w-]+>' => 'post/details',

Related

TYPO3: How can I set the sys_language_uid of news to -1 in TYPO3 9?

I want to use some news across multiple languages, but currently I can't choose -1 (all languages) via TYPO3 backend. Furthermore I can only choose between sys_language_uid 0 to 3, which are the uids of my configured languages.
If I take a look at the TCA configuration of the news model (tx_news_domain_model_news.php). Then I can see that -1, all languages still exists there.
'sys_language_uid' => [
'exclude' => true,
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.language',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'special' => 'languages',
'items' => [
[
'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.allLanguages',
-1,
'flags-multiple'
],
],
'default' => 0,
]
],
but it is not not available for me:
Do I miss a specific language setting to enable this option or how I can enable this?
The issue was caused by another extension which have removed this -1 entry.

Move guards to database in ZF2 application with ZfcRbac

I am using ZfcRbac for managing role-based access control for my ZF2 application. Currently I am controlling the access by updating the guards in zfc_rbac.global.php file in following way.
'guards' => [
'ZfcRbac\Guard\RouteGuard' => [
'p304' => ['*'],
'zfcuser/logout' => ['*'],
'home' => ['admin', 'engineer', 'user'],
'application*' => ['admin'],
'AppUser*' => ['admin'],
'Clients*' => ['admin', 'engineer', 'user'],
'zfcadmin*' => ['admin'],
'zfcuser' => ['admin', 'engineer', 'user'],
'zfcuser/login' => ['guest'],
]
],
I am struggling to find a way to move it to Database. Hope any one can help me to move this access control definition to database.
If you are using Doctrine as ORM there is already a documentation in ZfcRbac on how to implement this.

ZF2 - Asset Manager, slowing down application

I started writing this as I was struggling to get ZF2 Asset Manager to work properly however in mid swing I managed to sort out the problem and felt the question still needs to be asked in order to help others.
If you are looking for an Asset Manager for ZF2, try out: https://github.com/RWOverdijk/AssetManager
The problems I faced was essentially due to a lack of documentation and the solution was really simple.
For asset manager to work, you essentially need to generate a cache of your files that your app can locate. Once the files have been located and are reachable, your app will speed up tremendously. The first problem I faced was the module.config.php file. The documentation is not clear in how to set this up correctly.
My original file looked like this:
'asset_manager' => [
'resolver_configs' => [
'paths' => [
__DIR__ . '/../assets',
]
],
],
Which essentially tells my application to look in the module/assets directory for any assets. This worked out the box but was VEERY slow...
I read up about caching and my modification of my file was as follows:
'asset_manager' => [
'caching' => [
'default' => [
'cache' => 'FilePath', // Apc, FilePath, FileSystem etc.
],
],
'resolver_configs' => [
'paths' => [
__DIR__ . '/../assets',
]
],
],
This did nothing... so after searching code in gitHub to see how others had implemented Asset Manager I discovered you can set the options of where to put the cache... so my new config became this:
'asset_manager' => [
'caching' => [
'default' => [
'cache' => 'FilePath', // Apc, FilePath, FileSystem etc.
'options' => [
'dir' => getcwd() . 'public',
]
],
],
'resolver_configs' => [
'paths' => [
__DIR__ . '/../assets',
]
],
],
Still my app was not working although the assets where being generated in a folder called: trunkpublic in the root of my app. After much frustration I realised that I need to update:
'dir' => getcwd() . 'public', to 'dir' => getcwd() . '/public',
Adding a slash put the folder in the public directory, which in retrospect is obvious since the app needs access to the cached files.
My final configuration is this:
'asset_manager' => [
'caching' => [
'default' => [
'cache' => 'FilePath', // Apc, FilePath, FileSystem etc.
'options' => [
'dir' => getcwd() . '/public',
//'dir' => getcwd() . '/data/cache/assets',
]
],
],
'resolver_configs' => [
'paths' => [
__DIR__ . '/../assets',
]
],
],
You will notice I have this snippet commented out:
//'dir' => getcwd() . '/data/cache/assets',
The above is super fast and is used with the Filepath option and is great for development mode, it essentially generates a hash of the file in the /data.cache/assets directory however for a production environment I prefer to have actual files saved to the assets cache found in: public/assets as this allows the app to grab the files directly without having to invoke php.
NOTE:
There was another issue I faced and this is due to misleading documentation
If you look at this line:
'cache' => 'Filesystem', // Apc, FilePath, FileSystem etc.
You may be tempted to add your files using CamelCase... however some may reauire CamelCase and others may require Normalcase... check the code for this...
works for me!!
'asset_manager' => array(
'caching' => array (
'default' => array(
'cache' => 'FilePath', // Apc, FilePath, FileSystem etc.
'options' => array(
'dir' => './public',
),
),
),
'resolver_configs' => array(
'paths' => array(
'MyModule' => __DIR__ . '/../public',
),
),
),
now i try fix flter JSMin and JSSqueeze
tank you!

How to config Zend Frameword 2 output cache

I'm using output cache in zend framework 2:
$outputCache = Zend\Cache\PatternFactory::factory(
'output',
array(
'storage' => 'apc'
)
);
$outputCache->start('mySimpleViewScript');
include '/path/to/view/script.phtml';
$outputCache->end();
Please help me config time cache(ttl) and cache_dir.
Thanks.
If you pass storage by string ('apc' in your example), specific storage implementation is pulled from Zend\Cache\Storage\AdapterPluginManager as invokable with default options (ttl is 0 by default).
If you need custom options, just create your cache storage directly, it is covered by cache storage adapter documentation:
$cache = Zend\Cache\StorageFactory::factory([
'adapter' => [
'name' => 'apc',
'options' => [ 'ttl' => 3600 ],
],
]);
$outputCache = Zend\Cache\PatternFactory::factory('output', [
'storage' => $cache,
]);
cache_dir is not valid option for Apc adapter.

Unable to override route via DI

I'm attempting to override the routes provided by ZfcUser using akrabat's method, however it doesn't seem to have any effect. I'm starting by rebasing the routes from /user to /users but will want to add other routes later on (should be simple if I can get this working).
My DI configuration:
return [
'di' => [
'instance' => [
'Zend\Mvc\Router\RouteStack' => [
'parameters' => [
'routes' => [
'zfcuser' => [
'options' => [
'route' => '/users'
]
]
]
]
]
]
]
];
Am I making an obvious mistake or has the configuration structure for this changed since this blogpost?
You'd overwrite configuration from within your own modules.
'router' => array(
'routes' => array(
'zfcuser' => array(
//...
)
)
)
Though if i'm correct the full DI Path should still work... It's important, too, that your module loads AFTER the zfcUser-Module. So within your application.config.php be sure that your modules Namespace is listed after zfcUser. Since the arrays simply get overwritten depending on load time ^^

Resources