Я использую конструктор в моей модели и печатаю данные в блейде,
Проблема в том, что мои данные хранятся в базе данных с короткими именами, поэтому я хочу записывать реальные имена, когда они печатаются в блейде, а не просто возвращать эти короткие имена, но я не могу получить оператор if для работы в моем сборщике .
код
public function buildFooter($footer, $positionid = 'footer')
{
$result = null;
foreach($footer as $item)
if($item->type == $positionid) {
$result .= "<li class='dd-item nested-list-item' data-position='{$item->position}' data-id='{$item->id}'>
<div class='dd-handle nested-list-handle'>
<i class='fas fa-arrows-alt'></i>
</div>
<div class='nested-list-content'>
//if part
if('{$item->widget}' == 'feature-posts')
Feature Posts
elseif('{$item->widget}' == 'feature-posts-sidebar')
Feature Posts (Sidebar)
elseif('{$item->widget}' == 'top-categories-posts')
Top Categories (By Posts)
elseif('{$item->widget}' == 'top-categories-visits')
Top Categories (By Visits)
else
Popular Posts
endif
//if part
- {$item->status}
<div class='float-right'>
<a href=''>Edit</a> |
<a href='#' class='delete_toggle' rel='{$item->id}'>Delete</a>
</div>
</div>".$this->buildFooter($footer, $item->id) . "</li>";
}
return $result ? "\n<ol class=\"dd-list\">\n$result</ol>\n" : null;
}
// Getter for the HTML menu builder
public function getHTMLFooter($items)
{
return $this->buildFooter($items);
}
ошибка
syntax error, unexpected end of file, expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF)
Есть идеи?
Обновление
Хорошо, я подумал, что в моем блейде была проблема с ошибкой, но теперь, когда мой блейд загружается, я получаю такие данные:
текущий код
public function buildFooter($footer, $positionid = 'footer')
{
$result = null;
foreach($footer as $item)
if($item->type == $positionid) {
$result .= "<li class='dd-item nested-list-item' data-position='{$item->position}' data-id='{$item->id}'>
<div class='dd-handle nested-list-handle'>
<i class='fas fa-arrows-alt'></i>
</div>
<div class='nested-list-content'>
//if part
if($item->widget == 'feature-posts')
Feature Posts
elseif($item->widget == 'feature-posts-sidebar')
Feature Posts (Sidebar)
elseif($item->widget == 'top-categories-posts')
Top Categories (By Posts)
elseif($item->widget == 'top-categories-visits')
Top Categories (By Visits)
else
Popular Posts
endif
// if part
- {$item->status}
<div class='float-right'>
<a href=''>Edit</a> |
<a href='#' class='delete_toggle' rel='{$item->id}'>Delete</a>
</div>
</div>".$this->buildFooter($footer, $item->id) . "</li>";
}
return $result ? "\n<ol class=\"dd-list\">\n$result</ol>\n" : null;
}
// Getter for the HTML menu builder
public function getHTMLFooter($items)
{
return $this->buildFooter($items);
}
Обновление 2
Основываясь на предложении в комментариях, я внес изменения ниже
добавлено ".
и ."
вокруг if и некоторые изменения в возвращаемых текстах при добавлении ''
вокруг них.
//code
<div class='nested-list-content'>".
if ($item->widget == 'feature-posts'){
'Feature Posts'
} elseif ($item->widget == 'feature-posts-sidebar') {
'Feature Posts (Sidebar)'
} elseif ($item->widget == 'top-categories-posts') {
'Top Categories (By Posts)'
} elseif ($item->widget == 'top-categories-visits') {
'Top Categories (By Visits)'
} else {
'Popular Posts'
}
- {$item->status}
."<div class='float-right'>
//code
и теперь я получаю
syntax error, unexpected 'if' (T_IF)
На
if ($item->widget == 'feature-posts'){