Welcome Guest, Not a member yet? Register   Sign In
How to use Helper function on view - CI4?
#1

On CI-3, when I've loaded helpers through autoload, I can use any function as well on view wihtout defining it on controller first.
I've read the ci4 docs, that loaded helper via base controller then extent any controller to it. But however. I call it on controller and assign to variable before use it on View.

How can I use helper function on View directly?
Reply
#2

Yes, you can use helper functions in view. For example there are the form helper, that's the one I use the most.
Reply
#3

(04-23-2020, 02:49 PM)jreklund Wrote: Yes, you can use helper functions in view. For example there are the form helper, that's the one I use the most.

Im using my own helpers and loaded it via BaseController.but i can't use it on views. 
i can use if I defined variable on Controller before
Reply
#4

(This post was last modified: 04-24-2020, 10:21 AM by Mostafa Khudair.)

In your view file just call helper() function.

for example if you want to use form helper in view and you didn't define it in controller just do this in view:
PHP Code:
<?php helper('form'); ?>

once you do this all functions inside form helper will be enabled to use directly in view.

if you want to load more than one helper, you can do this
PHP Code:
<?php helper(['form''text']); ?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB