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

目次
環(huán)境変數(shù)
一般的な構(gòu)成
Databases Configuration
Config/app_local.php
config/app.php
Email Configuration
Email Configuration Transport
Email Delivery Profiles
ホームページ バックエンド開発 PHPチュートリアル CakePHP プロジェクトの構(gòu)成

CakePHP プロジェクトの構(gòu)成

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

この章では、CakePHP の 環(huán)境変數(shù)、一般設(shè)定、データベース設(shè)定 および メール設(shè)定 について理解します。

構(gòu)成 CakePHP にはデフォルトで 1 つの構(gòu)成ファイルが付屬しており、必要に応じて変更できます。この目的のために、「config」 という専用のフォルダーが 1 つあります。 CakePHP にはさまざまな設(shè)定オプションが付屬しています。

CakePHP の環(huán)境変數(shù)を理解することから始めましょう。

環(huán)境変數(shù)

環(huán)境変數(shù)を使用すると、さまざまな環(huán)境でアプリケーションを簡単に動作させることができます。たとえば、開発サーバー、テスト サーバー、ステージング サーバー、運(yùn)用サーバー環(huán)境などです。これらすべての環(huán)境について、env() 関數(shù)を使用して、必要な環(huán)境の構(gòu)成を読み取り、アプリケーションを構(gòu)築できます。

config フォルダーに config/.env.example があります。このファイルには、環(huán)境に基づいて変更されるすべての変數(shù)が含まれています。まず、config フォルダー (config/.env) にファイルを作成し、それらの変數(shù)を定義して使用します。追加の変數(shù)が必要な場合は、そのファイルに含めることができます。

以下に示すように、env() 関數(shù)を使用して環(huán)境変數(shù)を読み取ることができます -

$debug = env('APP_DEBUG', false);

最初の値は必要な環(huán)境変數(shù)の名前で、2 番目の値はデフォルト値です。環(huán)境変數(shù)の値が見つからない場合は、デフォルト値が使用されます。

一般的な構(gòu)成

次の表では、さまざまな変數(shù)の役割と、それらが CakePHP アプリケーションにどのような影響を與えるかを説明します。

シニア番號 変數(shù)名と説明 1
Sr.No Variable Name & Description
1

debug

Changes CakePHP debugging output.

false = Production mode. No error messages, errors, or warnings shown.

true = Errors and warnings shown.

2

App.namespace

The namespace to find app classes under.

3

App.baseUrl

Un-comment this definition, if you don’t plan to use Apache’s mod_rewrite with CakePHP. Don’t forget to remove your .htaccess files too.

4

App.base

The base directory the app resides in. If false, this will be auto detected.

5

App.encoding

Define what encoding your application uses. This encoding is used to generate the charset in the layout, and encode entities. It should match the encoding values specified for your database.

6

App.webroot

The webroot directory.

7

App.wwwRoot

The file path to webroot.

8

App.fullBaseUrl

The fully qualified domain name (including protocol) to your application’s root.

9

App.imageBaseUrl

Web path to the public images directory under webroot.

10

App.cssBaseUrl

Web path to the public css directory under webroot.

11

App.jsBaseUrl

Web path to the public js directory under webroot.

12

App.paths

Configure paths for non-class based resources. Supports the plugins, templates, locales, subkeys, which allow the definition of paths for plugins, view templates and locale files respectively.

13

Security.salt

A random string used in hashing. This value is also used as the HMAC salt when doing symmetric encryption.

14

Asset.timestamp

Appends a timestamp, which is last modified time of the particular file at the end of asset files URLs (CSS, JavaScript, Image) when using proper helpers. The valid values are ?

  • (bool) false - Doesn’t do anything (default).

  • (bool) true - Appends the timestamp, when debug is true.

  • (string) ‘force’ - Always appends the timestamp.

デバッグ CakePHP のデバッグ出力を変更します。 false = 本番モード。エラー メッセージ、エラー、警告は表示されません。 true = エラーと警告が表示されます。 2 App.namespace アプリクラスを検索するための名前空間。 3 App.baseUrl CakePHP で Apache の mod_rewrite を使用する予定がない場合は、この定義のコメントを解除します。 .htaccess ファイルも忘れずに削除してください。 4 App.base アプリが存在するベース ディレクトリ。 false の場合、これは自動検出されます。 5 App.encoding アプリケーションが使用するエンコーディングを定義します。このエンコーディングは、レイアウト內(nèi)で文字セットを生成し、エンティティをエンコードするために使用されます。データベースに指定されたエンコード値と一致する必要があります。 6 App.webroot ウェブルート ディレクトリ 7 App.wwwRoot Webroot へのファイル パス。 8 App.fullBaseUrl アプリケーションのルートへの完全修飾ドメイン名 (プロトコルを含む)。 9 App.imageBaseUrl webroot の下にあるパブリック イメージ ディレクトリへの Web パス。 10 App.cssBaseUrl Webroot の下にあるパブリック CSS ディレクトリへの Web パス。 11 App.jsBaseUrl webroot の下にある public js ディレクトリへの Web パス。 12 App.paths 非クラスベースのリソースのパスを構(gòu)成します。 プラグイン、テンプレート、ロケール、サブキーをサポートしており、それぞれプラグイン、ビュー テンプレート、ロケール ファイルのパスを定義できます。 13 セキュリティ.salt ハッシュ化に使用されるランダムな文字列。この値は、対稱暗號化を行うときに HMAC ソルトとしても使用されます。 14 Asset.timestamp 適切なヘルパーを使用する場合、アセット ファイル URL (CSS、JavaScript、畫像) の末尾に特定のファイルの最終変更時刻であるタイムスタンプを追加します。有効な値は - です。
  • (bool) false - 何もしません (デフォルト)。
  • (bool) true - デバッグが true の場合、タイムスタンプを追加します。
  • (文字列) ‘force’ - 常にタイムスタンプを追加します。
テーブル>

Databases Configuration

Database can be configured in config/app.php and config/app_local.php file. This file contains a default connection with provided parameters, which can be modified as per our choice.

The below snippet shows the default parameters and values, which should be modified as per the requirement.

Config/app_local.php

*/
   'Datasources' => [
      'default' => [
         'host' => 'localhost',
         'username' => 'my_app',
         'password' => 'secret',
         'database' => 'my_app',
         'url' => env('DATABASE_URL', null),
      ],
      /*
         * The test connection is used during the test suite.
      */
      'test' => [
         'host' => 'localhost',
         //'port' => 'non_standard_port_number',
         'username' => 'my_app',
         'password' => 'secret',
         'database' => 'test_myapp',
         //'schema' => 'myapp',
      ],
   ],

Let us understand each parameter in detail in config/app_local.php.

Host

The database server’s hostname (or IP address).

username

Database username

password

Database password.

database

Name of Database.

Port

The TCP port or Unix socket used to connect to the server.

config/app.php

'Datasources' => [
   'default' => [
      'className' => Connection::class,
      'driver' => Mysql::class,
      'persistent' => false,
      'timezone' => 'UTC',
      //'encoding' => 'utf8mb4',
      'flags' => [],
      'cacheMetadata' => true,
      'log' => false,
      'quoteIdentifiers' => false,
      //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
   ],
]   

Let us understand each parameter in detail in config/app.php.

log
Sr.No Key & Description
1

className

The fully namespaced class name of the class that represents the connection to a database server. This class is responsible for loading the database driver, providing SQL transaction mechanisms and preparing SQL statements among other things.

2

driver

The class name of the driver used to implement all specificities for a database engine. This can either be a short classname using plugin syntax, a fully namespaced name, or a constructed driver instance. Examples of short classnames are Mysql, Sqlite, Postgres, and Sqlserver.

3

persistent

Whether or not to use a persistent connection to the database.

4

encoding

Indicates the character set to use, when sending SQL statements to the server like ‘utf8’ etc.

5

timezone

Server timezone to set.

6

init

A list of queries that should be sent to the database server as and when the connection is created.

7

log

Set to true to enable query logging. When enabled queries will be logged at a debug level with the queriesLog scope.

8

quoteIdentifiers

Set to true, if you are using reserved words or special characters in your table or column names. Enabling this setting will result in queries built using the Query Builder having identifiers quoted when creating SQL. It decreases performance.

9

flags

An associative array of PDO constants that should be passed to the underlying PDO instance.

10

cacheMetadata

Either boolean true, or a string containing the cache configuration to store meta data in. Having metadata caching disable is not advised and can result in very poor performance.

Email Configuration

Email can be configured in file config/app.php. It is not required to define email configuration in config/app.php. Email can be used without it. Just use the respective methods to set all configurations separately or load an array of configs. Configuration for Email defaults is created using config() and configTransport().

Email Configuration Transport

By defining transports separately from delivery profiles, you can easily re-use transport configuration across multiple profiles. You can specify multiple configurations for production, development and testing. Each transport needs a className. Valid options are as follows ?

  • Mail ? Send using PHP mail function

  • Smtp ? Send using SMTP

  • Debug ? Do not send the email, just return the result

You can add custom transports (or override existing transports) by adding the appropriate file to src/Mailer/Transport. Transports should be named YourTransport.php, where 'Your' is the name of the transport.

Following is the example of Email configuration transport.

'EmailTransport' => [
   'default' => [
      'className' => 'Mail',
      // The following keys are used in SMTP transports
      'host' => 'localhost',
      'port' => 25,
      'timeout' => 30,
      'username' => 'user',
      'password' => 'secret',
      'client' => null,
      'tls' => null,
      'url' => env('EMAIL_TRANSPORT_DEFAULT_URL', null),
   ],
],

Email Delivery Profiles

Delivery profiles allow you to predefine various properties about email messages from your application, and give the settings a name. This saves duplication across your application and makes maintenance and development easier. Each profile accepts a number of keys.

Following is an example of Email delivery profiles.

'Email' => [
   'default' => [
   
      'transport' => 'default',
      'from' => 'you@localhost',
   ],
],

以上がCakePHP プロジェクトの構(gòu)成の詳細(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とは何ですか、そしてなぜそれがWeb開発に使用されるのですか? PHPとは何ですか、そしてなぜそれがWeb開発に使用されるのですか? Jun 23, 2025 am 12:55 AM

PhpBecamepopularforwebdevelopmentduetoitseaseaseaseaseasease、SeamlessintegrationWithhtml、widespreadhostingsupport、andalargeecosystemincludingframeworkelavelandcmsplatformslikewordspresspressinsinsionsisionsisionsisionsisionsionsionsisionsionsionsisionsisions

最新の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タイムゾーンを設(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