PHP变量问题

发布于 2024-10-09 13:48:10 字数 1232 浏览 4 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷乱花海 2024-10-16 13:48:11

创建受保护的方法来执行此操作并将 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']);
  } 
}

Create protected method to do this and pass store as an argument.
This will solve your problem.

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']);
  } 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文