Helper設(shè)計(jì)上是給View層使用的。應(yīng)該盡量避免,但有時(shí)為了避免重復(fù)代碼,想這么操作,也是可行的。
如下例所示:
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'));
}
}