simplyi Posted January 13, 2010 Share Posted January 13, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/ Share on other sites More sharing options...
simplyi Posted January 14, 2010 Author Share Posted January 14, 2010 why? no one uses Page Controllers? ... Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994591 Share on other sites More sharing options...
Lamez Posted January 14, 2010 Share Posted January 14, 2010 What is a page controller? Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994602 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 I would stick with he MVC pattern, in fact you might want to take a look at and maybe even use one of the (hundreds) already existing MVC based frameworks. Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994604 Share on other sites More sharing options...
simplyi Posted January 14, 2010 Author Share Posted January 14, 2010 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.... Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994612 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 This is a simple example I wrote for someone a long while ago. Its got a few typo's and has never actually been tested but should give you a general idea. That entire thread is probably a good read. Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994616 Share on other sites More sharing options...
nankoweap Posted January 14, 2010 Share Posted January 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994626 Share on other sites More sharing options...
simplyi Posted January 14, 2010 Author Share Posted January 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994629 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 That's not really an MVC implementation but it will do the job. MVC is generally overkill for something so simple. Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994631 Share on other sites More sharing options...
simplyi Posted January 14, 2010 Author Share Posted January 14, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994633 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994635 Share on other sites More sharing options...
simplyi Posted January 14, 2010 Author Share Posted January 14, 2010 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... Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994652 Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188388-i-need-one-more-advise-of-a-good-coding-practice-for-page-controler/#findComment-994658 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.