php - Codeigniter - find out if class was called directly -
php - Codeigniter - find out if class was called directly -
i attempting create controller can observe if called controller in application.
if called straight via url, however, need know can perform other actions.
i.e.
cheese/modulename
calling potato/modulename
different accessing site/cheese/modulename
via url - , need able pick on , deed accordingly.
i aware of:
$this->router->class
but not work may have same named class in module (hmvc pattern fyi) may want phone call controller (cheese/modulename
calling potato/modulename
illustration homecoming 'modulename' - can't utilize check see if called itself.)
i need check for:
controller called via controller = true / false
can tell me how (or if beingness thick!)
i doing in __construct()
in case solution have problem (can't see why never know!)
edit
thank mohammad walid answer.
for clarity construction is
clients models controllers - client - api views jobs models controllers - jobs - api views
i calling api client - may phone call api (possibly) may in module
for illustration clients api might called jobs api controller (i have no intention of doing @ nowadays may possibility under different scenarios haven't forseen , want create future-proof don't have massive refactoring job in future.)
you can seek this:
function is_called_via_url($controller_object){ homecoming $this->uri->segment(1) === get_class($controller_object); }
and in controller:
if(is_called_via_url($this)){ //do }
i'm not quite sure if passing $this
argument in constructor work, worth try.
reference , hint monkeyzeus's comment.
php codeigniter
Comments
Post a Comment