Welcome Guest, Not a member yet? Register   Sign In
Invoking a helper function
#1

Hey Guys,

I have added my own custom helper function in CI. However I was wondering if the only way isn't it possible to instantiate the class in the controller like the other classes such as $this->class->method

Rather I find my self doing $class = new Class(); $class->method();

Thanks!
Reply
#2

Please elaborate to what you are looking in as a solution to? what you have shared as requirement .. the picture is unclear for that to understand and reply.
Reply
#3

If it's a class file then it is a CI Library and needs to be placed in the ./application/libraries folder to work correct.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

It is possible that you setup your custom helper incorrectly. If you're using CI 2.x, here's a link to the instructions on how to do it correctly. If you're using CI 3.x, check that documentation instead. When done correctly, you don't have to create any class instance. You just load it with $this->load->helper('helper_name');
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#5

(This post was last modified: 02-16-2015, 10:00 AM by CroNiX. Edit Reason: code tags )

In CI, "helpers" are procedural functions, NOT a class.
"Libraries" are classes.

If you put your classes in /application/libraries, you'd just
Code:
$this->load->library('library_name'); //loads /application/libraries/library_name.php

That auto instantiates it, and then to use it you'd just:
Code:
$this->library_name->your_method();
Reply




Theme © iAndrew 2016 - Forum software by © MyBB