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

目錄
環(huán)境變數(shù)
範例
常規(guī)設定
Databases Configuration
Config/app_local.php
config/app.php
Email Configuration
Email Configuration Transport
Email Delivery Profiles
首頁 後端開發(fā) php教程 CakePHP 專案配置

CakePHP 專案配置

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

本章我們將了解CakePHP中的環(huán)境變數(shù)、常規(guī)設定、資料庫設定郵件配置

設定 CakePHP 預設自帶一個設定文件,我們可以依照自己的需求進行修改。為此,有一個專用資料夾 “config”。 CakePHP 具有不同的配置選項。

讓我們先從了解 CakePHP 中的環(huán)境變數(shù)開始。

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

環(huán)境變數(shù)使您的應用程式在不同環(huán)境下的工作變得容易。例如,在開發(fā)伺服器、測試伺服器、登臺伺服器和生產(chǎn)伺服器環(huán)境上。對於所有這些環(huán)境,您可以使用 env() 函數(shù) 讀取所需環(huán)境的配置並建立您的應用程式。

在您的 config 資料夾中,您將看到 config/.env.example。該文件包含將根據(jù)您的環(huán)境進行更改的所有變數(shù)。首先,您可以在 config 資料夾中建立一個文件,即 config/.env 並定義這些變數(shù)並使用它們。如果您需要任何其他變量,可以將其放入該文件中。

您可以使用 env() 函數(shù)讀取環(huán)境變量,如下所示 -

範例

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

第一個是您想要的環(huán)境變數(shù)的名稱,第二個值是預設值。如果沒有找到環(huán)境變數(shù)的值,則使用預設值。

常規(guī)設定

下表描述了各種變數(shù)的作用以及它們?nèi)绾斡绊懩?CakePHP 應用程式。

表>

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.

先生No 變數(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.

調(diào)試 更改 CakePHP 偵錯輸出。 false = 生產(chǎn)模式。沒有顯示錯誤訊息、錯誤或警告。 true = 顯示錯誤和警告。
2 App.namespace 用於在其下尋找應用程式類別的命名空間。
3 App.baseUrl 如果您不打算將 Apache 的 mod_rewrite 與 CakePHP 一起使用,請取消註解此定義。不要忘記也刪除您的 .htaccess 檔案。
4 App.base 應用程式所在的基本目錄。如果為 false,則會自動偵測到。
5 App.encoding 定義您的應用程式使用的編碼。此編碼用於產(chǎn)生佈局中的字元集並對實體進行編碼。它應該與為您的資料庫指定的編碼值相符。
6 App.webroot webroot 目錄。
7 App.wwwRoot webroot 的檔案路徑。
8 App.fullBaseUrl 應用程式根目錄的完全限定網(wǎng)域名稱(包括協(xié)定)。
9 App.imageBaseUrl webroot 下公用映像目錄的 Web 路徑。
10 App.cssBaseUrl webroot 下公用 css 目錄的 Web 路徑。
11 App.jsBaseUrl webroot下公用js目錄的網(wǎng)路路徑。
12 App.paths 配置非基於類別的資源的路徑。支援外掛程式、範本、語言環(huán)境、子項目,它們允許分別定義外掛程式、視圖範本和語言環(huán)境文件的路徑。
13 Security.salt 用於散列的隨機字串。在進行對稱加密時,該值也用作 HMAC salt。
14 資產(chǎn).時間戳 使用正確的幫助程式時,在資產(chǎn)文件 URL(CSS、JavaScript、圖像)末尾附加一個時間戳,即特定文件的最後修改時間。有效值為 -
  • (bool) false - 不執(zhí)行任何操作(預設)。
  • (bool) true - 當 debug 為 true 時附加時間戳記。
  • (string) ‘force’ - 始終附加時間戳。
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 專案配置的詳細內(nèi)容。更多資訊請關注PHP中文網(wǎng)其他相關文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發(fā)現(xiàn)涉嫌抄襲或侵權的內(nèi)容,請聯(lián)絡admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動的應用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

我如何了解最新的PHP開發(fā)和最佳實踐? 我如何了解最新的PHP開發(fā)和最佳實踐? Jun 23, 2025 am 12:56 AM

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

什麼是PHP,為什麼它用於Web開發(fā)? 什麼是PHP,為什麼它用於Web開發(fā)? Jun 23, 2025 am 12:55 AM

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

如何設置PHP時區(qū)? 如何設置PHP時區(qū)? Jun 25, 2025 am 01:00 AM

tosetTherightTimeZoneInphp,restate_default_timezone_set()functionAtthestArtofyourscriptWithavalIdidentIdentifiersuchas'america/new_york'.1.usedate_default_default_timezone_set_set()

我如何驗證PHP中的用戶輸入以確保其符合某些標準? 我如何驗證PHP中的用戶輸入以確保其符合某些標準? Jun 22, 2025 am 01:00 AM

TovalidateuserinputinPHP,usebuilt-invalidationfunctionslikefilter_var()andfilter_input(),applyregularexpressionsforcustomformatssuchasusernamesorphonenumbers,checkdatatypesfornumericvalueslikeageorprice,setlengthlimitsandtrimwhitespacetopreventlayout

什麼是php(serialize(),Unserialize())中的數(shù)據(jù)序列化? 什麼是php(serialize(),Unserialize())中的數(shù)據(jù)序列化? Jun 22, 2025 am 01:03 AM

thephpfunctionserize()andunSerialize()redustoconvertComplexdatStructDestoresToroStoroStoroSandaBackagagain.1.Serialize()

如何將PHP代碼嵌入HTML文件中? 如何將PHP代碼嵌入HTML文件中? Jun 22, 2025 am 01:00 AM

可以將PHP代碼嵌入HTML文件中,但需確保文件以.php為擴展名,以便服務器能正確解析。使用標準的標籤包裹PHP代碼,可在HTML中任意位置插入動態(tài)內(nèi)容。此外,可在同一文件中多次切換PHP與HTML,實現(xiàn)條件渲染等動態(tài)功能。務必注意服務器配置及語法正確性,避免因短標籤、引號錯誤或遺漏結束標籤導致問題。

編寫清潔和可維護的PHP代碼的最佳實踐是什麼? 編寫清潔和可維護的PHP代碼的最佳實踐是什麼? Jun 24, 2025 am 12:53 AM

寫乾淨、易維護的PHP代碼關鍵在於清晰命名、遵循標準、合理結構、善用註釋和可測試性。 1.使用明確的變量、函數(shù)和類名,如$userData和calculateTotalPrice();2.遵循PSR-12標準統(tǒng)一代碼風格;3.按職責拆分代碼結構,使用MVC或Laravel式目錄組織;4.避免麵條式代碼,將邏輯拆分為單一職責的小函數(shù);5.在關鍵處添加註釋並撰寫接口文檔,明確參數(shù)、返回值和異常;6.提高可測試性,採用依賴注入、減少全局狀態(tài)和靜態(tài)方法。這些做法提升代碼質(zhì)量、協(xié)作效率和後期維護便利性。

如何使用PHP執(zhí)行SQL查詢? 如何使用PHP執(zhí)行SQL查詢? Jun 24, 2025 am 12:54 AM

Yes,youcanrunSQLqueriesusingPHP,andtheprocessinvolveschoosingadatabaseextension,connectingtothedatabase,executingqueriessafely,andclosingconnectionswhendone.Todothis,firstchoosebetweenMySQLiorPDO,withPDObeingmoreflexibleduetosupportingmultipledatabas

See all articles