What is the best way to view...

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

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

What is the best way to view...

Post by psurrena »

What would be the best approach for this case:
On the homepage there are two columns - events and news, the titles are pulled from a db. When you click on one or the other it takes you to a new page to view the full content pulled from the db.

I only want one page the view both news and events.

What is the best way for, lets say, view.php to determine the difference between the two db tables (news, events)?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The request data?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It sounds like if you had a single "full" view, you could just pass a different model to that view depending on what you wanted to display. The model could provide the page title, and rows of data. Probably you want the model to have getTitles() and getAllContent() methods for use on the home and "full" view pages respectively.
(#10850)
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

That sounds right - could you elaborate a bit more? Would the model be the "view.php" page? How would you go about distiguishing the two sets of information? Is it through the url (xxx.php?id=2)?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I was thinking that there would be two Models -- NewsModel and EventsModel. They would be polymorphic. You would decide which one to use based on some parameter (like your id=2). This show how web apps often fall into the MVC pattern. You have the Models that provide the data. You have the View that creates HTML with the data in it. And the Controller figures out which Model and View to use base on some parameters.
(#10850)
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

How do people get clean URLs using the method? Instead of http://www.mysite.com/view.php?id=324 I would get http://www.mysite.com/view.php/name-of-article/

Or is that a whole other topic?

Thanks for all you help, everything is much more clear now.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

psurrena wrote:How do people get clean URLs using the method? Instead of http://www.mysite.com/view.php?id=324 I would get http://www.mysite.com/view.php/name-of-article/

Or is that a whole other topic?

Thanks for all you help, everything is much more clear now.
Search for mod_rewrite
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

psurrena wrote:How do people get clean URLs using the method? Instead of http://www.mysite.com/view.php?id=324 I would get http://www.mysite.com/view.php/name-of-article/
$_SERVER['PATH_INFO']
psurrena wrote:Or is that a whole other topic?
Yes it is.
(#10850)
Post Reply