I updated Yii2 from version 2.0.13 to the last 2.0.15.1 with php composer.phar update and in the documentation says:
You can start preparing your application for Yii 2.1 by doing the
following:
Replace ::className() calls with ::class (if you’re running PHP 5.5+).
Replace usages of yii\base\InvalidParamException with yii\base\InvalidArgumentException.
Replace calls to Yii::trace() with Yii::debug().
Remove calls to yii\BaseYii::powered().
If you are using XCache or Zend data cache, those are going away in 2.1 so you might want to start looking for an alternative.
like this
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
//
]
]
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
],
];
}
But PhpStorm says "Class name constant is available in PHP 5.5 only
Checks that language features used in the source code correspond the selected language level. (i.e. traits can be used only in PHP 5.4)."
My Php is 7.2.11, what's wrong?
You need to change PHP version in Settings -> Languages & Frameworks -> PHP:
Related
My Folder and code strucure is -
api/
modules/
v1/
controllers/
UserController.php
BaseController.php
Module.php
v2/
controllers/
UserController.php
BaseController.php
Module.php
And my application configuration would look like:
'modules' => [
'v1' => [
'basePath' => '#app/modules/v1',
'class' => 'api\modules\v1\Module'
],
'v2' => [
'basePath' => '#app/modules/v2',
'class' => 'api\modules\v2\Module'
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => ['v2/user']],
['class' => 'yii\rest\UrlRule', 'controller' => ['v1/user']],
],
]
I am following the same procedue as given on yii2 doc But its versioning not working .
UPDATE :
I have created a costume rule and parse according that . Looking for something else .
class ApiUrlRule implements UrlRuleInterface {
public function parseRequest($manager, $request) {
$pathInfo = $request->getPathInfo();
$paramas=$request->getQueryParams();
$version=Yii::$app->response->acceptParams['version'];
$route = Yii::$app->response->acceptParams['version'].'/'.$pathInfo;
return [$route,$paramas];
}
public function createUrl($manager, $route, $params) {
}
}
From the docs you linked:
Both methods have their pros and cons, and there are a lot of debates about each approach. Below you'll see a practical strategy for API versioning that is a mix of these two methods:
Put each major version of API implementation in a separate module whose ID is the major version number (e.g. v1, v2). Naturally, the API URLs will contain major version numbers.
Within each major version (and thus within the corresponding module), use the Accept HTTP request header to determine the minor version number and write conditional code to respond to the minor versions accordingly.
The major api version number is determined by the url, as you've set in your urlManager. You can access them by calling your-yii2-app.com/v1/controller/action or your-yii2-app.com/v2/controller/action. Any code that parses the header must be written by you:
Accept HTTP request header to determine the minor version number and write conditional code to respond to the minor versions accordingly.
If you want to write a custom api version header functionallity, this is possible. I suggest you try and create a new question if you run into trouble.
I am using the Yii2 Framework and I am translating all texts of buttons, labels, messages, etc.
Then I read this article http://www.yiiframework.com/doc-2.0/guide-tutorial-i18n.html that shows how to do it automatically but I don't understand it.
I want to translate to Spanish from Argentina: es-AR or at least to any Spanish.
So I think I need to change from en-US to es-AR but I would like to know which files should I change.
Also I am using the great Gii code generator where I can see a checkbox called Enable I18N.
I watched these files but I am not sure if I am looking the right files:
vendor/yiisoft/yii2/base/Application.php
vendor/yiisoft/yii2/i18n/I18N.php
common/config/main-local.php
Add language propery and i18n component in application config. For advanced application template in common/config/main.php
return [
'language' => 'es-AR',
...
'components' => [
...
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
],
],
],
...
],
]
Use Yii::t() for all user messages (model labels, views, error messages etc).
echo \Yii::t('app', 'Friend');
Create directory messages/es-AR. Create file app.php in this directory and add translations
return [
'Friend' => 'Amigo',
'Girl' => 'Сhica',
...
];
Try to look into the official documentation, it is best tutorial for you. http://www.yiiframework.com/doc-2.0/guide-tutorial-i18n.html
Also, look at this answer yii2 basic multiple language
You can change default language by changing 'language' parameter of your main configuration file. Like this:
return
[
// set target language to be English
'language' => 'en-US',
]
Where instead 'en-US' you must to set needed locale code, e.g. 'es-AR'
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.
Using the config.php always_load configuration, how does one load a language file from a package?
All of the fuelphp documentation alludes to being able to do this, but only shows the syntax for loading from a module.
Here's what I'm trying to do:
fuel/app/config/config.php
'always_load' => [
'language' => [
// loads fuel/app/lang/en/login.php into login group
'login',
],
],
fuel/app/config/production/config.php
'always_load' => [
'language' => [
// override /config/config.php with contents from
// /fuel/packages/pkg/lang/en/login.php
'lang_file_from_package' => 'login',
],
],
Packages are core extensions, which means it will merge the contents of the files found in app and in the package.
As such, there is no method to define you want to load it from the package only, other then by specifying a fully qualified pathname, which will always load just that file.