• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call controller method within library without redirect

#1
Hey!

I'm building a library for CI and I need to run the callback after my logic.

How do i call a controller method within library?

I tried different ways and nothing worked Sad

PHP Code:
$default_controller_callback 'Welcome';
$default_method_callback 'custom_message';

// ERROR:  Undefined property: Welcome::$load
$controller = new $default_controller_callback();
call_user_func(array($controller $default_method_callback));

// ERROR: Got Strict standards: call_user_func() expects parameter 1 to be a valid callback, non-static method 
// Welcome::custom_message() should not be called statically
call_user_func(array($default_controller_callback $default_method_callback)); 

Here is the full library code: https://github.com/russ-ab/CodeIgniter-C...n.php#L192

I want to change the redirect to real callback calling.

Thanks!
Reply

#2
I have not looked at your full code (sorry) but I believe you cannot do what you ask (ie call controller method from somewhere else) without HMVC or similar. (I am not 100% on this though)

However there is no reason why your callback in, say, controller A, cannot call a common function (say 'common_callback_function') from a model or a library to get a result, just like any library or model call works. It is just a function after all. Then you are free to reuse that common_callback_function in any other library, or from where ever you want. Keeping everything DRY.

I hope that makes sense.

Paul.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.