View (MVC) Function / Class

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: View (MVC) Function / Class

Post by allspiritseve »

psurrena wrote:oh, and I might have made fun of this but it has just saved me a ton of work. It must be worth something
If you combine what arborint and I posted, you may find that this is a bit cleaner:

Code: Select all

public function createTabs ($tabCount)  {
 
    $template = new Template ('tabs.tpl');
    $template->set ('tabCount', $tabCount);
    return $template->render();
 
}
Assuming the Template class is arborint's phpTemplate class, and tabs.tpl contains my html+presentational php.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: View (MVC) Function / Class

Post by Christopher »

And for the record, allspiritseve's createTabs() function would be the "View".
(#10850)
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Re: View (MVC) Function / Class

Post by psurrena »

Looks great, I'll implement it later today and see how it goes. Thanks again!
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Re: View (MVC) Function / Class

Post by psurrena »

One question, why is tabcount listed twice, in two forms?

Code: Select all

$template->set ('tabCount', $tabCount);
User avatar
allspiritseve
DevNet Resident
Posts: 1174
Joined: Thu Mar 06, 2008 8:23 am
Location: Ann Arbor, MI (USA)

Re: View (MVC) Function / Class

Post by allspiritseve »

psurrena wrote:One question, why is tabcount listed twice, in two forms?

Code: Select all

$template->set ('tabCount', $tabCount);
One's the key, one's the value. That way you can tell the template class what to name the variable when it passes control over to the included form. Look up the extract() function in the php manual, you'll see what it does. It's pretty handy.
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Re: View (MVC) Function / Class

Post by psurrena »

Great, thanks a lot.
Post Reply