• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Aspects In Codeigniter

I want to implement the ability to do aspects (or something close to it) in my codeigniter project. Can someone tell me how I might be able to do this. I want to use this for putting logging and notifications into my project. I don't want to scatter the code around the project. I was hoping that somewhere there was a gateway that always gets called in CI and I can then evaluate the class and property being called.


You could create a post-controller hook that spit out whatever you need based on a var you set insed your controllers (like $this->aspect)
The only catch is the extend the redirect() function to call your post-controller hook before redirecting.

If you extend the base-controller, by creating a MY_Controller.php and put that in the libraries-folder, you could create all these hooks very easily.

Have a look at Creating Core System Classess

The Hooks seems like the way to go. I looked at the documentation and have one question. How do I determine the information about the controller that was triggered? For the post-controller I want to examine the triggered controller and method to determine if I want to actually process the code.

Thanks for the great suggestion.

Load the url helper and use $this->uri->uri_string();

Couldn't the URI be unreliable based on the project structure? Is there a guaranteed way to get the controller & method?


I have this code:


if (!defined('BASEPATH')) exit('No direct script access allowed');

class log

    const todo_add = '/todo/todo_add_c/submit';
    const todo_edit = '/todo/todo_edit_c/submit';

    function checkURI()
        $CI =& get_instance();
        $uri = $CI->uri->uri_string();
        switch ($uri) {
            case log::todo_add:
                log_message('error', 'test todo add');
            case log::todo_edit:
                log_message('error', 'test todo edit');



This code will not log a message. Is the issue that it is not matching to the submit? The hook works fine as long as I do not redirect in the submit controller.


I did notice that


separates out the class/method

any way to tap into this if the hook does not do that?


I just thought I would try one more time and see if anyone has any other ideas. So far I can't get this to work. Is there an actual project that can help with this?

Thanks for any info.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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