-5

我是 php 新手,我已经下载了 Contus groupclone 无效代码。我连接到 mysql 数据库,但是当我想运行它时,我得到了这个错误。我的本地服务器是 wamp 2.2 并在 windows vista 上使用 apache 2.2.21 、 php 5.3.8 和 mysql 5.5.16 。如果有人可以帮助我,我将不胜感激。

  public function urlCollections()
  {
      if ($this->isLicense() === true) {
          $attribute = Mage::getmodel("eav/config")->getAttribute("catalog_product", "562");
          $cityValue = array();
        * foreach ($attribute->getSource()->getAllOptions(true, true) as $option) {*
              $cityValue[$option['label']] = $option['value'];
              $storeId                     = Mage::app()->getStore()->getStoreId();
              $city                        = $option['value'];

              if ($city != "") {
                  $cityName     = $option['label'];
                  $cityName     = ereg_replace("[^A-Za-z0-9^-]", "", $cityName);
                  $cityName     = str_replace(" ", "-", $cityName);
                  $cityName     = strtolower($cityName);
                  $requestPath  = "deal/" . $cityName . ".html";
                  $realPath     = "deal/index/index/city/" . $city;
                  $resource     = Mage::getsingleton("core/resource");
                  $read         = $resource->getConnection("read");
                  $tPrefix      = ( boolean ) Mage::getconfig()->getTablePrefix();
                  $rewriteTable = "magentocore_url_rewrite";
                  $idPath       = "deal/index/index/city/" . $city;
                  $urlRewrite   = $read->select()->from(array(
                      "ur" => $rewriteTable
                  ), array(
                      "ur.request_path"
                  ))->where("ur.id_path =? ", $idPath)->where("ur.store_id =? ", $storeId)->where("ur.is_system =?", 0);
                  $cityUrl      = $read->fetchRow($urlRewrite);
                  if (empty($cityUrl)) {
                      $urlCheck     = $read->select()->from(array(
                          "ur" => $rewriteTable
                      ), array(
                          "ur.request_path"
                      ))->where("ur.request_path =? ", $requestPath)->where("ur.store_id =? ", $storeId)->where("ur.is_system =?", 0);
                      $cityUrlCheck = $read->fetchRow($urlCheck);
                      if (!empty($cityUrlCheck)) {
                          $requestPath = "deal/" . $cityName . "-" . $city . ".html";
                      }
                      $executeQuery = $read->query("INSERT INTO {$rewriteTable} (`store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES ({$storeId}, NULL, NULL, '{$realPath}', '{$requestPath}', '{$realPath}', '0', '', NULL)");
                  }
              }
          }
          return $cityValue;
      }
  }
4

1 回答 1

1

该错误意味着您$attribute通过调用运算符将​​变量视为对象->,但 PHP 并未将其识别为对象类型。

$attribute = Mage::getmodel("eav/config")->getAttribute("catalog_product", "562");
$cityValue = array();
* foreach ($attribute->getSource()->getAllOptions(true, true) as $option) {*
$cityValue[$option['label']] = $option['value'];'

你有一个*之前和之后你的foreach,为什么?在分配后立即执行var_dump()or print_r()on 。$attribute你甚至可以gettype()打电话。

于 2012-09-13T06:06:47.213 回答