What PHP application design/design patterns do you use?

前端 未结 9 1337
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 18:12

Please share your favorite application design / design patterns for use in PHP with me. Some things I\'d like to know:

  • How your folders are designed
  • How y
相关标签:
9条回答
  • 2021-01-29 18:17

    i've explained most of my PHP methodology here.

    but nowadays, i just use Django everywhere i can.

    0 讨论(0)
  • 2021-01-29 18:20

    I have to agree with the above posters. If you're not using a framework when programming in PHP you're really programming with your hands tied behind your back. I personally recommend CodeIgniter. It's the fastest framework around, it's very easy to learn, and has a very active community. All of your questions will be answered by the framework:

    * How your folders are designed
    

    CodeIgniter (or any framework for that matter) separates your logic into views, models, and controllers, each with their own folder.

    * Do you have a standard way of dealing with CRUD, pagination, or any other common tasks?
    

    CI has a pagination library, and it has 3rd party libraries like DataMapper for wrapping your CRUD calls in an object oriented way (ORM).

    * What are ways in which you can make your code more elegant?
    

    The seperation of the model, view, and controller make for very elegant code.

    (The 2 questions I didn't answer are pretty much implied when using the framework)

    0 讨论(0)
  • 2021-01-29 18:21

    I started out with the smarty templating engine when i first got tired of mixing code and html. After hacking for a while, I realized that writing my own framework is just duplicating work.

    I've done a few projects with Joomla, which is really a CMS but it gives clients a lot of control over content.

    Ultimately I've settled on using a real framework for my projects. I'm using symfony, which is inspired by Rails and is very well documented, but I've heard cakePHP and ZendFramework are also very good.

    0 讨论(0)
  • 2021-01-29 18:24

    I use Zend Framework, which pretty much defines folder layout and OOP (MVC paradigm). For common tasks, such as for example pagination I use Zend_Paginator (my model classes implement Zend_Paginator_Adapter_Interface), for validation I use Zend_Validate classes etc. Thanks to that I can fully concentrate on business logic instead of reinventing the wheel.

    0 讨论(0)
  • 2021-01-29 18:32

    I imagine a lot of php developers have followed a similar route to mine: small scripts -> procedural/inline-code -> possibly a look at templating -> OOP -> then a framework. I think it may be quite common for a PHP developer to have "grown up" with PHP, learning design patterns to match the features available with the current version.

    MVC is the most frequently used design pattern in the popular frameworks being used today. CakePHP is my framework of choice although Symphony and Zend are very popular too – it's well worth trying out a few and it'll soon become apparent which you feel most comfortable with.

    For most projects (where rapid development and portable code are the priorities) I use Cake, however for light weight apps (one I developed recently was Good Baad) that you'd like to run fast (on low spec hardware) and do not need the bulk/weight added by the functionality of one of the large frameworks I recommend reading Rasmus Lerdorf's article on his No Framework PHP MVC framework.

    Basically if you're after a true object oriented language that encourages beautiful code and the best design practices PHP is always going to lose out to the likes of Ruby Python and C#. But, PHP has its strengths e.g. no need for a templating language (it is one), PHP can run very fast and cheaply and does not need the weight of a large framework for all applications.

    I'd encourage adopting a design pattern that takes the manageability of a design pattern like MVC and combine it with PHP's strengths.

    0 讨论(0)
  • 2021-01-29 18:36

    I've been messing around writing my own stuff for a while now and everytime I can never get around to finishing it fully because I get stuck on something.

    And then comes the part where I come to realization of whether I am doing something right.

    And as such I have given up on writing my own an going with a crowd favourite: Zend.

    I looked at others but it seems Zend has been around a while and they know their things.

    MVC is also the way I am going forward with anything I write now.

    0 讨论(0)
提交回复
热议问题