I am trying to apply a theme to yii2 advanced application in frontend.
the code I am using to apply the theme is as follows:
'view' => [
'theme' => [
'pathMap' => ['#app/views' => '#app/themes/stargazers'],
'baseUrl' => '#web/../themes/stargazers',
],
],
pretty URL is turned on.
The physical location of theme is in the path like
frontend/themes/stargazers.
and stargazers folder is having this files and folders.
files/
layouts/
layouts/main.php
files/main_style.php
files/theme/
files/theme/main_style.css
files/theme/*.png
I have tried all path location, but was not able to apply the theme, may be missing something silly here.
Yii2 advanced template does not have #app this namespace by default, should you change to #frontend?
'view' => [
'theme' => [
'pathMap' => ['#frontend/views' => '#frontend/themes/stargazers'],
'baseUrl' => '#frontend/themes/stargazers',
],
],
Related
I have a yii2 project which is using a default URL rule (http://example.com?r=controller/action&id=1)
I want to add a REST API module in the project and enable the pretty URL format (http://example.com/controller/action?id=1) only for this module.
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule',
'controller' => [
'api/default',
]
],
],
]
When I configure UrlManager enablePrettyUrl=>true, that also changes the URL format project wide. We have hardcoded URLs in default URL format in the frontend which cannot be changed now as the codebase has grown exponentially.
Is there a way to configure the URL rules only for REST API module and use default URL format for other modules.
Which one is better to set directory folder for global usage?
Below are set to yii2 web config.
'aliases' => [
'#uploads' => 'uploads/csv',
],
Or in
'params' => [
'adminEmail' => 'admin#example.com',
'uploadCsv' => 'uploads/csv/',
];
If I am using the Yii Advanced template I prefer using the alias option.For the Yii basic template any will be fine.
Example: in the common/config/bootstrap.php of Advanced template
Yii::setAlias('#uploads', dirname(__DIR__) . '/uploads/csv');
Is it possible to use two or more caching storage in yii2 framework? I already setup a Memcache for my web app but I wanted also to use a FileCache since I will be dealing with a large chunk of data.
hope someone can help. Thanks!
You can set any cache. Just set it at config file.
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'memCache' => [
'class' => 'MEMCACHE CLASS HERE',
],
.... ANY cache you want ...
]
You can register multiple cache application components. The component named cache is used by default by many cache-dependent classes (e.g. yii\web\UrlManager).
Official link
'components' => [
'cache' => [
'class' => 'yii\caching\MemCache',
],
'fileCache' => [
'class' => 'yii\caching\FileCache',
]
]
I am working on yii2 framework.This is new framework for me. I want to setup multiple language. I tried some way but didn't got success. Can anyone please suggest me simplest way ? What should i have to do ?
I am using this reference link
http://techisworld.com/working-with-multiple-languages-app-in-yii2-framework-using-i18n-system.html
1- For dynamic content (coming from database) I usually use this:
webvimark/multilanguage
It is very easy and isolated from your app DB tables structure and code, that gives flexibility in adding/removing languages at the long term.
2- For static content (words inside the markup) in frontend as an example:
add the lines in your frontend/config/main.php file,
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
'sourceLanguage' => 'en_US',
'fileMap' => [
'app' => 'app.php'
],
],
],
],
Put you translation file app.php file inside /frontend/messages, as any Yii translation file it returns an array of translations in a key-value pairs.
Then you can translate your static content using:
Yii::t('app', 'text to be translated')
I'm trying to find a way to use custom Gii templates for Yii 2, but looking at the missing documentation in the docs, I assume it's not possible yet?
Or am I missing something?
Copy ie. the crud generator templates from gii/generators/crud/templates to your application app/templates/mycrud.
Then define the templates in your config:
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'generators' => [
'crud' => [
'class' => 'yii\gii\generators\crud\Generator',
'templates' => ['mycrud' => '#app/templates/mycrud']
]
]
];
Until the documentation is finished you may also have a look at my Gii extension how to create a custom generator and templates.