Helper设计上是给View层使用的。应该尽量避免,但有时为了避免重复代码,想这么操作,也是可行的。
如下例所示:
class UsersController extends AppController {
function index() {
App::import('Helper', 'Html'); // loadHelper('Html'); in CakePHP 1.1.x.x
$html = new HtmlHelper();
debug($html->link('Cake!', 'http://cakephp.org'));
}
}
Helper使用
本文介绍了一种在View层使用的Helper设计,并通过实例展示了如何加载和使用HtmlHelper来避免代码重复。
225

被折叠的 条评论
为什么被折叠?



