Last active
December 16, 2015 05:08
-
-
Save etaubman/5381798 to your computer and use it in GitHub Desktop.
A method for extending CodeIgniter to have pre and post filters simliar to RoR and Cake. The actual method call is left in for reference. This is and addition to the file ./system/core/CodeIgniter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //this is a snippet from ./system/core/CodeIgniter.php | |
/* | |
* ------------------------------------------------------ | |
* Is there a pre-filter on the requested method? | |
* ------------------------------------------------------ | |
*/ | |
if (isset($CI->pre_filter) && is_array($CI->pre_filter)) | |
{ | |
foreach ($CI->pre_filter as $pre_filter_action => $filtered_action) | |
{ | |
if (is_string($filtered_action) && $method == $filtered_action) | |
{ | |
//call pre-filter | |
call_user_func_array(array(&$CI,$pre_filter_action),array_slice($URI->rsegments, 2)); | |
} | |
else if (is_array($filtered_action) && in_array($method,$filtered_action)) | |
{ | |
//call pre-filter | |
call_user_func_array(array(&$CI,$pre_filter_action),array_slice($URI->rsegments, 2)); | |
} | |
} | |
} | |
/* | |
* ------------------------------------------------------ | |
* Call the requested method | |
* ------------------------------------------------------ | |
*/ | |
//LEAVE THE STANDARD CI METHOD CALL IN HERE | |
/* | |
* ------------------------------------------------------ | |
* Is there a post-filter on the requested method? | |
* ------------------------------------------------------ | |
*/ | |
if (isset($CI->post_filter) && is_array($CI->post_filter)) | |
{ | |
foreach ($CI->post_filter as $post_filter_action => $filtered_action) | |
{ | |
if (is_string($filtered_action) && $method == $filtered_action) | |
{ | |
//call post-filter | |
call_user_func_array(array(&$CI,$post_filter_action),array_slice($URI->rsegments, 2)); | |
} | |
else if (is_array($filtered_action) && in_array($method,$filtered_action)) | |
{ | |
//call post-filter | |
call_user_func_array(array(&$CI,$post_filter_action),array_slice($URI->rsegments, 2)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment