CodeIgniter Forums
HMVC Routes: Protected methods result in warning instead of 404 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: HMVC Routes: Protected methods result in warning instead of 404 (/showthread.php?tid=68295)



HMVC Routes: Protected methods result in warning instead of 404 - RBX - 06-20-2017

I've been using HMVC modular extensions. I have a base class in which I've defined some protected methods available to all inheriting controller, however I don't want them to be accessible using URL. When trying to access with URL, I get a warning instead of 404 error. It would be great if these could return 404 as I believe only public methods are intended to be available as routes.

Code:
Severity: Warning

Message: call_user_func_array() expects parameter 1 to be a valid callback, cannot access protected method Controller::method()

Filename: core/CodeIgniter.php

Line Number: 532



RE: HMVC Routes: Protected methods result in warning instead of 404 - Martin7483 - 06-20-2017

Maybe you could use the _remap method in your controllers. Have a check in that method that checks if the called method is public.

remapping-method-calls

You could then use something like this

PHP Code:
public function _remap($method$params = array())
{
 
   ifmethod_exists($this$method) )
 
   {
 
       $reflection = new ReflectionMethod(get_class($this), $method);
 
       if$reflection->isPublic() )
 
       {
 
           return call_user_func_array(array($this$method), $params);
 
       }
 
       else
        
{
 
           show_404();
 
       }
 
   }

 
   show_404();