How do I instantiate a custom class based helper in a view |
In the world of CodeIgniter Helpers are not written in an Object Oriented format. In other words, they are not classes.
The code you have is a library. You should move the file to /application/libraries/ and rename it as shown making sure the first character in the file name is uppercase, ie. Imageresize.php Change the class definition from PHP Code: Class ImageResize PHP Code: Class Imageresize The CamelCase naming won't work well with CodeIgniter. (Keep the uppercase first letter.) Remove this from /config/autoload.php PHP Code: $autoload['helper'] = ['imageresize']; It looks like the class requires a file name when it is instantiated. The code you share does not show any other method. Without some other way to supply the file name, this class is not a good candidate for use with $autoload. The reason is that that way of loading resources doesn't accommodate arguments to the autoload request. If the class has some other way to set what file it's working with you could use the following in /config/autoload.php PHP Code: $autoload['libraries'] = ['imageresize']; If you don't want it to autoload (a.k.a. always load) but only in specific places use PHP Code: $this->load->library('imageresize', 'filename'); Either way, the class file will be included and an object instantiated and ready for use. PHP Code: $this->imageresize->resizeImage($newWidth, $newHeight); |
Messages In This Thread |
How do I instantiate a custom class based helper in a view - by seanr - 12-01-2018, 09:33 AM
RE: How do I instantiate a custom class based helper in a view - by dave friend - 12-01-2018, 12:37 PM
RE: How do I instantiate a custom class based helper in a view - by seanr - 12-01-2018, 04:40 PM
RE: How do I instantiate a custom class based helper in a view - by dave friend - 12-02-2018, 07:44 AM
RE: How do I instantiate a custom class based helper in a view - by seanr - 12-02-2018, 11:00 AM
|