我有一个自定义类,我存储在 /app/Lib 中,我想使用 htmlhelper 但由于该类没有扩展任何内容,因此对 $this 的引用$this->Html->link
给出了错误:调用成员函数链接()非对象
我如何在自己的班级中使用这个助手?
这是:
<?php
class Tree {
private $level = 0;
public function show_tree($tree_array) {
$this->level++;
$style = ($this->level==1) ? ' class="sortable"':'';
echo "<ol".$style.">\n";
foreach ($tree_array as $t) {
echo "<li id=\"list_".$t['Category']['id']."\">\n";
echo "<div>".$t['Category']['name'];?>
echo $this->Html->link(__('View'), array('action' => 'view', $t['Category']['id']));
echo $this->Html->link(__('Edit'), array('action' => 'edit', $t['Category']['id']));
echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $t['Category']['id']), null, __('Are you sure you want to delete # %s?', $t['Category']['id']));
echo "</span>\n";
echo "</div>\n";
if (!empty($t['children'])) $this->show_tree($t['children']);
echo "</li>\n";
}
echo "</ol>\n";
$this->level--;
}
}