views:

80

answers:

3

Hello There,

I have been developing my own PHP MVC framework. Now I have seen different frameworks implementing different extensions for the View files. I am using simply php extension for my view files.

Now is there anything wrong if i use php extension.

Are there any merits or de-merits of it?

Why use other extension such as: phtml etc

+1  A: 

If you're talking about using these extensions in public facing URLs, then I would say don't use either:

File name extension. This is a very common one. "cgi", even ".html" is something which will change. You may not be using HTML for that page in 20 years time, but you might want today's links to it to still be valid. The canonical way of making links to the W3C site doesn't use the extension.

(Taken from W3C URL style guide)

You can achieve this with mod_rewrite, for example.

However, if you're talking about how to name your files in the filesystem, it's largely a matter of taste. I think both the extensions you suggested (phtml and php) make sense, the main thing is being consistent.

Edit: Also, since you said this is for a framework, you should consider choosing a non-standard extension may require extra webserver configuration. For example, to support both .phtml and .php in Apache:

AddType application/x-httpd-php .phtml .php
oops
thanks for such great explanation oops.
Sarfraz
This is a good explanation of what would happen if you tried using phtml as the file extension for the controller, but that is not what he is talking about.You can include a file containing PHP with .monkeysuncle and it will still run fine.
Phil Sturgeon
+1  A: 

There's nothing wrong with using PHP extension if the code inside is valid PHP. It's nice to indicate somehow that a file is a view script. That's why some use .phtml. But I guess, you put them in a separate place-for-views anyway, right?

A benefit of .phtml is that it's obvious what kind of file it is when displayed in a "Jump to file" list. It's a feature of my IDE I use a lot: just typing a part of any file name in a project and picking the one to jump to.

Ivan Krechetov
A: 

It really doesn't matter what you use and as far as Apache goes its exactly the same if you are directly including the files.

Some use .tpl, some use .php and some use .phtml. Just pick the one you like the look of most.

Phil Sturgeon