且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CodeIgniter - 从视图内部调用函数

更新时间:2023-11-29 15:21:16

视图并不意味着调用控制器操作。
颠倒你的逻辑,在控制器中调用该函数,并将其设置为发送到视图的变量。然后你可以有if语句检查你的视图模板中的变量。

Views are not meant to call controller actions. Reverse your logic, call that function in the controller and set it to a variable you sent to the view. Then you can have the if statement check that variable in your view template.

如果这不适合你,也许一个助手是你需要的: http://ellislab.com/codeigniter/user-guide/general/helpers.html

If that doesn't work for you, maybe a helper is what you need: http://ellislab.com/codeigniter/user-guide/general/helpers.html