Php css文件中的动态内容
我正在修改一个web应用程序。它允许用户为标签颜色、背景颜色和字体颜色输入十六进制值。当用户输入值并单击“更新模板”时。我需要能够根据用户输入的十六进制值更新背景色、标签色和字体颜色。我将标签颜色、背景颜色和字体颜色以及其他模板信息存储在MySQL表中。我可以在控制视图的所有Php css文件中的动态内容,php,css,zend-framework,Php,Css,Zend Framework,我正在修改一个web应用程序。它允许用户为标签颜色、背景颜色和字体颜色输入十六进制值。当用户输入值并单击“更新模板”时。我需要能够根据用户输入的十六进制值更新背景色、标签色和字体颜色。我将标签颜色、背景颜色和字体颜色以及其他模板信息存储在MySQL表中。我可以在控制视图的所有.phtml文件中执行以下操作: $Idtemplate = $this->user->defaultTemplate; $Objtemplate = new Template(); $Thetemplate =
.phtml
文件中执行以下操作:
$Idtemplate = $this->user->defaultTemplate;
$Objtemplate = new Template();
$Thetemplate = $Objtemplate->fetchRow("id=" . $Idtemplate);
$Title_Shiprequest = $Thetemplate->descriptionShipRequestTitle;
$clabel = $Thetemplate->descriptionlabelColor;
$cbackground = $Thetemplate->descriptionBkgColor;
$cfont =$Thetemplate->descriptionFontColor;
$clabel
,$cbackground
,$cfont
用于.phtml
中的颜色样式
问题是大约有34个.phtml
文件。如果我想这样做,我必须找到负责颜色的div类,并在那里进行相应的更改。对我来说,这听起来是一个非常低效和冗长的解决方案
但是css文件中大约有4-5个类,其中定义并使用了所有颜色值。对我来说,在css文件中执行类似上述代码的操作(唯一的问题是它在css文件中不起作用)并像下面那样引用它们(我已将我的common.css
重命名为common.php
):
(以及相应功能中的$cbackground和$cfont)带有
它停止工作了。因此,我将getdata.php移动到models Make类,该类包含上述所有函数:
<?php
Class fetchData extends Template
{
function getLabelColor() {
$Idtemplate = 101// I had assign a known value here. I was not able to use $this->user->defaultTemplate; Not sure why I wont be able to use $this
$Objtemplate = new Template();
$Thetemplate = $Objtemplate->fetchRow("id=" . $Idtemplate);
$clabel = $Thetemplate->descriptionlabelColor;//for future usage for dynamic color
return ('#'.$clabel);
}
function getBkgColor() {
$Idtemplate = 101// I had assign a known value here. I was not able to use $this->user->defaultTemplate; Not sure why I wont be able to use $this
$Objtemplate = new Template();
$Thetemplate = $Objtemplate->fetchRow("id=" . $Idtemplate);
$cbackground = $Thetemplate->descriptionBkgColor;//for future usage for dynamic color
return ('#'.$cbackground);
}
function getFontColor() {
$Idtemplate = 101// I had assign a known value here. I was not able to use $this->user->defaultTemplate; Not sure why I wont be able to use $this
$Objtemplate = new Template();
$Thetemplate = $Objtemplate->fetchRow("id=" . $Idtemplate);
$cfont =$Thetemplate->descriptionFontColor;//for future usage for dynamic color
return ('#'.$cfont);
}
}
?>
这只适用于.phtml,而不适用于common.php。我认为common.php不允许实例化对象
PS:这是我的common.php调用的样子:
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseUrl();?>/css/common.php" />
在common.php
中将此行添加为页面的第一行:
.panel1
{
width: auto;
height: 22px;
background-color: <?= $cbackground ?>;
padding: 5px;
}
header("Content-type: text/css");
你只要使用
<link rel="stylesheet" type="text/css" media="screen" href="/css/mycss.php" />
然后可以在css中使用php。您可以使用php中的标题添加适当的标题(text/css)
// mycss.php
<?php
header("content-type:text/css");
?>
<style type='text/css'>
// Stylesheet
</style>
//mycss.php
//样式表
我遇到了与您相同的问题,然后我将十六进制颜色更改为数据库中颜色的名称,一切正常。我不知道为什么十六进制颜色不能像其他文本一样显示出来,但无论如何,只需更改颜色名称:
E.I.:白色表示#FFFFFF
我希望这对你有帮助
编辑:我认为这也会有帮助,
插入到数据库时,使用hexdec();从数据库显示时,使用dechex()。
dechex将返回不带散列(#)的十六进制,因此您可能需要这样打印:
<?php echo "#".dechex($decimal_number); ?>
我希望这是有用的,伙计。注意,标题
调用应该出现在任何输出之前,甚至是空格/换行符。否则PHP将抛出一个“headers ready sent”错误。不,它不会被解决。请参阅上面的更新。
$Idtemplate = $this->user->defaultTemplate;
$Objtemplate = new Template();
$Thetemplate = $Objtemplate->fetchRow("id=" . $Idtemplate);
$clabel = $Thetemplate->descriptionlabelColor;
return ('#'.$clabel);
<?php
Class fetchData extends Template
{
function getLabelColor() {
$Idtemplate = 101// I had assign a known value here. I was not able to use $this->user->defaultTemplate; Not sure why I wont be able to use $this
$Objtemplate = new Template();
$Thetemplate = $Objtemplate->fetchRow("id=" . $Idtemplate);
$clabel = $Thetemplate->descriptionlabelColor;//for future usage for dynamic color
return ('#'.$clabel);
}
function getBkgColor() {
$Idtemplate = 101// I had assign a known value here. I was not able to use $this->user->defaultTemplate; Not sure why I wont be able to use $this
$Objtemplate = new Template();
$Thetemplate = $Objtemplate->fetchRow("id=" . $Idtemplate);
$cbackground = $Thetemplate->descriptionBkgColor;//for future usage for dynamic color
return ('#'.$cbackground);
}
function getFontColor() {
$Idtemplate = 101// I had assign a known value here. I was not able to use $this->user->defaultTemplate; Not sure why I wont be able to use $this
$Objtemplate = new Template();
$Thetemplate = $Objtemplate->fetchRow("id=" . $Idtemplate);
$cfont =$Thetemplate->descriptionFontColor;//for future usage for dynamic color
return ('#'.$cfont);
}
}
?>
include('C:/sr/application/models/getdata.php');
$datafetchObj = new fetchData();
$clabel = $datafetchObj->getLabelColor(); //purple 51:0:153
$cbackground = $datafetchObj->getBkgColor(); //Light blue 102:102:204
$cfont = $datafetchObj->getFontColor();
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseUrl();?>/css/common.php" />
header("Content-type: text/css");
<link rel="stylesheet" type="text/css" media="screen" href="/css/mycss.php" />
// mycss.php
<?php
header("content-type:text/css");
?>
<style type='text/css'>
// Stylesheet
</style>
<?php echo "#".dechex($decimal_number); ?>