Jump to content

oop problem (small)


Destramic

Recommended Posts

the problem im getting is with this line in the bootstrap

 

$this->view->head_title('test');

 

the view property is only initiated in the league_controller and $this->view doesnt exsist within the bootstap but i call the bootstrap header in the league controller and it wont let me execute the head title...if anyone can help me on why or how i can over come this please....thank you  (code below)

 

bootstrap

public static function header()
{
	$this->view->head_title('test');
}

 

 

leaugue_controller method

public function league($game_name, $league_name)
{
	Bootstrap::header();

	$rows = $this->leagues->fetch_league($game_name, $league_name);

	$this->view->head_title()->set_separator()->prepend('hello');
	$this->view->rows = $rows;

	Bootstrap::footer();
}

Link to comment
https://forums.phpfreaks.com/topic/246041-oop-problem-small/
Share on other sites

It looks like a scope issue to me.  Just because you invoke the bootstrap's header method in your league controller doesn't mean that the bootstrap will automatically have access to the controller's members.  You need to pass in the view to the method, just like you would with a function in a procedural context.  Remember: in PHP methods are functions.  Treat them accordingly.  Scope still applies.

Link to comment
https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1263629
Share on other sites

@nightsylr i decided to do it like you said...

 

	public function league($game_name, $league_name)
{
	$rows = $this->leagues->fetch_league($game_name, $league_name);

    $this->view->head_title('test - hello');
	$this->view->rows = $rows;
	$this->view->render('headers/header.html');
	$this->view->render('leagues/league.html');
	$this->view->render('footers/footer.html');
}

 

if that is how you meant...now when the title is set it will assign the value to $this->_title ... but i dont want the title called like that in my header file...is there a way i can do this without changing the property name?

Link to comment
https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264317
Share on other sites

im using my own framework im building...now ive decided to go down the root of using helpersin my view class

 

public function __call($helper, $arguments)
{
	if (!$this->get_helper($helper))
	{
		$instance = new $helper($arguments);
		$this->set_helper($helper, $instance);
		return $instance;
	}
}

 

now the __call works as i want it...but the problem is the $arguments var is an array and gets sent to the helper like that...what is the best way to tackle this...i'd like it to be send as a string as it is not a array (i think the __call method automatically makes the incoming string an array)

 

if you could give me your help/suggestions please guys

Link to comment
https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264562
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.