Destramic Posted August 30, 2011 Share Posted August 30, 2011 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/ Share on other sites More sharing options...
KevinM1 Posted August 30, 2011 Share Posted August 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1263629 Share on other sites More sharing options...
Destramic Posted August 31, 2011 Author Share Posted August 31, 2011 ok i see now thank you...so what would be the best way to do this and include the header and footer to each controller? Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264021 Share on other sites More sharing options...
KevinM1 Posted August 31, 2011 Share Posted August 31, 2011 To be honest, I'm wondering why your bootstrap is even trying to handle the header and footer. That should be the responsibility of your view logic. Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264040 Share on other sites More sharing options...
Destramic Posted September 1, 2011 Author Share Posted September 1, 2011 @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? Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264317 Share on other sites More sharing options...
KevinM1 Posted September 1, 2011 Share Posted September 1, 2011 I don't know enough about your system architecture to say. Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264334 Share on other sites More sharing options...
Destramic Posted September 1, 2011 Author Share Posted September 1, 2011 ok but calling $this->_title inside the template isnt exactly right is it? Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264380 Share on other sites More sharing options...
premiso Posted September 1, 2011 Share Posted September 1, 2011 I don't think you could call it like $this->_title anyways, if the _title is a private property. You should be able to grab it with $this->title, depending on the framework. But I dunno what framework etc you are using, so yea. Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264385 Share on other sites More sharing options...
Destramic Posted September 1, 2011 Author Share Posted September 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264562 Share on other sites More sharing options...
Destramic Posted September 2, 2011 Author Share Posted September 2, 2011 this is what i wanted call_user_func_array(array(new $name(), "__construct"), $arguments); Quote Link to comment https://forums.phpfreaks.com/topic/246041-oop-problem-small/#findComment-1264578 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.