【发布时间】:2020-09-18 20:53:33
【问题描述】:
我正在尝试编辑具有数据库驱动结果的类。 我使用 Our Code World 的 ColorInterpreter,它是 JavaScript 库 NTC JS 的 PHP 端口。
在这个类中有一个公共变量,它是一个十六进制/颜色名对的数组。这是硬编码到类中的。我想通过使用 DB 输出来实现这一点。
我仍在努力学习课程,所以我无法解决这个问题。
colornames.inc.php: 输出如下:
Array
(
[b0bf1a] => Acid Green
[7cb9e8] => Aero
[c9ffe5] => Aero Blue
[b284be] => African Violet
[00308f] => Air Force Blue (USAF)
[72a0c1] => Air superiority Blue
...
}
ColorInterpreter.php:
class ColorInterpreter
{
public function __construct()
{
$color = null;
$rgb = null;
$hsl = null;
$name = null;
for($i = 0; $i < count($this->names); $i++)
{
$color = "#".$this->names[$i][0];
$rgb = $this->rgb($color);
$hsl = $this->hsl($color);
array_push
(
$this->names[$i],
$rgb[0],
$rgb[1],
$rgb[2],
$hsl[0],
$hsl[1],
$hsl[2]
);
}
}
public function name($color)
{
...
}
// adopted from: Farbtastic 1.2
// http://acko.net/dev/farbtastic
public function hsl($color)
{
...
}
// adopted from: Farbtastic 1.2
// http://acko.net/dev/farbtastic
public function rgb($color)
{
...
}
public function color($name)
{
...
}
// Below is the part I need to replace with the output given from colornames.inc.php
public $names = array(
// Pink colors
array("FFC0CB", "Pink"),
array("FFB6C1", "Light Pink"),
array("FF69B4", "Hot Pink"),
array("FF1493", "Deep Pink"),
array("DB7093", "Pale Violet Red"),
array("C71585", "Medium Violet Red"),
array("E0115F", "Ruby"),
array("FF6FFF", "Ultra"),
...
);
}
我不知道如何、是否或在何处可以/应该包含 colornames.inc.php 而且我不知道在哪里正确声明所需的变量。显然,$this->names 代表硬编码数组,但是如何更改它以反映我拥有的 DB 输出? 我完全迷路了。
【问题讨论】: