Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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; } }
    ?>
    Last edited by feras_wilson; 05-13-2010 at 08:15 AM.
    Exp:
    PHP
    .NET

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    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...

  • #4
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  • #5
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the help guys! I fixed it
    Exp:
    PHP
    .NET

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Regular Coder feras_wilson's Avatar
    Join Date
    Jul 2005
    Location
    Sweden
    Posts
    129
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •