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');
Related
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',
],
],
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.
In Yii 1.x you have the CWebLogRoute class to log all your queries and stuff in your browser. Is this option already available for Yii 2.0? I only see the FileTarget, DbTarget and EmailTarget classes in the framework.
The correct answer:
return [
'bootstrap' => ['debug'],
'modules' => [
'debug' => 'yii\debug\Module',
// ...
],
];
It's called debugger now in Yii 2.0. To enable it, put this in your configuration:
'preload' => ['debug'],
'modules' => [
'debug' => 'yii\debug\Module'
],
I'm following the method described here to have my control panel in backend folder.
The problem is I don't want to create two assets folders so I want to set assetManager baseUrl property in my backend/config/main.php but I'm enable to get the URL of the backend in the config. I don't want it hard coded because I need the code to be portable.
What can I do?
Thanks.
You can configure asset manager's baseUrl in /backend/config/main.php
'components' => array(
...
'assetManager' => array(
'class' => 'CAssetManager',
'baseUrl' => 'frontend.assets'
),
...