Jump to content

cloing class property


Destramic

Recommended Posts

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 
		{

		}
	} 
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/236459-cloing-class-property/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.