PHP变量问题
我的 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']);
}
}
奇怪的是,除非我回显,否则 storelocation isset 似乎会失败var 在 isset 之前,有什么想法吗?
I am having an issue with my PHP vars and getting them set to the correct value. Basically I have a method that looks to see if you a store exists and also whether or not that store has a sister store. I then look to see if that store as a image in the file system if it does not i show and awaiting image image.
My issue is that if the store has a sister store then it will only show the image of the sister store, for both the sister and the main store here is my code
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']);
}
}
The curious thing is that the storelocation isset seems to fail unless I echo the var before the isset, has any got any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建受保护的方法来执行此操作并将 store 作为参数传递。
这将解决您的问题。
Create protected method to do this and pass store as an argument.
This will solve your problem.