Welcome Guest, Not a member yet? Register   Sign In
I'm probably doing something stupid but it seems to be autoloading my helper class
#1

(This post was last modified: 06-09-2015, 03:31 AM by DreamOfSleeping.)

Hi. I have a helper class called my_url_helper. This has some simple functions called css_url, js_url, and image_url to help me load them. It works great. Then I noticed I had forgot to load the helper on half my pages, but it still works and I don't know why.

Things I've tried.

I checked and double checked the autoload file to make sure I hadn't added it to it. I haven't

I commented out all the parts in my code where I load the helper in case codeigniter somehow remembered it. It still works.

I wondered if the file had just been cached or something, so I added another function to the helper class called poo_face that simple returns a string saying "pooooooo face". I added a call to the poo_face function, and it worked despite the helper not being
loaded.

I thought I would ask here in case there is something that I might have overlooked.

Here is a one of my controllers and the view that has the functions.

PHP Code:
<?php

class User extends CI_Controller {
 
   
    public 
function __construct() {
 
       parent::__construct();
 
       $this->load->helper('url');
 
       $this->load->library('session');
 
       $this->load->model('user_model');
 
   }
 
   
  
    
    public 
function home() {
 
  
        $this
->load->view('user_home_view');
 
   }
 
   
    public 
function profile() {
 
       
    
}
 
   
    public 
function add_creation() {
 
       $this->load->view('add_creation_view');
 
   }



Code:
<!DOCTYPE html>
<html>
   <head>
       <title>Add Creation</title>
       <meta charset="UTF-8">
       <?php
             // both these functions are found in my_url_helper, not to be confused with the official url helper.
             echo css_url('create-critique'); // this prints out the css url
             echo poo_face(); // this prints pooooo face
       ?>
   </head>
   
</html>
   
Reply
#2

If you mean "MY_helper_class", it means you are overriding codeigniter class by that way it always loaded...
Try this, change classes prefix on "config.php" file, and the class won't be loaded anymore...
cheers...
NexoPOS 2.6.2 available on CodeCanyon.
Reply
#3

Thanks for the reply. To clarify - Are you saying that whenever you add the word "my" to a helper class that is already in the codeigniter framework it overrides it? If that's true then I'll just change the name of my class. I've now changed the name of "my_url_helper" to "assets_url_helper" and that has fixed the problem. Thanks again!
Reply
#4

(06-09-2015, 03:49 AM)DreamOfSleeping Wrote: Thanks for the reply. To clarify - Are you saying that whenever you add the word "my" to a helper class that is already in the codeigniter framework it overrides it? If that's true then I'll just change the name of my class. I've now changed the name of "my_url_helper" to "assets_url_helper" and that has fixed the problem. Thanks again!

Having said that. Overriding it wouldn't necessarily be a bad thing so I might change it back.
Reply
#5

And I've just read the instruction about the extending helper classes thing now, so no need to clarify.
Reply
#6

That's seem to be simple indeed,
every time you intent to extends a core class, this one override automaticaly without any special include. Just use the class prefix defined on config.php file and it's done.

I think you sould create a custom library instead and drop that file on "library/" folder, so it would be easy for you to include it on each controllers or on specifics.
NexoPOS 2.6.2 available on CodeCanyon.
Reply
#7

Helpers in CI are not classes, I don't know what are you two talking about. If you need to find info about what is loaded when, modify log_treshold value.
Reply
#8

That's nice said...
NexoPOS 2.6.2 available on CodeCanyon.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB