Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1

    Please give me some advice on PHP coding style.

    Hello,
    I'd like to get some help/advice on the way of writing PHP codes.

    Generally I write a page like
    1)Include a template page which may have the other include directives of class-files, functions for adding doctype, <head> section, page heading, nav-bar, footer etc.
    2)Each page may include some specific class-files if any.
    3)Call the functions from the template wherever required and call other functions from class-files according to the required flow execution.
    4)No html part is generated inside class-file, rather it'll be added in the other files along with the data obtained from the class-files if any.
    5)Don't use same page to display contents with no logical relation with the help of if-else statements.
    6)Finally the html part is separated from PHP AFAP.

    For me, its very easy to maintain the site.
    Now my problem is, it's very hard to customise free packages like phpBB, Joomla etc since they all follow a different style of coding. I know they are doing in the right way because they all provide an easy way to configure the setup even for one who don't know anything about PHP.

    Are you all doing similar to them? Is there any resource to learn a style like that? I'm still a beginner, so please give your valuable suggestions.

    regards,
    art
    Last edited by abduraooft; 09-05-2007 at 12:34 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    code in your own style, if thats how you find it easier to code do it like that.

  • #3
    New Coder
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes I have developed my own style in coding, and have found that a creative mind is the way to go.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    OK, thank you both for quick replies.
    Actually I came up with this thread is on behalf my previous unanswered thread regarding ExtCalendar package (Anybody there to give some help on ExtCalendar-2 package?)
    I hope you may have seen how the thread regarding php-logo has been solved, and as you all know it's not the right way to solve this problem(help with phpbb styles)

    I can't simply give up this thread without getting some introduction on the above mentioned style of coding as our Active membership count is 8,496 .

    regards,
    art.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    code in your own style, if thats how you find it easier to code do it like that.
    I found this somewhat amusing.

    Q: How do I do X?
    A: Do it your own way!

    To answer the topic; sites like phpBB and Joomla don't necessarily use the right way. I've found that with most "big" open source packages the source code is rather convoluted and hard to read. Not to mention bloated. I certainly wouldn't use them to measure your code quality with.

    You have some good methods of coding going, but there is always room for improvement.

    The main thing that I find helps me is Object Oriented design, but in a more basic way. I tend to model the basic, grand scheme of things. For instance, I have a class that handles displaying a page in a certain way, reading certain files, etc. I have a few that handle the page differently, but they all do the same thing (rendering HTML to present to the user).

    2)Each page may include some specific class-files if any.
    I forgot where I read about this, but this is my setup. Every class I create has its own source file. The way I set up the naming of the class and the files, means I never have to include any source files, because I use __autoload().

    For instance, a database class for MySQL would be called Database_MySQL, and it would be found in: Database/MySQL.php (notice how the _ gets translated to a /)

    All I have to do in code is: $db = new Database_MySQL(); and the autoloading feature will automatically include my class file.

    6)Finally the html part is separated from PHP AFAP.
    Remember that your goal is to seperate business logic from presentation logic, not HTML from PHP. This is a common misconception, which has led to templating "methods" such as Smarty.

    PHP -is- a templating language. That's what it originally was, and it still is. There is no reason to introduce some esoteric language that you have to learn in addition to PHP.

    Business logic should be seperate from presentation. So that you may modify the output without changing the quality of the output.

    Are you all doing similar to them? Is there any resource to learn a style like that?
    There is 1 resource that will give you the most effective coding solution: your experience.

    The more you use PHP, the more you will understand it. The more you understand it, the more efficient your code gets.

    There is not 1 right way.

  • Users who have thanked aedrin for this post:

    abduraooft (09-05-2007)

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Aah... great relief! thanks a lot.
    Quote Originally Posted by aedrin View Post
    Remember that your goal is to seperate business logic from presentation logic, not HTML from PHP. This is a common misconception, which has led to templating "methods" such as Smarty.
    Could you please explain a little more on your point on Smarty. Is it a bad one?
    (I don't know much about this and haven't used)
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    It's not necessarily bad. It's a good idea, but in the end it is just another layer over PHP with nearly the same syntax as PHP. While the whole point was to prevent people from writing PHP.

    There are some good uses for it, but I've never found one that required me to use it. Usually it is easier to create something yourself.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •