How to design an interceptor in PHP CodeIgniter like in Java structs? -
How to design an interceptor in PHP CodeIgniter like in Java structs? -
when using codeigniter implement little application, want business checking functions in controllers defined outside controller more flexible.
the checking functions session checking, user info completion checking, or has user post article, , on.
firstly, tried utilize helper implement. in core controller extended ci_controller wrote check function:
protected function check () { $this->checked = true; $methods = func_get_args(); foreach ($methods $method) { $m = 'check_' . $method; if (!function_exists($m)) { $this->load->helper("filters/$m"); } if ($m() === false) { homecoming false; } } homecoming true; } then in controller can utilize method check business logic this:
public function () if (!$this->check('session')) { homecoming $this->relogin(); } // ... if (!$this->check('userinfo')) { homecoming $this->redirect('settings'); } // ... if (!this->check('has_post')) { // ... } // ... } but has problem helper function global, , can't invoke protected functions in $ci instance. didn't find way how invoke instance function outside javascript's call/apply.
so turned check hook document of ci. don't think helps, because hook point can't within of controller functions. must outside.
at last, can fallback set checking functions core controller class. wonder there way utilize interceptor in java structs?
php codeigniter interceptor
Comments
Post a Comment