Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-12-2010, 09:41 PM   PM User | #1
feras_wilson
Regular Coder

 
feras_wilson's Avatar
 
Join Date: Jul 2005
Location: Sweden
Posts: 129
Thanks: 1
Thanked 0 Times in 0 Posts
feras_wilson is an unknown quantity at this point
Exclamation Need help with my MVC code (Very Light)

Code:
 
<?php
 
class
Starter extends Mysql { public $settings, $fetchsettings, $pagenr, $fetchpages, $menuq, $pagesq; public $menustr; public $fetchmenu; public $options, $tag; public $i = 0; public function Start() { $this->makeconnection("","","",""); // Load Default Settings
$this->settings = $this->query("SELECT * FROM settings WHERE id='1'"); $this->fetchsettings = mysql_fetch_array($this->settings); // Load Pages
$this->pagenr = mysql_real_escape_string($_GET['page']); if($this->pagenr == "") { $this->pagenr=1; } $this->pagesq = $this->query("SELECT * FROM pages WHERE id='".$this->pagenr."'"); $this->fetchpages = mysql_fetch_array($this->pagesq); // Load Menu
$this->menuq = $this->query("SELECT * FROM menu"); } public function showmenu() { while($this->fetchmenu = mysql_fetch_array($this->menuq)) { $this->menustr[$this->i] = "<a href=\"".$this->fetchmenu['item_url']."\"".$_GET['page'] == 1 || $_GET['page'] == "" ? "class=\"selected\"" : "" .">".$this->fetchmenu['item_text']."</a>"; $this->i++; } return $this->menustr; } } ?>
<?php
class
Template extends View { // This is default settings and these is set by the template config file //
public $li_included = true; public function GenerateMenu() { return $Starter->menustr; } }
?>
__________________
Exp:
PHP
.NET

Last edited by feras_wilson; 05-13-2010 at 08:15 AM..
feras_wilson is offline   Reply With Quote
Old 05-12-2010, 11:22 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
The error you are receiving is because $Starter has not been declared within the template, and is not an object with an accessable showmenu() method (since it hasn't been constructed).
Starter either needs to be passed into the GenerateMenu method, or constructed or passed into either the Template or View object upon construction. This would then require access under $this->Starter instead. This can be enforced with typehinting if required:
PHP Code:
public function GenerateMenu(Starter $starter) {
// .... 
If the Starter::showmenu() is from a higher interface, typehint on that instead of a lower level class.

Edit:
Oh well nvm. I guess I shouldn't have left this thread open when I went out.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 05-12-2010, 11:50 PM   PM User | #3
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
Quote:
Originally Posted by feras_wilson View Post
Never mind it, I wont get anyhelp anyway
What??? Your topic was 46 minutes old! You don't think people sit here on the forums with an itchy trigger finger pecking away at the ol' F5 key... do you? Patience...
__________________
ZCE
kbluhm is offline   Reply With Quote
Old 05-13-2010, 08:21 AM   PM User | #4
feras_wilson
Regular Coder

 
feras_wilson's Avatar
 
Join Date: Jul 2005
Location: Sweden
Posts: 129
Thanks: 1
Thanked 0 Times in 0 Posts
feras_wilson is an unknown quantity at this point

Catchable fatal error: Argument 1 passed to Template::GenerateMenu() must be an instance of Starter, none given, called in /home/server/public_html/styles/default/index.tpl on line 108 and defined in /home/server/public_html/includes/template.php on line 6

__________________
Exp:
PHP
.NET
feras_wilson is offline   Reply With Quote
Old 05-13-2010, 11:02 AM   PM User | #5
feras_wilson
Regular Coder

 
feras_wilson's Avatar
 
Join Date: Jul 2005
Location: Sweden
Posts: 129
Thanks: 1
Thanked 0 Times in 0 Posts
feras_wilson is an unknown quantity at this point
Thanks for the help guys! I fixed it
__________________
Exp:
PHP
.NET
feras_wilson is offline   Reply With Quote
Old 05-13-2010, 03:24 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by feras_wilson View Post
Thanks for the help guys! I fixed it
Great to hear, did you end up passing $Starter into the GenerateMenu(), or did you end up instantiating inside of the constructor for it?
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 05-13-2010, 04:22 PM   PM User | #7
feras_wilson
Regular Coder

 
feras_wilson's Avatar
 
Join Date: Jul 2005
Location: Sweden
Posts: 129
Thanks: 1
Thanked 0 Times in 0 Posts
feras_wilson is an unknown quantity at this point
I used the right method xD
See (View):
Code:
 
class View {

public $Model;
public function __construct($Model) { $this->Model = $Model; }
}
Controller:
Code:
class Controller { public $View, $Model; public function __construct($Model, $View) { $this->Model = $Model; $this->View = $View; } public function SwitchCase($Case) {
$this->Case = $Case; switch($this->Case) { case "Start": $this->Model->Start(); break; case "ShowMenu": $this->Model->showmenu(); break; case "MakeConnection": $this->Model->makeconnection(); break; }
} }
__________________
Exp:
PHP
.NET
feras_wilson is offline   Reply With Quote
Reply

Bookmarks

Tags
advanced, framework, mvc, php, view

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:15 PM.


Advertisement
Log in to turn off these ads.