2017-03-22 8 views
0

このエラーが発生しました。 if statementパースエラー:29行目のD:¥xampp¥htdocs¥ramesh¥wmw¥catalog¥controller¥sub_category.phpの構文エラー、予期しない 'if'(T_IF)、 ')'

Parse error: syntax error, unexpected 'if' (T_IF), expecting ')' in D:\xampp\htdocs\ramesh\wmw\catalog\controller\product\sub_category.php on line 29

異なるhrefため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*/ 
     } 

    ); 
} 
+0

http://stackoverflow.com/questions/4118875/a-conditional-element-inside-an-array-constructを確認してください。 –

+0

リプレイのおかげで@PhilipTzou申し訳ありませんが私のコードで教えてください理解できません。それは簡単です –

答えて

0

Finalyを実行しようと、私は細かい

作業コード、次の答えを得ました3210
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 
); 

}

+0

私は結果を得ました –

0

コードの構文が間違っています。配列内でelse条件が許可されていない場合。

でコードを交換してください、次のエラーが解決されます -

foreachの($結果としてcategory_info $){$ の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  

); 

}

+0

あなたの再生のためにありがとうございます@ Knowbandプラグインしかし、私のコードは正常に動作します –

関連する問題