国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

目次
ステップ 4
出力
メール
Example
Output

CakePHP の國際化

Sep 10, 2024 pm 05:26 PM
php cakephp PHP framework

他の多くのフレームワークと同様、CakePHP も國際化をサポートしています。単一言語から複數(shù)言語に移行するには、次の手順に従う必要があります。

ステップ 1

別のロケール ディレクトリ リソースを作成しますlocales.

ステップ 2

ディレクトリ srcLocale の下に、言語ごとにサブディレクトリを作成します。サブディレクトリの名前は、言語の 2 文字の ISO コード、または en_US、fr_FR などの完全なロケール名にすることができます。

ステップ 3

各言語サブディレクトリの下に個別の default.po ファイルを作成します。このファイルには、次のプログラムに示すように、msgid および msgstr の形式のエントリが含まれています。

msgid "msg"
msgstr "CakePHP Internationalization example."

ここで、msgid はビュー テンプレート ファイルで使用されるキーであり、msgstr は翻訳を保存する値です。

ステップ 4

View テンプレート ファイルでは、以下に示すように、上記の msgid を使用できます。これはロケールの設(shè)定値に基づいて翻訳されます。

<?php echo __('msg'); ?>

デフォルトのロケールは、config/app.php ファイルで次の行で設(shè)定できます。

'defaultLocale' => env('APP_DEFAULT_LOCALE', 'en_US')

実行時にローカルを変更するには、次の行を使用できます。

use Cake\I18n\I18n;
I18n::locale('de_DE');

次のプログラムに示すように、config/routes.php ファイルを変更します。

config/routes.php

<?php use Cake\Http\Middleware\CsrfProtectionMiddleware;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
$routes->setRouteClass(DashedRoute::class);
$routes->scope('/', function (RouteBuilder $builder) {
   $builder->registerMiddleware('csrf', new CsrfProtectionMiddleware([
      'httpOnly' => true,
   ]));
   $builder->applyMiddleware('csrf');
   //$builder->connect('/pages',
      ['controller'=>'Pages','action'=>'display', 'home']);
   $builder->connect('locale',
      ['controller'=>'Localizations','action'=>'index']);
   $builder->fallbacks();
});

src/Controller/LocalizationsController.php に LocalizationsController.php ファイルを作成します。 コントローラー ファイルに次のコードをコピーします。

src/Controller/LocalizationsController.php

<?php namespace App\Controller;
   use App\Controller\AppController;
   use Cake\I18n\I18n;
   class LocalizationsController extends AppController {
      public function index() {
         if($this->request->is('post')) {
            $locale = $this->request->getData('locale');
            I18n::setLocale($locale);
         }
      }
   }
?>

resourceslocaleslocales ディレクトリを作成します。 locales ディレクトリの下に、en_US、fr_FR、de_DE という 3 つのディレクトリを作成します。各ディレクトリの下に default.po. というファイルを作成し、それぞれのファイルに次のコードをコピーします。

resources/locales/en_US/default.po

msgid "msg"
msgstr "CakePHP Internationalization example."

resources/locales/fr_FR/default.po

msgid "msg"
msgstr "Exemple CakePHP internationalisation."

resources/locales/de_DE/default.po

msgid "msg"
msgstr "CakePHP Internationalisierung Beispiel."

src/Template にディレクトリ Localizations を作成し、そのディレクトリの下に index.php. という名前の View ファイルを作成します。そのファイル內(nèi)の次のコード。

src/Template/Localizations/index.php

Form->create(NULL,array('url'=>'/locale'));
   echo $this->Form->radio("locale",
      [
         ['value'=>'en_US','text'=>'CakePHP の國際化'],
         ['value'=>'de_DE','text'=>'German'],
         ['value'=>'fr_FR','text'=>'French'],
      ]
   );
   echo $this->Form->button('Change Language');
   echo $this->Form->end();
?>
<?php echo __('msg'); ?>

次の URL にアクセスして、上記の例を?qū)g行します。 http://localhost/cakephp4/locale

出力

実行すると、次の出力が表示されます。

CakePHP の國際化

メール

CakePHP は、電子メール関連の機(jī)能を管理するための Email クラスを提供します。コントローラーで電子メール機(jī)能を使用するには、まず次の行を記述して電子メール クラスをロードする必要があります。

use Cake\Mailer\Email;

Email クラスは、以下で説明するさまざまな便利なメソッドを提供します。

構(gòu)文
Syntax

From(string|array|null $email null, string|null $name null )

Parameters
  • String with email

  • Name

Returns

array|$this

Description

It specifies from which email address; the email will be sent

From(string|array|null $email null, string|null $name null ) パラメータ
  • 電子メールを含む文字列
    Syntax

    To(string|array|null $emailnull, string|null $namenull)

    Parameters
    • String with email

    • Name

    Returns

    array|$this

    Description

    It specifies to whom the email will be sent

名前
返品
Syntax

Send(string|array|null $contentnull)

Parameters
  • String with message or array with messages.

Returns array
Description

Send an email using the specified content, template and layout

配列|$this 説明
送信元の電子メール アドレスを指定します。メールが送信されます
Syntax

Subject(string|null $subjectnull)

Parameters
  • Subject string

Returns

array|$this

Description

Get/Set Subject

構(gòu)文 To(string|array|null $emailnull, string|null $namenull) パラメータ
  • 電子メールを含む文字列
  • 名前
返品 配列|$this 説明 メールの送信先を指定します 構(gòu)文 Send(string|array|null $contentnull) パラメータ
  • メッセージを含む文字列、またはメッセージを含む配列。
返品 配列 説明 指定されたコンテンツ、テンプレート、レイアウトを使用してメールを送信します 構(gòu)文 件名(文字列|null $subjectnull) パラメータ
  • 件名の文字列
返品 配列|$this 説明 件名の取得/設(shè)定 テーブル>
Syntax

Attachments(string|array|null $attachmentsnull)

Parameters
  • String with the filename or array with filenames

Returns

array|$this

Description

Add attachments to the email message

Syntax

Bcc(string|array|null $emailnull, string|null $namenull)

Parameters
  • String with email

  • Name

Returns

array|$this

Description

Bcc

Syntax

cc( string|array|null $emailnull , string|null $namenull )

Parameters
  • String with email

  • Name

Returns

array|$this

Description

Cc

Example

Make changes in the config/routes.php file as shown in the following program.

config/routes.php

<?php use Cake\Http\Middleware\CsrfProtectionMiddleware;
use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;
$routes->setRouteClass(DashedRoute::class);
$routes->scope('/', function (RouteBuilder $builder) {
   $builder->registerMiddleware('csrf', new CsrfProtectionMiddleware([
      'httpOnly' => true,
   ]));
   $builder->applyMiddleware('csrf');
   //$builder->connect('/pages',['controller'=>'Pages','action'=>'display', 'home']);
   $builder->connect('/email',['controller'=>'Emails','action'=>'index']);
   $builder->fallbacks();
});

Create an EmailsController.php file at src/Controller/EmailsController.php. Copy the following code in the controller file.

src/Controller/EmailsController.php

<?php namespace App\Controller;
   use App\Controller\AppController;
   use Cake\Mailer\Email;
   class EmailsController extends AppController{
      public function index(){
         $email = new Email('default');
         $email->to('abc@gmail.com')
            ->subject('About')
            ->send('My message');
      }
   }
?>

Create a directory Emails at src/Template and under that directory, create a View file called index.php. Copy the following code in that file.

src/Template/Emails/index.php

Email Sent.

Before we send any email, we need to configure it. In the below screenshot, you can see that there are two transports, default and Gmail. We have used Gmail transport.

You need to replace the “GMAIL USERNAME” with your Gmail username and “APP PASSWORD” with your applications password. You need to turn on 2-step verification in Gmail and create a new APP password to send email.

config/app.php

Program App

Execute the above example by visiting the following URL ? http://localhost/cakephp/email

Output

Upon execution, you will receive the following output.

Documents Api

以上がCakePHP の國際化の詳細(xì)內(nèi)容です。詳細(xì)については、PHP 中國語 Web サイトの他の関連記事を參照してください。

このウェブサイトの聲明
この記事の內(nèi)容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰屬します。このサイトは、それに相當(dāng)する法的責(zé)任を負(fù)いません。盜作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡(luò)ください。

ホットAIツール

Undress AI Tool

Undress AI Tool

脫衣畫像を無料で

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード寫真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

寫真から衣服を削除するオンライン AI ツール。

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中國語版

SublimeText3 中國語版

中國語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強(qiáng)力な PHP 統(tǒng)合開発環(huán)境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

最新のPHP開発とベストプラクティスを最新の狀態(tài)に保つにはどうすればよいですか? 最新のPHP開発とベストプラクティスを最新の狀態(tài)に保つにはどうすればよいですか? Jun 23, 2025 am 12:56 AM

postaycurrentwithpdevellyments andbest practices、follow keynewsourceslikephp.netandphpweekly、egagewithcommunitiessonforums andconferences、keeptooling and gradivallyadoptnewfeatures、andreadorcontributeTopensourceprijeprijeprijeptrijeprijeprests.

PHPとは何ですか、そしてなぜそれがWeb開発に使用されるのですか? PHPとは何ですか、そしてなぜそれがWeb開発に使用されるのですか? Jun 23, 2025 am 12:55 AM

PhpBecamepopularforwebdevelopmentduetoitseaseaseaseaseasease、SeamlessintegrationWithhtml、widespreadhostingsupport、andalargeecosystemincludingframeworkelavelandcmsplatformslikewordspresspressinsinsionsisionsisionsisionsisionsionsionsisionsionsionsisionsisions

PHPタイムゾーンを設(shè)定する方法は? PHPタイムゾーンを設(shè)定する方法は? Jun 25, 2025 am 01:00 AM

tosettherighttimezoneInphp、usedate_default_timezone_set()functionthestthestofyourscriptwithavalididentifiersiersuchas'america/new_york'.1.usedate_default_timezone_set()beforeanydate/timefunctions.2.2.Altertentally、confuturethephp.inifilebyset.

PHPでのユーザー入力を検証して、特定の基準(zhǔn)を満たすことを確認(rèn)するにはどうすればよいですか? PHPでのユーザー入力を検証して、特定の基準(zhǔn)を満たすことを確認(rèn)するにはどうすればよいですか? Jun 22, 2025 am 01:00 AM

tovalidateuserinputinphp、usebuilt-validationfunctionslikefilter_var()andfilter_input()、applyRegularexpressionsforcustomformatsusususussusorphoneNumbers、checkdatatypesfornumerueSlikeageorpricepriceprice

PHP(serialize()、unserialize())のデータシリアル化とは何ですか? PHP(serialize()、unserialize())のデータシリアル化とは何ですか? Jun 22, 2025 am 01:03 AM

thephpfunctionSerialize()andunserialize()areusedtoconvertcomplexdatastructostorestorestorustorasandabackagain.1.serialize()c onvertsdatalikecarraysorobjectsraystringcontainingtainingtainingepeandStructureinformation.2。

HTMLファイルにPHPコードを埋め込むにはどうすればよいですか? HTMLファイルにPHPコードを埋め込むにはどうすればよいですか? Jun 22, 2025 am 01:00 AM

PHPコードをHTMLファイルに埋め込むことができますが、ファイルに.phpの拡張機(jī)能があることを確認(rèn)して、サーバーが正しく解析できるようにします。標(biāo)準(zhǔn)タグを使用してPHPコードをラップし、HTMLのどこにでも動的コンテンツを挿入します。さらに、同じファイルでPHPとHTMLを複數(shù)回切り替えて、條件付きレンダリングなどの動的関數(shù)を?qū)g現(xiàn)できます。短いラベル、引用マークエラー、または省略されたエンドラベルによって引き起こされる問題を回避するために、サーバーの構(gòu)成と構(gòu)文の正確性に注意してください。

クリーンで保守可能なPHPコードを書くためのベストプラクティスは何ですか? クリーンで保守可能なPHPコードを書くためのベストプラクティスは何ですか? Jun 24, 2025 am 12:53 AM

清潔で維持しやすいPHPコードを書くための鍵は、標(biāo)準(zhǔn)、合理的な構(gòu)造に従って、コメント、テスト能力を適切に利用する明確な命名にあります。 1。$ userDataやcalculatetotalprice()などの明確な変數(shù)、関數(shù)、クラス名を使用します。 2。PSR-12標(biāo)準(zhǔn)統(tǒng)一コードスタイルに従ってください。 3.責(zé)任に従ってコード構(gòu)造を分割し、MVCまたはLaravelスタイルのカタログを使用して整理します。 4.麺スタイルのコードを避け、単一の責(zé)任でロジックを小さな関數(shù)に分割します。 5.キーポイントにコメントを追加し、インターフェイスドキュメントを書き込み、パラメーター、返品値、例外を明確にします。 6.テスト可能性を改善し、依存関係を採用し、グローバルな狀態(tài)と靜的な方法を減らします。これらのプラクティスは、コードの品質(zhì)、コラボレーション効率、メンテナンス後の容易さを改善します。

See all articles