Jump to content

Where do we write the business logic?


sri1025

Recommended Posts

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

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.

 

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

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.