Questions regarding the latest tutorial (1.3.0)

I've been asked a couple of questions via email that I think are probably worth answering here, just in case others are wondering the same thing!

1) Why did you change the functionality of the BaseURL? You moved the BaseURL to the IndexController and in the previous version it was in the Bootstrap.

The main reason I did this is that the new MVC code works out the base URL for us in the request object, so use it rather than do our own. Also, in previous versions of the tutorial, I had hard coded the URLs in all the templates, so I took the opportunity of the reworking to fix that too.

2) In the previous version the template files were called filename.tpl.php. Now they are called filename.phtml. Why did you do this? I think the first option is better, the reason being that if something goes wrong with the .htaccess file, visitors see the source code if the webserver does not know of .phtml files. In case of the filename.tpl.php method, nothing bad happens since the .php files will be processed by the webserver and will probably just give errors on the screen instead of the source code.

The .phtml extension is the default used in the new view integration code in Zend_Controller_Action, so I used it too. On the proposal, Mathew Weier O'Phinney stated:

Suffixes are a developer preference, really; you don't need to use .tpl with Smarty, nor .php with Zend_View. I actually chose .phtml as (a) most apache configurations specify it as an alternate extension associated with the PHP engine, (b) most IDEs and text editors will identify .phtml as PHP + HTML for syntax highlighting, and (c) it visually separates template scripts from other PHP files in the directory tree.

Personally, I quite like .phtml as it reinforces the idea that the template files are HTML files with PHP in them. It's easy enough to get render() to use .tpl.php: just set $this->viewSuffix in your init() function.

I hope that makes sense. If anyone's got any questions, please ask away!

If you would like to comment on this article, please ping me on twitter.
If your response won't fit into 140 characters, write a blog post and then ping me!