Jump to content

I need one more advise of a good coding practice for Page Controler


Recommended Posts

I need one more advise of a good coding practice.

 

1. Page_1 contains HTML form.

2. User clicks on Submit and Form data is posted to Controller page for fields validation and then for making a new record into a database.

 

What is a good design pattern in PHP for Page Controller to perform the above mentioned actions? Provided that I have a separate Class for Validating fields and a separate Class for talking to database  - DAO.php.

 

 

Thank you!

 

 

 

Thank you very much for your replies!

 

thorpe, do you have a simple example of a Controller from your experience. I do not want to study an existing MVC framework until I understand the simplest and Correct use of Controller. I believe Frameworks offer more advanced features that I do not need at this moment.

 

I understand that View is html or php presentation page. Model is a Transfer Object + business some logic and Controller is some kind of swhich that makes a decission what to do and where to direct user Request and then a Response. But for very simple and common tasks that I described above what do you think is a very very simple and CORRECT example of Controller. 

 

I am searching for it online and all I find is frameworks or very complicated examples for PHP beginner to understand....

 

 

 

 

 

the mvc pattern doesn't mandate a physical separation of the layers. when developing in php i choose to physically combine the controller and view and implement the model in a set of classes. for instance, a simple registration process might utilize the following physical files:

 

  • register.php - this is the view/controller for the registration process.
  • UserManager.php - this is a class that contains the implementation of all user-related functionality. it is used by all view/controllers as well as other manager objects that need access to user-related functionality.

 

hope that helps.

 

jason

Will this be a good, correct and simplest example of MVC?

 

1. Page 1 contains a Form and submits Form data to Controller.php

 

      2.1. Controller.php calls UtilityClass to validate submited information for required fields and their format

      2.2. Controller.php calls DAO methods to insert data into database

      2.3. Controller.php sends email to user so he can confirm his email and finish registration process.

      2.4. Controller.php executes Header("Location:RegistrationOk.php") to display a message

 

3. RegistrationOk.php is displayed to show user a message.

 

 

 

Can the above example be considered a better approch for a small web site with few modules (Register, Login, List News) than a more proper MVC example described in this thread  http://www.phpfreaks.com/forums/index.php/topic,165712.msg729041.html#msg729041 or because of Redirection to a View or other Controlers in a sequence the above example is a not proper pattern to follow even for a small web site?

 

 

I wouldn't necessarily call it a better approach, but it will get the job done, and really, for something so simple its usually all that is required.

 

You say your new to php but what programming background do you have? New comers don't just start out speaking in design patterns and best approuches.

 

The MVC pattern (or any other pattern) is the same in any language. So, whatever background you have, just apply the same logic to php.

Thank you for your message and thank you for your support in this thread.

 

I have some Java background but very little experience with PHP. Need to master it for a web project ASAP. So I went online to study PHP OO, Best Practices and ofcourse Patterns like MVC, DataAccess Object, Value object. Yes, you are right! concepts are very similiar and many design patters are common in programming languages... but for educational porpuses I do not want at this time to use any of PHP MVC frameworks and started asking basic questions.. Once I am more familiar with PHP I will surely choose some frameworks to use...

I think you'll find most people who apply OOP to PHP have done so through examples written in Java. The concepts aren't just similar, I would say they are the same.

 

The basic site you seem to be describing doesn't likely need a framework to support it, you could build your own simply infrastructure.  I was just letting you know there are plenty of good examples of OOP designed implementations already out there.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.