我有以下示例:
我在config \ resources.php中有一个值数组 - 例如:
<?php define('resrc', array( 'logo' => 'src/images/logo.png', 'bscss' => 'src/bootstrap.css', 'bsthcss' => 'src/bootstrap-theme.css', 'bsjs' => 'src/js/bootstrap.js', 'chset' => 'utf-8', 'jquery' => '/src/jquery/jquery_1.12.4_min.js', ) ); ?>现在在结构\ head.php我有这样的事情:
<?php require('config/resources.php'); class Head { public static $head; public static function renderHeadTag() { $head = "<head>"; $head .= "<meta charset=".$resrc['chset'].">"; $head .= "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"; $head .= "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"; $head .= "</head>"; return $head; } } ?>但我仍然无法获得数组的值。 我做这样的事情已经有一段时间了。 任何人都可以暗示一下吗?
I have the following example:
I have an array of values in config\resources.php - eg.:
<?php define('resrc', array( 'logo' => 'src/images/logo.png', 'bscss' => 'src/bootstrap.css', 'bsthcss' => 'src/bootstrap-theme.css', 'bsjs' => 'src/js/bootstrap.js', 'chset' => 'utf-8', 'jquery' => '/src/jquery/jquery_1.12.4_min.js', ) ); ?>Now in the structure\head.php I have something like this:
<?php require('config/resources.php'); class Head { public static $head; public static function renderHeadTag() { $head = "<head>"; $head .= "<meta charset=".$resrc['chset'].">"; $head .= "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"; $head .= "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"; $head .= "</head>"; return $head; } } ?>but I still can't get the value of the array. It is quite a while since i were doing something like this. Can anybody give a hint?
最满意答案
你正在使用常量数组
调用常量不得以美元符号为前缀
这一行:
$head .= "<meta charset=".$resrc['chset'].">";应该如下:
$head .= "<meta charset=".resrc['chset'].">";PS常量遵循一些命名约定,最好用(不一定要)用大写字母命名常量,例如RESRC
you are using a constants array
calling constants must not prefixed with dollar sign
this line :
$head .= "<meta charset=".$resrc['chset'].">";should be as follows :
$head .= "<meta charset=".resrc['chset'].">";P.S. constants following some naming convention , it's better (not must have) to name your constants in capital letters, RESRC for example
更多推荐
发布评论