[英]PHP variable issue
我的PHP变量有问题,并将它们设置为正确的值。 基本上,我有一种方法可以查看您是否存在商店,以及该商店是否有姊妹商店。 然后,我查看该文件是否存储为文件系统中的图像(如果没有显示)并等待图像图像。
我的问题是,如果商店有姐妹商店,那么它将仅显示姐妹商店的图像,因为姐妹商店和主商店都是我的代码
if(isset($storelocation)) {
//var_dump($sofalocation);
$path = $_SERVER{'DOCUMENT_ROOT'}.'/webroot/images/stores/'.strtolower(str_replace(' ', '-', $storelocation['storename'])).'.jpg';
if(file_exists($path)) {
//echo $path;
$this->assign('storeimage', 'images/stores/'.strtolower(str_replace(' ', '-', $storelocation['storename'])).'.jpg');
//var_dump($sofalocation['storename']);
} else {
echo $path;
$this->assign('storeimage', 'images/stores/awaiting-image.jpg');
}
}
if(isset($sisterlocation)) {
$path = $_SERVER{'DOCUMENT_ROOT'}.'/webroot/images/stores/'.strtolower(str_replace(' ', '-', $sisterlocation['storename'])).'.jpg';
if(file_exists($path)) {
$this->assign('sisterimage', 'images/stores/'.strtolower(str_replace(' ', '-', $sisterglocation['storename'])).'.jpg');
} else {
echo $path;
$this->assign('sisterimage', 'images/stores/awaiting-image.jpg');
// var_dump($sisterlocation['storename']);
}
}
奇怪的是,除非我在isset之前回显var,否则storelocation isset似乎会失败,有什么想法吗?
创建受保护的方法来执行此操作,并将store作为参数传递。 这样可以解决您的问题。
protected function _prepareImage( $storeName, $storeLocation )
{
$path = $_SERVER{'DOCUMENT_ROOT'}.'/webroot/images/stores/'.strtolower(str_replace(' ', '-', $storeLocation['storename'])).'.jpg';
if(file_exists($path)) {
$this->assign($storeName, 'images/stores/'.strtolower(str_replace(' ', '-', $storeLocation['storename'])).'.jpg');
} else {
echo $path;
$this->assign($storeName, 'images/stores/awaiting-image.jpg');
// var_dump($storeLocation['storename']);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.