Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help! File Management in MVC-pattern PHP / mySQL Application

Posted on 2009-05-04
4
Medium Priority
?
287 Views
Last Modified: 2013-11-08
Hi experts. A grey Bank Holiday in England so a good excuse for some development :-) I'm looking for some help with my app. I think part of the problem is file management, and the rest is because I'm new to the whole world of object-oriented code. Allow me to explain...

I'm setting up a website with a remote assistance service. On my homepage, I have a login box on the right side. I want this to be a quick entry route into starting a remote assistance session.

The app needs to:
- Check if the user is logged in
- If no, display a username/password form
- If yes, display some data about that user's account, a "Welcome, [user name]" message, and the form which allows the user to initiate the remote assistance service.

I could code this fairly quickly with a simple procedural approach, but I've had a taste of OOP / MVC and I like it! However, I'm having some trouble 'bringing it all together'. Let me explain the two immediate problems, and I will then explain my app architecture:

Problem 1:

I have separated my files as below. My core classes, business model, controllers and views are all in separate folders. Let's say my db_connect script needs to 'know about' my db core class to perform its actions. Should I include() the db core class in the db_connect script, or should they all be glued together elsewhere?

Problem 2:

My understanding is that the controller should take user input, consult the model, and then generate a relevant view. Rather than generate two entire homepages depending on whether the user has logged in or not, how should I configure my app so that I can have one homepage 'view' with two alternative login areas?



Core Classes (ones that I could use across multiple apps)
-------------------
"html.php" - class to simplify generation of a standard HTML page (meta tags, google analytics code etc..)
"form.php" - class to simplify HTML Form code generation
"db.php" - class to handle connections and queries
"user.php" - class to handle a user object with login, data collection and logout methods

Model
------------------
"db_connect.php"

Straight script. Creates a "db" object from core classes, and calls a method with (hostname, username, password) parameters to open the database connection.

Controller
-----------------
"login.php"

Checks to see if the login form has been submitted.

If yes, the "login" method in my "user" core class is called.  The database is queried to check the username and password match. If yes, session variables are created for future authentication.

View
------------------
"index.php"

A mix of HTML and object-oriented PHP built from my core classes. No logic, just output.
0
Comment
Question by:jimbo2k2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
mostart earned 2000 total points
ID: 24295666
Well in the end you could do what you want. But if you like to have a OO and MVC approach why reinventing the wheel. You should consider using a MVC framework like ZEND (http://framework.zend.com/). This will give you all components OO style. It also makes a lot of things much more easy by providing handy classes for lots of jobs such as DB communication, form generation, Mail, Localization, Validation and many more..

I'm not a Zend Consultant and there might be other Frameworks, this is just the one I used yet and found very handy. Others I also used are not for PHP..
0
 

Author Comment

by:jimbo2k2
ID: 24295930
Thanks for your comment mostart.

It is tempting to use a framework, but I am always put off by having to learn the framework first. I think I would prefer to work with my own code, especially because I am trying to learn PHP and OOP rather than just 'get something done'.

I suppose I want to understand the thought process of an experienced PHP programmer in approaching this problem.

I was just thinking, maybe I could create a 'view' for multiple page elements (header, navigation, body, login area, footer) and then write a simple script to glue it all together?










0
 
LVL 8

Assisted Solution

by:mostart
mostart earned 2000 total points
ID: 24295985
>I was just thinking, maybe I could create a 'view' for multiple page elements (header, navigation, >body, login area, footer) and then write a simple script to glue it all together?

yes I think this is a good idea in general.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question