Destramic Posted May 15, 2011 Share Posted May 15, 2011 hey guys i havent done any cloneing before but what im trying to do is clone $this->_view property in my Action class and pass it to my News_Controller class so i can call the View class by a varaible and not a property....can anyone help me and give me some advise on how i should do this...i tried below but i cant get it to work...thanks alot news controller class <?php class News_Controller extends Action { public function articles() { $view->title = "hello"; } } ?> action class <?php class Action { protected $_request; protected $_response; public $_view; public function __construct(Request $request, Response $response) { $this->set_request($request)->set_view(); $view = $this->clone_view(); $view->title = "hello"; $this->_response = $response; } protected function set_request(Request $request) { $this->_request = $request; return $this; } protected function set_view() { $this->_view = new View; return $this; } protected function get_request() { return $this->_request; } public function clone_view() { $view = clone $this->_view; return $view; } public function dispatch($method, $parameters) { if ($this->get_request()->is_dispatched()) { if(method_exists($this, $method)) { call_user_func_array(array($this, $method), $parameters); } else { } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/236459-cloing-class-property/ Share on other sites More sharing options...
Zane Posted May 15, 2011 Share Posted May 15, 2011 couldn't you just create a new Action object within your NewsController instead. class News_Controller extends Action { public function articles() { $action = new Action(); $action->title = "New Title"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/236459-cloing-class-property/#findComment-1215674 Share on other sites More sharing options...
Destramic Posted May 15, 2011 Author Share Posted May 15, 2011 I did really want to clone the property as $view...i could just do $this->_view but as I said I really would like to clone it across it that could be done Quote Link to comment https://forums.phpfreaks.com/topic/236459-cloing-class-property/#findComment-1215679 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.