How do you organize your PHP scripts and files?

Even if you are using a template language, I’d bet that you still have to charter some programmer to turn that new design into something functional. The designer probably won’t get it.

Actually, I jumped to that conclusion… has there been a PHP-dunce designer who could go through, create a new design, and then edit all the template-lang-type statements back into said design? The only way I could see this happening is if there were tags that looked like html, but offered additional functionality (<if>, <repeater>, <cycle>, etc). But even then, if you had something like the following, I bet that php-dunce designer would get thrown for a loop: <div class=“alt1 <if condition=”{$current}“>current</if>”>words and such.</div>

I can understand the seperation of most code from design, as it makes my life as a programmer easier, but I’m not sure if it makes the designer’s job easier at all…

No, why I would i trust him to change php files? He is a DESIGNER, not coder. Designers shouldnt ever need to change php

It doesn’t matter if it’s php, python or smarty, if they break it, they break it :slight_smile:

A better and more maintainable solution would be to use PHP & XSLT.

HI

What if you don’t want to give your source to someone? Is it possible to encrypt your files with ION cube or Zend encoder if you’re using some of mentioned frameworks ?

What is the procedure?

Thanks

Why are Codeigniter and Cake trash? Can you explain a bit further? What is it about Symfony that is so promising in comparison?

  1. Don’t use short tags then…
  2. See all the other comments - if you have loops in your template meta language, it is just as easily broken as if you just used php in the first place instead of wasting time with templates.

And I do keep my business logic code separate, in the classes. The presentation layer then uses these classes and outputs the html directly. Using a template to do that is just creating an extra layer of complexity for no added benefit whatsoever.

from the horse’s mouth http://devzone.zend.com/article/1236-The-Best-Tool-For-The-Job-OO-versus-Procedural-Programming-in-PHP

the FACT that you complain about PHP’s OOP speed and the SAD FACT that this topic exist just goes to show you OOP in PHP is an after though. PHP was never build with OOP in mind from the ground up unlike Ruby, Python, Java or C#.

for programing languages that build with OOP from the ground up, the speed is never the issue and the NAME SPACE is how you organize your code and not some made up “blah_class.php”.

PHP6 promise the support for Name Space and other OOP goodies. let’s hope Zend doesn’t put out yet another half-baked OOP support in PHP.

Its kinda funny

the procedural guys claiming OO is slower (tho still no benchmarks presented of latest PHP5 with APC of procedural vs OO)

they seem completely oblivious to the benefits OO when used properly by knowledgeble programmers for medium to large size projects (no im not talking about mickey mouse blogs or small sites, im talkin about large web apps that actually make alot of money)

its hilarious that users are arguin about OO vs Procedural when in fact most of the speed problems with php come from them using Apache (mod_php) not a server like lighttpd or nginx (php fastsci) which would give them a magnitude faster results for large sites, its like arguing about the size of the engine in a truck which has bicycle wheels on!

also alot of webapps are slowed not by php but by mysql, using latest mysql with innodb and memory tables + ramdrive caches + memcached will help alot, tho it seems from the posts here alot of users use shared hosting (where speed is out of theitr controll anyways) and wouldnt know how to run own servers or compile programs on linux or optimise large php sites

its quite apparent from this thread that there are many misconceptions about PHP which is sad

btw the example @ http://www.webmasterstop.com/56.html is very badly written! the muppet initializes the object every time arround the loop! lol

I’ve been using the Zend Framework since it was first made available. It has been the best aide in teaching me php 5 and object orientated programming.


/stage (apache document root and phing build directory)
/branches
/tags
/trunk
    /app
        /www
            /controllers
            /views
        /cli
            /controllers
            init.php
        /admin
        /ads
        /mail
        bootstrap.php
    /build-tools
        build.xml
    /data
        /cache
        /uploads
        /sql
        /sessions
        app.log
        php.log
    /docs
    /etc
        apache2.conf
        php.ini
        app.ini
    /lib
         /Zend
         /PersonalFramework
    /share
        /www
            /images
            /css
            /js
        /admin
        /ads
        /mail
    /tests

root

  • includes
    • connections
    • defaults
  • javascript
  • media
    • audio
    • css
    • images
    • flash

/index.php
/rpc.php
/boot.php
/dynamic
–frontend
–backend
----modules
–cache

/static
–images
----global
–css
----global
–flash
–javascript
–misc

all basic php classes goes into/dynamic/backend while site modules ie the model goes into /dynamic/backend/modules
all templates ie the view goes into /dynamic/forntend/Template Name
all template related images and css goes into /static/images/Template Name /static/css/Template Name
in both images and css folder there is a global folder. in global folder all the images/css used globally by all templates will be placed
boot.php when included in any php file boot’s up/initialize the whole application
the main class and the main controller is located in /dynamic/backend/main.php which routes the traffic to the modules
rpc.php allow to call the module methods which will return the data in json xml or normal html

Interesting the mix of replies on this topic.

I use my own MVC Framework. I will never go back to doing things the way I did before. When you start to get very huge applications, it’s can be a nightmare to maintain and evolve to work with new features and requirements. So, separation of things into the various MVC layers makes a cleaner more manageable design.

For those that throw function libraries into a main include, what if you jsut don’t need all those libraries on every page? With MVC, you dynamically load only what you need for a particular functionality. I’d gladly trade off a few microseconds for less scratching my head when it comes to how am I gonna work in some new functionality.

Most of my reusable includes are outside of the web root. I use XAMPP in the opt folder on Linux.

/opt/myframework/config (server specific config)
/opt/myframework/includes

In the includes:
auth/
db/
debug/
error/
export/
html/
ldap/
log/
mvc/
mail/
states/
types/
xml/

In the webroot, I have:

opt/xampp/htdocs/app1
opt/xampp/htdocs/app2
opt/xampp/htdocs/app3

Inside an app folder:
config/ (app specific config)
css/
java/
images/
realm/
template-cache/

The realm folder contains related sets of sub applications. Inside a realm folder would be at least:
models/
templates/

and optionally
includes/
web-services/

Each template folder has an optional nav.tpl file. It contains a category name and set of links to the sub applications. If the file exist, the framework will pick it up and stick it into the left side main application navigation automatically. So, I can drop in new sub applications easily without having to change any of the main templates.

I use mod_rewrite to alter the URL:
http://msite.com/app1/realm/model/event

becomes

http://msite.com/app1/index.php?realm=some-realm&model=some-model&event=some -event

Every application has a default realm which contains the an error model, a login model, logout model, maintenance model. The default templates contain templates for each for the above models, plus common data output utilities, like result.tpl which prints a beautiful table for any 2d array of output from a database query, complete with optional pagination.

index.php loads my controller. The controller looks for the model named some- model and loads it. If the model is not found, it loads the error model and sends it the error code for “Model not found”. If the model exists, the controller checks if login is required and if not logged in, loads the login model instead, remembering the path of where the user was trying to go so it can take them there once they’ve logged in. Also, the controller looks at the event the user is requesting and checks if it’s a restricted event. If so, it looks up that user’s membership in any group that is allowed access to that event. If not a member, the error models is loaded with a “Your not Authorized” message.

Each model is derived from a parent model which gives the same base functionality, like session management, database connectivity, creating the base view which loads the main templates for that sites look and feel. Adding a new page can be as simple as creating a new empty model derived from one of the parent models and calling the display() function. Only a few lines of code. If I need to output a phone list of all employees. I add just a few lines: query = “some sql”, execute query, fetch all to array, assign result template, assign result array, display.

As I said, I’ll never go back to the old way of doing things. I’m still learning, but MVC, OOP has made things much easier without a doubt. It’s a “night and day” difference.

Please do not presume how much I know about OOP. I know a lot. I myself build all my large application using my own MVC Pattern with PHP5 OOP. I reuse code all the time with my own class and function libraries. I do not stereotype myself as any type of coder. I myself run my own dedicated server and have run many commands on it. APC has it drawbacks too, because it can use more memory on your server.

Easy… use a real language, not one with OOP bolted on and mixed with procedural functions that can’t even keep a consistent name among all of them.

oh php is far from perfect but what do you suggest?

I sometimes wonder if people have any criticism of php that isn’t “oh but i don’t like the function names” - its a really lame argument. As for oop, its getting better all the time with php. I’d certainly much rather use php than asp.

no one uses asp anymore

its c#/asp.net

and as a phpdeveloper i will admit they have got alot of things right that php hasnt yet

I’ve read this argument about Smarty many times and I have to disagree with it completely! [LIST=1]
[]Invalid Smarty syntax will break your pages just as quickly as bad PHP code.
[
]If you aren’t using a revision control system already you need to be. Don’t allow anyone (including yourself) to overwrite important application files permanently.
[]Any application that uses Smarty requires a developer who knows the syntax. You are more likely to find a designer familiar with PHP than with Smarty.
[
]As for designers who know nothing about Smarty or PHP, why would you want them to learn Smarty first? PHP is just as easy to learn, and raises their skill level so they could be utilized over a number of different projects and tasks.
[*]Smarty adds way to much overhead to your web application! Everything that is accomplished with Smarty can be accomplished with the same amount (or less) PHP code. To quote the php.net website, “PHP is a general-purpose scripting language that is especially suited for Web development and can be embedded into HTML”. Why add this unnecessary level of abstraction when you can accomplish all your requirements using the core PHP language?[/LIST]I prefer the Zend Framework approach to views. It keeps my templates clean, lean and mean.

[page.phtml]


<?php
$this->headTitle('Page Title');
$this->headScript()->appendScriptFile('/js/tinymce/tiny_mce.js');
$js = <<<EOT
    tinyMCE.init({

    });
EOT;
$this->headScript()->appendScript($js);
$this->useLayout('abc.php');
<body>
    Hello <?=strtoupper($this->first_name)?>!
    <?=$this->form?>
    <?php if ($this->isAuth()) : ?>
        Show special auth menu
    <?php elseif; ?>
        Show regular menu
    <?php endif; ?>
</body>
?>

Maybe, but then I hate the whole idea of frameworks anyway.

Perhaps. I’ve worked on web apps in C#/ASP.NET and PHP, and I just enjoy writing the PHP code more.