Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Magic Method __call in rest controller
  • Hey anyone knows how to implement __call method in rest controller?
    Is it supported?
  • Mitali Khundiwala wrote on Wednesday 9th of November 2011:
    Hey anyone knows how to implement __call method in rest controller?
    Is it supported?

    Following FuelPHP architecture, all controller should be executed from Request class. But wouldn't router() method be enough to 'act' as __call
  • Is there any other solution for calling dynamic method?
  • Mitali Khundiwala wrote on Thursday 10th of November 2011:
    Is there any other solution for calling dynamic method?

    I don't see the need to have __call method in a Controller, if there a requirement to call the class OTHER than through Request class, you should use a basic class structure and call it from a controller class.
  • Actually __call method is working fine with simple controller. But it is not working with rest controller.
    What I need is If i defined some method in some class than it should be called directly from rest controller with that some class instance. I don't want to add method for calling some class method.
  • A rest controller is a class like any other. No reason why a __call() magic method wouldn't work. If you give us more information on what you try to achieve, maybe we can figure out what the issue is. It is quite possible you don't fully understand how FuelPHP gets to calling your controller method? For example, such a magic method is only useful if that method is actually called. If the code does a method_exists() first, it might not be called at all since technically the method does not exist. If is_callable() is used, it would work, as that correctly checks the existence of a __call() method. With respect to controller methods being called from the router, the remark in one of the previous posts is correct, for that you should use the router() method, and not introduce __call().

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion