【问题标题】:Parse error: syntax error, unexpected 'if' (T_IF), expecting ')' in D:\xampp\htdocs\ramesh\wmw\catalog\controller\product\sub_category.php on line 29解析错误:语法错误,意外的 'if' (T_IF),在 D:\xampp\htdocs\ramesh\wmw\catalog\controller\product\sub_category.php 第 29 行期待 ')'
【发布时间】:2017-03-22 04:34:35
【问题描述】:

我在尝试为不同的 href 运行 if statement 时收到此错误

解析错误:语法错误,意外的 'if' (T_IF),期望 ')' 在 D:\xampp\htdocs\ramesh\wmw\catalog\controller\product\sub_category.php 第 29 行

sub_category.php

foreach ($category_info as $result) {
        $data['categories'][] = array(
        'name' => $result['name'],
        'parent_id' => $result['parent_id'],
        'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), this->config->get('config_image_category_height')),
        'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
        /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
        'href' => $this->url->link('product/sub_category')*/
        if($result['category_id']==24)
        {
            'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])
    }
    elseif
    {
            /*some code for href*/
        }

      );
}

【问题讨论】:

标签: if-statement opencart href


【解决方案1】:

最后我得到了以下代码工作正常的答案

 foreach ($category_info as $result) {
 if($result['category_id']==24)
 {
    $link1 = $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id']);
 }
else
{
    $link1 = $this->url->link($_SERVER["REQUEST_URI"]);
}
$data['categories'][] = array(
    'name' => $result['name'],
    'parent_id' => $result['parent_id'],
    'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
    /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
    'href' => $this->url->link('product/sub_category')
    'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id'])*/
    'href' => $link1
);

}

【讨论】:

  • 我得到了结果
【解决方案2】:

您的代码语法错误。 if else 条件不允许在数组中使用。

请用以下代码替换您的代码,错误将得到解决 -

foreach ($category_info as $result) { $href = '';

    if ($result['category_id']==24) {
        $href = $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id']);
    } else {
        /*some code for href*/
    }

    $data['categories'][] = array(
    'name' => $result['name'],
    'parent_id' => $result['parent_id'],
    'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height')),
    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
    /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id'])
    'href' => $this->url->link('product/sub_category')*/        
    'href' => $href    

  );

}

【讨论】:

  • 感谢您的重播@Knowband Plugins 但我的代码工作正常
猜你喜欢
  • 2011-07-23
  • 2013-06-20
  • 2013-12-09
  • 1970-01-01
  • 1970-01-01
  • 2018-01-08
  • 1970-01-01
  • 1970-01-01
  • 2010-12-20
相关资源
最近更新 更多