我正在使用Ionize cms作为我网站的后端,我想创建自己的标签 - 用于从我自己的表中传递数据.我已经按照本教程创建自定义标记,并通过它 - 将数据传递给视图,但我不断收到错误:
标签缺失:演示,范围:.
这是我的观点:
<ul>
<ion:demo:details>
<li><ion:detail field="user_name" /></li>
</ion:demo:details>
</ul>
Run Code Online (Sandbox Code Playgroud)
以下是我添加到TagManager.php的更改
public static $tag_definitions = array
(
// <ion:demo:authors /> calls the method “tag_details”
"demo:details" => "tag_details",
"demo:details:detail" => "tag_detail",
);
Run Code Online (Sandbox Code Playgroud)
我还尝试创建一个简单的codeigniter控制器并使用view()传递数据并执行以下操作:
<ul>
<?php foreach($details as $detail): ?>
<li>
<?php echo $detail['name'] ?>
</li>
<?php endforeach ;?>
</ul>
Run Code Online (Sandbox Code Playgroud)
但是我得到了未定义的错误$details.
改变了标签,现在它很好.
<?php
class TagManager_Data extends TagManager
{
public static $tag_definitions = array(
"authors" => "tag_authors",
"authors:author" => "tag_author",
);
public static function index(FTL_Binding $tag)
{
$str = $tag->expand();
return $str;
}
public static function tag_authors(FTL_Binding $tag)
{
$str = '';
$authors = [["name" => 'josh', "foo" => 'josh'], ["name" => 'joshjosh', "foo" => 'josh'], ["name" => 'josh', "foo" => 'josh']];
foreach($authors as $author) {
$tag->set('author', $author);
$str.= $tag->expand();
}
return $str;
}
public static function tag_author(FTL_Binding $tag)
{
$field = $tag->getAttribute('field');
if (!is_null($field)) {
$author = $tag->get('author');
if (!empty($author[$field])) {
return self::output_value($tag, $author[$field]);
}
return self::show_tag_error($tag, 'The attribute <b>"field"</b> is not set');
}
}
}
Run Code Online (Sandbox Code Playgroud)