php - How to access one controller action inside another controller action? -
i using cakephp-2.x. have 1 function name user_info()
in userscontroller.php
want access in controller name messagescontroller.php
code -
userscontroller.php
public function user_info(){ $user_id=$this->session->read('auth.user.id'); $data=$this->user->findbyid($user_id); $this->set('user_info',$data); }
messagescontroller.php
public function index(){ //$userinfo=new userscontroller(); //$userinfo->user_info(); $this->user_info(); pr($data); }
error message-
fatal error error: phone call undefined method messagescontroller::user_info() file: e:\xampp\htdocs\2014\myshowcam\msc\app\controller\messagescontroller.php line: 18 notice: if want customize error message, create app\view\errors\fatal_error.ctp
typically if you're trying access function in 1 controller controller have fundamental flaw in project's logic.
but in general object usage thus:
$othercontroller = new whatevermycontrollernameis(); $othercontroller->functionname();
however i'm not familiar plenty cake tell pitfalls of doing such thing. illustration have no thought routes or other variables/objects required initialize controller correctly.
edit:
ref: cakephp 2.3.8: calling controller function in croncontroller.php
app::import('controller', 'products'); // mention @ top // instantiation // mention within cron function $products = new productscontroller; // phone call method $products->controllerfunction();
php cakephp
No comments:
Post a Comment