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

目錄
環(huán)境變量
示例
常規(guī)配置
Databases Configuration
Config/app_local.php
config/app.php
Email Configuration
Email Configuration Transport
Email Delivery Profiles
首頁(yè) 后端開(kāi)發(fā) php教程 CakePHP 項(xiàng)目配置

CakePHP 項(xiàng)目配置

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

本章我們將了解CakePHP中的環(huán)境變量、常規(guī)配置、數(shù)據(jù)庫(kù)配置郵件配置。

配置 CakePHP 默認(rèn)自帶一個(gè)配置文件,我們可以根據(jù)自己的需要進(jìn)行修改。為此,有一個(gè)專用文件夾 “config”。 CakePHP 具有不同的配置選項(xiàng)。

讓我們從了解 CakePHP 中的環(huán)境變量開(kāi)始。

環(huán)境變量

環(huán)境變量使您的應(yīng)用程序在不同環(huán)境下的工作變得容易。例如,在開(kāi)發(fā)服務(wù)器、測(cè)試服務(wù)器、登臺(tái)服務(wù)器和生產(chǎn)服務(wù)器環(huán)境上。對(duì)于所有這些環(huán)境,您可以使用 env() 函數(shù) 讀取所需環(huán)境的配置并構(gòu)建您的應(yīng)用程序。

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

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

示例

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

第一個(gè)是您想要的環(huán)境變量的名稱,第二個(gè)值是默認(rèn)值。如果沒(méi)有找到環(huán)境變量的值,則使用默認(rèn)值。

常規(guī)配置

下表描述了各種變量的作用以及它們?nèi)绾斡绊懩?CakePHP 應(yīng)用程序。

表>

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 變量名稱和描述
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 調(diào)試輸出。 false = 生產(chǎn)模式。沒(méi)有顯示錯(cuò)誤消息、錯(cuò)誤或警告。 true = 顯示錯(cuò)誤和警告。
2 App.namespace 用于在其下查找應(yīng)用程序類的命名空間。
3 App.baseUrl 如果您不打算將 Apache 的 mod_rewrite 與 CakePHP 一起使用,請(qǐng)取消注釋此定義。不要忘記也刪除您的 .htaccess 文件。
4 App.base 應(yīng)用程序所在的基本目錄。如果為 false,則會(huì)自動(dòng)檢測(cè)到。
5 App.encoding 定義您的應(yīng)用程序使用的編碼。此編碼用于生成布局中的字符集并對(duì)實(shí)體進(jìn)行編碼。它應(yīng)該與為您的數(shù)據(jù)庫(kù)指定的編碼值匹配。
6 App.webroot webroot 目錄。
7 App.wwwRoot webroot 的文件路徑。
8 App.fullBaseUrl 應(yīng)用程序根目錄的完全限定域名(包括協(xié)議)。
9 App.imageBaseUrl webroot 下公共圖像目錄的 Web 路徑。
10 App.cssBaseUrl webroot 下公共 css 目錄的 Web 路徑。
11 App.jsBaseUrl webroot下公共js目錄的Web路徑。
12 App.paths 配置非基于類的資源的路徑。支持插件、模板、語(yǔ)言環(huán)境、子項(xiàng),它們?cè)试S分別定義插件、視圖模板和語(yǔ)言環(huán)境文件的路徑。
13 Security.salt 用于散列的隨機(jī)字符串。在進(jìn)行對(duì)稱加密時(shí),該值也用作 HMAC salt。
14 資產(chǎn).時(shí)間戳 使用正確的幫助程序時(shí),在資產(chǎn)文件 URL(CSS、JavaScript、圖像)末尾附加一個(gè)時(shí)間戳,即特定文件的最后修改時(shí)間。有效值為 -
  • (bool) false - 不執(zhí)行任何操作(默認(rèn))。
  • (bool) true - 當(dāng) debug 為 true 時(shí)附加時(shí)間戳。
  • (string) ‘force’ - 始終附加時(shí)間戳。
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 項(xiàng)目配置的詳細(xì)內(nèi)容。更多信息請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動(dòng)的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機(jī)

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強(qiáng)大的PHP集成開(kāi)發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)代碼編輯軟件(SublimeText3)

如何升級(jí)PHP版本? 如何升級(jí)PHP版本? Jun 27, 2025 am 02:14 AM

升級(jí)PHP版本其實(shí)不難,但關(guān)鍵在于操作步驟和注意事項(xiàng)。以下是具體方法:1.確認(rèn)當(dāng)前PHP版本及運(yùn)行環(huán)境,使用命令行或phpinfo.php文件查看;2.選擇適合的新版本并安裝,推薦8.2或8.1,Linux用戶用包管理器安裝,macOS用戶用Homebrew;3.遷移配置文件和擴(kuò)展,更新php.ini并安裝必要擴(kuò)展;4.測(cè)試網(wǎng)站是否正常運(yùn)行,檢查錯(cuò)誤日志確保無(wú)兼容性問(wèn)題。按照這些步驟操作,大多數(shù)情況都能順利完成升級(jí)。

如何防止PHP中的跨站點(diǎn)偽造偽造(CSRF)攻擊? 如何防止PHP中的跨站點(diǎn)偽造偽造(CSRF)攻擊? Jun 28, 2025 am 02:25 AM

TopreventCSRFattacksinPHP,implementanti-CSRFtokens.1)Generateandstoresecuretokensusingrandom_bytes()orbin2hex(random_bytes(32)),savethemin$_SESSION,andincludetheminformsashiddeninputs.2)ValidatetokensonsubmissionbystrictlycomparingthePOSTtokenwiththe

PHP初學(xué)者指南:當(dāng)?shù)丨h(huán)境配置的詳細(xì)說(shuō)明 PHP初學(xué)者指南:當(dāng)?shù)丨h(huán)境配置的詳細(xì)說(shuō)明 Jun 27, 2025 am 02:09 AM

要設(shè)置PHP開(kāi)發(fā)環(huán)境,需選擇合適的工具并正確安裝配置。①最基礎(chǔ)的PHP本地環(huán)境需要三個(gè)組件:Web服務(wù)器(Apache或Nginx)、PHP本身和數(shù)據(jù)庫(kù)(如MySQL/MariaDB);②推薦初學(xué)者使用集成包如XAMPP或MAMP,它們簡(jiǎn)化了安裝流程,XAMPP適用于Windows和macOS,安裝后將項(xiàng)目文件放入htdocs目錄并通過(guò)localhost訪問(wèn);③MAMP適合Mac用戶,支持便捷切換PHP版本,但免費(fèi)版功能有限;④高級(jí)用戶可用Homebrew手動(dòng)安裝,在macOS/Linux系統(tǒng)中

如何將兩個(gè)PHP陣列組合獨(dú)特的值? 如何將兩個(gè)PHP陣列組合獨(dú)特的值? Jul 02, 2025 pm 05:18 PM

要合并兩個(gè)PHP數(shù)組并保留唯一值,有兩種主要方法。1.對(duì)于索引數(shù)組或僅需值去重的情況,使用array_merge和array_unique組合:先用array_merge($array1,$array2)合并數(shù)組,再用array_unique()去重,最終得到包含所有唯一值的新數(shù)組;2.對(duì)于關(guān)聯(lián)數(shù)組且希望保留第一個(gè)數(shù)組中的鍵值對(duì)時(shí),使用 運(yùn)算符:$result=$array1 $array2,這將確保第一個(gè)數(shù)組中的鍵不會(huì)被第二個(gè)數(shù)組覆蓋。這兩種方法分別適用于不同場(chǎng)景,根據(jù)是否需要保留鍵名或只關(guān)注

如何使用PHP退出功能? 如何使用PHP退出功能? Jul 03, 2025 am 02:15 AM

exit()是PHP中用于立即終止腳本執(zhí)行的函數(shù),常見(jiàn)用途包括:1.在檢測(cè)到異常情況時(shí)提前終止腳本,如文件不存在或驗(yàn)證失??;2.調(diào)試時(shí)輸出中間結(jié)果并停止執(zhí)行;3.結(jié)合header()重定向后調(diào)用exit()防止后續(xù)代碼執(zhí)行;此外,exit()可接受字符串參數(shù)作為輸出內(nèi)容或整數(shù)作為狀態(tài)碼,其別名為die()。

將語(yǔ)義結(jié)構(gòu)應(yīng)用于html的文章,部分和旁邊 將語(yǔ)義結(jié)構(gòu)應(yīng)用于html的文章,部分和旁邊 Jul 05, 2025 am 02:03 AM

在HTML中合理使用語(yǔ)義化標(biāo)簽?zāi)芴嵘?yè)面結(jié)構(gòu)清晰度、可訪問(wèn)性和SEO效果。1.用于獨(dú)立內(nèi)容區(qū)塊,如博客文章或評(píng)論,需保持自包含性;2.用于歸類相關(guān)內(nèi)容,通常包含標(biāo)題,適用于頁(yè)面不同模塊;3.用于與主內(nèi)容相關(guān)但非核心的輔助信息,如側(cè)邊欄推薦或作者簡(jiǎn)介。實(shí)際開(kāi)發(fā)中應(yīng)結(jié)合、等標(biāo)簽,避免過(guò)度嵌套,保持結(jié)構(gòu)簡(jiǎn)潔,并通過(guò)開(kāi)發(fā)者工具驗(yàn)證結(jié)構(gòu)合理性。

如何訪問(wèn)PHP中的會(huì)話數(shù)據(jù)? 如何訪問(wèn)PHP中的會(huì)話數(shù)據(jù)? Jun 30, 2025 am 01:33 AM

在PHP中訪問(wèn)會(huì)話數(shù)據(jù)需先啟動(dòng)會(huì)話,再通過(guò)$_SESSION超全局?jǐn)?shù)組進(jìn)行操作。1.啟動(dòng)會(huì)話必須使用session_start(),且該函數(shù)需在任何輸出前調(diào)用;2.訪問(wèn)會(huì)話數(shù)據(jù)時(shí)應(yīng)檢查鍵是否存在,可使用isset($_SESSION['key'])或array_key_exists('key',$_SESSION);3.設(shè)置或更新會(huì)話變量只需對(duì)$_SESSION數(shù)組賦值,無(wú)需手動(dòng)保存;4.清除特定數(shù)據(jù)可用unset($_SESSION['key']),清空所有數(shù)據(jù)可設(shè)$_SESSION為空數(shù)組,

PHP中的遞歸功能是什么? PHP中的遞歸功能是什么? Jun 29, 2025 am 02:02 AM

遞歸函數(shù)在PHP中指自我調(diào)用的函數(shù),其核心要素是1.定義終止條件(基例),2.分解問(wèn)題并遞歸調(diào)用自身(遞歸例)。它適用于處理分層結(jié)構(gòu)、拆解重復(fù)子問(wèn)題或提升代碼可讀性,如計(jì)算階乘、遍歷目錄等。但需注意內(nèi)存消耗及棧溢出風(fēng)險(xiǎn)。編寫時(shí)應(yīng)明確退出條件、確保逐步逼近基例、避免冗余參數(shù)、優(yōu)先測(cè)試小輸入。例如掃描目錄時(shí),函數(shù)遇子目錄即遞歸調(diào)用自身,直到所有層級(jí)遍歷完畢。

See all articles