i am using yii2 advanced template.and i dont understand how to use DbMessageSource.i read the guide and i created two tables source_message and message and i wrote in my common/config/main.php file this code
'*'=> [
'class' => 'yii\i18n\DbMessageSource',
'sourceMessageTable'=>'{{%source_message}}',
'messageTable'=>'{{%message}}',
'enableCaching' => true,
'cachingDuration' => 3600
],
and what i have to write in brackets when i using <?= Yii::t()?>
P.S. i am also changed language in my config.
P.P.S. i generated models and cruds for this tables
try this:
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\DbMessageSource',
'forceTranslation'=>true,
]
],
],
set parameter forceTranslation as true. This trick helps me.
Related
i want to rewrite my URLs from
/view?id=100
to
/view/100-article-title
But the site already has several thousand search pages. As far as I know, such a change can be bad for SEO. Is there a way to keep the old URLs working when switching to the new routing.
*I am creating links as follows:
Url::to(['view', 'id' => $item->id])
Is it possible to create links further through ID?
you can create getLink() function on your model and use it on. Then, when function runs you can check id if id <= 100 then return Url::to(['view', 'id' => $item->id]) else return Url::to(['view', 'id' => $item->id, 'slug' => $this->slug])
And add route with slug on your main.php
Look at my example.
First config urlManager in config.php in 'app/config' folder. In my case look like:
'components' => [
...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
''=>'home/index',
'<slugm>-<id:\d+>-' => 'home/view',
],
],
.
...
],
and create link as fallow:
Url::to(['/home/view', 'id' => $model->home_id, 'slugm' =>$model->title_sr_latn])
and finaly url look like:
https://primer.izrada-sajta.rs/usluge-izrade-sajtova-1-
Hello there I am supposed to transfer artisan logs to bigquery and store it. I wrote Custom Channel
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'bigquery'],
],
'bigquery' => [
'driver' => 'custom',
'level' => 'debug',
'via' => BigQueryHandler ::class,
'with' => [
'bq_dataset_name' => 'something',
'bq_table_name' => 'something_com_logs'
]
],
I have wrote BigQueryHandler class to write those logs using write() method. I have also wrote test case which works fine and updates the record in bigquery table. but If I invoke bigquery channel from artisan files it doesnt work. Can someone tell me whats wrong here?
the command to invoke bigquery channel is
\Log::channel('bigquery')->info('Something happened!');"
Have written it inside handle().
In yii2, i want to override some core messages translation, example:
in #yii/messages/vi/yii.php, has key => translated message:
'Update' => 'Sửa'
but in my application, i want to change this as:
'Update' => 'Cập nhật'
I have created the file: #app/messages/vi/yii.php, has only one the message which need to override:
return [
'Update' => 'Cập nhật'
];
in my main.php config, I added this to components:
'i18n' => [
'translations' => [
'yii' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages'
],
],
],
It works but just only for the override messages, others of core don't work.
I think you should copy yii.php from core to #common/messages/<your language>/yii.php and edit it. It should be work stable.
Try somehing like this
'i18n'=>[
'yii'=>[
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => "#vendor/yiisoft/yii2/messages",
'sourceLanguage' => 'en_US', // put your language here
'fileMap' => [
'yii'=>'yii.php',
]
]
]
],
Might be outdated thread but I'm putting this in case someone hits this in a search results as I did.
This works out for me :
// get the default translation file for desired language
$yii = require \Yii::getAlias('#vendor/yiisoft/yii2/messages/az/yii.php');
// just override what ever you want
return yii\helpers\ArrayHelper::merge( $yii,
[
'update' => 'myUpdateString',
// ... and so on
]);
Trying to restrict a compareWith to just on create
$validator->add('password', [
'compare' => [
'rule' => ['compareWith', 'password_confirmation']]]);
I cant seem to work out how to do it added 'create' to the end like
$validator->add('password', [
'compare' => [
'rule' => ['compareWith', 'password_confirmation']]],'create');
in fact i have tried the 'create' in many places either build errors or still validating on an edit
Appreciate any help
Try this:
$validator->add("password", "compare", [
"rule" => ["compareWith", "password_confirmation"],
"message" => __("Password and password confirmation fields don't match."),
"on" => "create"
]);
This will certainly work.
Hope this helps.
Peace! xD
I am using CodeIgniter 2.1.3, and HMVC by Wiredesignz.
How can I include a custom form_validation configuration file in the module's folder (in application/modules/user/config/form_validation.php) as opposed to the central config folder (application/config/form_validation.php)?
Edit I have accepted Salvador's answer, due to his suggestion in the comments.
<?php
$config=[
'add_article_rules' => [
[
'field' => 'title',
'label' => 'Article Title',
'rules' => 'required|alpha'
],
[
'field'=>'body',
'label'=>'Article Body',
'rules'=>'required',
]
],
'admin_login' => [
[
'field'=> 'username',
'label'=> 'User Name',
'rules'=> 'required|alpha|trim',
],
[
'field'=>'password',
'label'=>'password',
'rules'=>'required',
]
]
];
?>
Why in config?
There is a better way, you can use it in application/libaries/MY_form_validation.php
There you can safely modify the form_validation class o add new features.
Check this or this