• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
post_controller_constructor get_instance issues

#1
[eluser]i_like_ponies[/eluser]
Hi, so I've looked around this site and others and I was trying to figure out how to dynamically turn on profiling based on remote user IP.

So I found some great examples about using the post_controller_constructor and then setting the enable_profiler via the hook (using a config flag).

So the issue I've been running into constantly is that the get_instance always returns a NULL. I looked into hacking it to use the globals out of curiosity but they don't seem to be part of the constructor class.

http://codeigniter.com/wiki/Customizing_the_Profiler/

That tutorial looks like it should work, but everything I've tried so far never gets me a $CI object. Any thoughts? Everything I've read says that get_instance should work in this hook and later for the processing of the request, but that doesn't seem to be true. And I wanted to setup the environment for the requests before the methods on my controller get hit.

I'd give code examples but I've been using the ones from the site to test with and so far none have worked.

#2
[eluser]jedd[/eluser]
Why not just extend CI's controller using the tried-n-trusted method of the MY_Controller thing, put a simple IP test in there, and if it meets whatever criteria, enable the profiler?

#3
[eluser]TheFuzzy0ne[/eluser]
This is an excerpt from my config.php
Code:
$config['dev_mode'] = FALSE;

and the MY_Controller.php file looks like this:
Code:
<?php

class MY_Controller extends Controller {
    
    function MY_Controller()
    {
        parent::Controller();
        $this->output->enable_profiler($this->config->item('dev_mode'));
            
    }
}

// End of file: MY_Controller.php
// ./system/application/libraries/MY_Controller.php

You could easily put some logic in the config file, which will enable the profiler if your IP address matches a specific IP address.

There's nothing wrong with Jedd's suggestion, I just like to put everything config-related into the config.php file.

However, I must ask, why would you want to do this? Surely you have a production site, and a development site, no?

#4
[eluser]jedd[/eluser]
Quote:However, I must ask, why would you want to do this? Surely you have a production site, and a development site, no?

I was thinking about why you'd do this, and concluded that it might be handy for testing, if you have an extra machine (even a VM). You could hit your site from your development machine to make sure it looks okay, and easily flick over to the same page *with profiling* from the other machine. Similarly, identifying (and forcing profiling) based on browser identification.

I guess it'd be good where you have several developers, especially where one was responsible for the SQL calls, say, while the others were more interested in functionality / aesthetics.

#5
[eluser]i_like_ponies[/eluser]
Yeah I figured out my issue. I had also tried overriding the Controller class but I didn't realize that the Controller class has subclasses disabled by default and I had to change my controllers to inherit from my class name instead.

And yes, the root issue is code design goals. I need the code base to be flexible enough to meet my goals. Some of these include the following:

* multiple developers and development machines
* multiple stages of release (devel,staging,production)
* multiple site/database/feature configurations in a single code base

So I basically need an initialization function that I can user to prepare the code base for whatever site the incoming request is for. We already have a similar code base in Perl so I'm just looking for a way to replicate our current features into this framework so we can create sites in multiple programming languages.

My next goal is to incorporate our current db configuration into this framework. So I'll let you guys know how that goes. Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.