开发者

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

I开发者_运维知识库 would like to be able use custom constants in my zend framework like this

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

where FILE_UPLOAD_DESTINATION would be a path predefined in some other file. So that later when i need to change this path, rather than hunting down line by line, i can simply change a particular constant in one central file.

i know i can be done easily using include in normal PHP scripts but i was hoping if there is similar functionality built into ZF.


You can define the path in your application.ini and in your Bootsrap.php you can make a constant for this path. For example:

in application.ini:

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

and in Bootstrap.php you can do:

protected function _initMakeFileUploadConsant() {

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

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

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

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜