簡體   English   中英

在zend框架中定義自定義常量或使用預定義常量

[英]defining custom constant or using pre-defined constants in zend framework

我希望能夠在這樣的zend框架中使用自定義常量

$upload->setDestination(FILE_UPLOAD_DESTINATION); //set destination upload dir

其中FILE_UPLOAD_DESTINATION是其他文件中預定義的路徑。 這樣,以后當我需要更改此路徑時,而不是逐行搜索,我只需在一個中央文件中更改一個特定的常量即可。

我知道我可以使用常規PHP腳本中的include輕松完成操作,但我希望ZF中內置類似功能。

您可以在application.ini中定義路徑,在Bootsrap.php中可以為該路徑設置常量。 例如:

在application.ini中:

myvars.fileuploaddir = APPLICATION_PATH "/../public/images"

在Bootstrap.php中,您可以執行以下操作:

protected function _initMakeFileUploadConsant() {

    $myVars = $this->getOption('myvars');

    $imgDir = realpath($myVars['fileuploaddir']);

    defined('FILE_UPLOAD_DESTINATION') || define('FILE_UPLOAD_DESTINATION', $imgDir);

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM