I would like to start development on a web application but really have no idea how to do it. I like to think that I am pretty well versed in PHP, but feel like my coding practices are off. What I would like to know is, what is "the best" way, or a way that you have found to work for you for writing a powerful web application in PHP? I have read about Zend Framework and tried to follow a fairly simple tutorial using it. It seems pretty powerful, but it can be somewhat confusing.

I guess what I'm really asking is how do I come up with the structure of my code? For instance, I have customized this script in the past to fit my needs, http://www.evolt.org/node/60265, and it's very useful and the file structure and so forth makes sense to me, but I just have no idea how they came up with it. Is there somewhere I can read to figure this out?

Thanks!

This isn't an easy question to answer. In some ways using one of the frameworks might make the designing easier but you do need to spend some time learning how to use the framework. I learned PHP about 7 years ago. Previously to that, I did a lot of programming on mainframes and PC's. I think the knowledge about how to structure a system in PHP came from:
1. Many years of building and modifying systems of all sizes on a variety of hardware and operating systems. This built basic knowledge of how to design systems.
2. Building a knowledge of what facilities PHP provides and how to use them through trial and error, reading the documentation, reading forum posts and so forth.
3. Looking at, installing and modifying a large number of open-source PHP systems.
4. Building some of my own systems and going through a learning process where I discovered better / more flexible ways to implement features as I gained more experience.

I don't think there is any silver bullet for this but once your PHP knowledge is adequate, looking at how some of the larger open-source PHP systems (e.g. CMS Systems) have been structured will provide some examples of how to build sophisticated systems using PHP (and MySQL). I keep learning and finding better ways to do things. It takes a long time until you get to Guru level and have done it all. Not too much is really new. Once you see how other people have done things, you can reuse and adapt their approach, whether or not you're at the point where you could have invented it from scratch. There is a huge base of open-source PHP code that you can use in your own applications. I built a scheduling system by starting with a calendar application that I liked and then I modified it and built around it. It is used commercially and it's now up to about 160,000 lines of code in PHP, html, javascript and CSS. The structure isn't scientifically perfect but it works and I improve on it as I go.

Hope that helps a bit.

I really appreciate the reply and it actually helps a lot. It seems this is more of a learning process than just learning some standards one time. This is good news to me. It means I can get right in and start creating what I like and then adapt my code as I learn new things! Once again, thanks a lot for the help. I have been searching for an answer to this question ever since I felt versed enough in PHP to write my own applications.

For anyone interested, I've found that learning a framework and particularly the MVC method of doing things is the way to go. It's so elegant and you can code powerful systems in a short amount of time.

I recently learned how to use CodeIgniter and I love it. I think this is probably one of the better ones to start on. It's not hard to learn and gets you used to OOP in PHP and MVC and working with frameworks.

I originally was going to use Zend Framework, but their tutorials just do not make it easy at all. If you're looking for a framework to learn on, you'll likely be reading a lot of the documentation, and this is where CodeIgniter shines.

To give you an idea, I coded a secure login script--which gives each user his own personal profile and allows new users to register--in under an hour! All the error checking, data sanitation and everything included.

This is a question that has often plagued me--in PHP, and any kind of development, really. I get obsessed with the absolute correct way to do something, and the search to find that method overshadows the need to create the end product. Often, I never find that method, and the end product is never created, or sometimes never even started.

I've learned that, in most cases, there is no single right way to do something. Important guidelines exist that must be followed, but even they leave fairly broad wiggle room. Learn as much as you can from books, but don't neglect the best teacher: experience.

When I begin learning a new technique, I usually spend a little time playing around before I get serious about design. I learn a little bit, then start coding with no intention of my work being in a final product. Most of this code will be thrown away, but the time invested is minimal. I may go through several iterations of starting, starting again, and again, and again, taking notes as I go along. In each new iteration, I'll reuse the good from the previous attempt.

Note, however, that this process is one of learning, not engineering. Currently, most of my work does pertain to learning since I'm still in school, but I doubt my method would work well in a serious job situation in which I'm expected to already know my stuff. It's also not usually suited to class assignments, which are crafted such that little experimentation is necessary. I mainly use it when I'm trying to learn something on my own time, which is the approach I'm taking with PHP.

I'm not to the place where I can compare the merits of various frameworks, but the Jobeet tutorial for Symfony frameworks looks very promising, and I really want to go through it soon:

http://www.symfony-project.org/jobeet/1_4/Propel/en/

I went through the Zend tutorial last year and got through it but found it confusing, mostly the setup not so much the php per se.

I expect Symfony, Zend, CodeIgniter, CakePHP et al. are fairly similar. In fact I'd love to hear from someone who begs to differ. (I heard Zend has the best multi-language support and Magento e-commerce works with it, if you need those things.)

Yeah I think out of those Zend is supposed to be the most powerful, but it almost feels like they did too much with it. The hard part about Zend for me was the language they used. Having to learn MVC and the language that accompanies it, at the same time is kind of a task.

I have to say I cannot be happier with CI.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.