sri1025 Posted February 5, 2007 Share Posted February 5, 2007 I am new to PHP and I have programmed a lot on Java. Now we are recently planning to write a web-based application on PHP. In Java, we usually wrote the business logic (the Model component) in separate set of classes and it is often separated from the presentation logic (the View component) which are JSPs. And to add to that, there is also a Controller component. Are these things separated and done in the same way in PHP? Let's say I need to query and return a list of all the employee details from a database table, then this is what I usually do in Java. --> Button Click --> --> Controller Component (which talks to the appropriate Model class, here the Employee DB Model) --> --> Employee Database Model (which returns the result to the caller, here the Controller) --> --> Back to the Controller, it fetches the appropriate View (JSP), adds the result to it (as a request attribute), and forwards the request --> --> Now the View (JSP), takes the result (from the request attribute) and displays it. We are planning to write the Model Component (that talks to the database) in Java, and the View and the Controller component in PHP. And we are currently planning to transfer the data from the Model (Java) to the Controller (PHP) through XML. But I think it's going to be very slow and a lot of work. Is it a good idea to carry on this approach or it's really not necessary to write the Model Component in Java and instead that can also be done in PHP? Please share your thoughts, I may well be joining your PHP club very soon. Link to comment https://forums.phpfreaks.com/topic/37125-where-do-we-write-the-business-logic/ Share on other sites More sharing options...
ultrus Posted February 7, 2007 Share Posted February 7, 2007 Hello sri1025, Welcome to the forums! Java is extremely foreign to me. PHP is something I use every day, but I lack many of the technical terms commonly used. As your post seems lonely, perhaps I can take a wretched stab at it while a true expert corrects me. I recommend using PHP to communicate with the database directly. I'd personally hate to write something in php that sent data to java, which made a query to a database, which then converted the results to xml, returning it to php, which would then have to parse it before using it. It seems like a lot of work and waisted processing. I'm guessing a lot of what you are doing can be done in php. You may find it useful to script modularly like you are now. I tend to separate different groups of functions into classes and make reference to them when needed (e.g. mail class, database access class, image manipulation class, encryption class). I build applications in pages, where each page serves a different purpose in the application (e.g. manage users page, login page, profile page). I've seen many ways of scripting php, and many people who have a "right" way of doing things. There are many ways to achieve your goals in php. If you stick to a method similar to what you are used to, it may work for you? I'm not sure if this helps as I ramble before hitting the hay. I hope this sparks something however. Good luck on your project. Link to comment https://forums.phpfreaks.com/topic/37125-where-do-we-write-the-business-logic/#findComment-178887 Share on other sites More sharing options...
sri1025 Posted February 7, 2007 Author Share Posted February 7, 2007 Welcome to the forums! Java is extremely foreign to me. PHP is something I use every day, but I lack many of the technical terms commonly used. As your post seems lonely, perhaps I can take a wretched stab at it while a true expert corrects me. Thank you very much! I recommend using PHP to communicate with the database directly. I'd personally hate to write something in php that sent data to java, which made a query to a database, which then converted the results to xml, returning it to php, which would then have to parse it before using it. It seems like a lot of work and waisted processing. Yes, even I think it is a wasted effort for literally no advantage. I'm guessing a lot of what you are doing can be done in php. You may find it useful to script modularly like you are now. I tend to separate different groups of functions into classes and make reference to them when needed (e.g. mail class, database access class, image manipulation class, encryption class). I build applications in pages, where each page serves a different purpose in the application (e.g. manage users page, login page, profile page). Sounds good and I really like to write my code in a more modular way with less coupling and more cohesion. I've seen many ways of scripting php, and many people who have a "right" way of doing things. There are many ways to achieve your goals in php. If you stick to a method similar to what you are used to, it may work for you? I'm not sure if this helps as I ramble before hitting the hay. I hope this sparks something however. Good luck on your project. I really hope the gurus to write their opinion to me and thanks for helping me with your opinion. Thanks, Srikanth Link to comment https://forums.phpfreaks.com/topic/37125-where-do-we-write-the-business-logic/#findComment-178914 Share on other sites More sharing options...
KrisNz Posted February 7, 2007 Share Posted February 7, 2007 theres a number of MVC frameworks for php, heres links to a few of them. http://www.cakephp.org http://www.symfony-project.com/ http://www.codeigniter.com Link to comment https://forums.phpfreaks.com/topic/37125-where-do-we-write-the-business-logic/#findComment-178915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.