Jump to content

Classes


Rommeo

Recommended Posts

For our semester project as a group we're building an advertisement website.

it's simply ;

"visitors can see any advertisement like home/automobile advertisement

visitors that are logged in can send messages to other users and post a new advertisement"

it's like very simple version of e-bay.com

 

And my problem is;

In my UML i have 3 classes

[Page] <---(connected to)---[Advertisement]<---(connected to)---[Guest]

-When guest is logged in, he can send ads, otherwise latest ads will be listed.

 

1) Is this the way of thinking is correct ? Can it be done with this 3 classes ? Are my classes correct ?

 

2) Cause my page will change when the user is logged in ( ex : messages will be shown when logged in )

I was using a lot of echos and ifs like

if ( user is logged in ) show_messages ()
else  display_login_form()
.
.
public function display_login_form()
{
echo "<form name = "" action = "".... 

}

As a result I m really tired of correcting and adding " " tags to every html code.  So my question is can I display forms or files by include or require method ? like

 

// show messages table "messages.php file" require it when needed.
<table width="400" border="1">
  <tr>
    <td>Hello $this->username</td>
        <td>You have  $this->messagecount messages</td>
........

So in my page class I can just require or include the specific file instead of echoing the table or codes. Is it possible ?

 

Thank you in advance for your help.

 

 

Link to comment
https://forums.phpfreaks.com/topic/184432-classes/
Share on other sites

Any ideas ?

 

Are you able to instantiate and use sessions? That will fix your problem with the login form. What I'd recommend is sending them to a login page if say, $_SESSION['user_id'] is not set, And you don't need to write public functions to echo a form, it's a waste of server processing time than to just fit it in an IF statement.

 

And yes, you can include/require any file of PHP or HTML to set up a more simple template system.

Link to comment
https://forums.phpfreaks.com/topic/184432-classes/#findComment-973929
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.