25th March 2007
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!
Posted in PHP | 14 Comments »
25th March 2007
Having promised that I'd look into a tutorial for Zend_Auth ages and ages ago, I've finally managed to get one together…
Note that this tutorial only covers Zend_Auth; Zend_Acl will have to be the topic for another one at some point in the future!
As always, if you have any comments (especially corrections!) then please let me know. Who knows? Maybe we won't need 30 revisions to catch all the typos this time!
Update
That didn't take long! David found some typos within 15 mins!
Posted in PHP | 10 Comments »
24th March 2007
I've finally managed to update my tutorial for version 0.9 of the Zend Framework. Sorry for the delay.
This is a significant reworking of the code to take into account the changes in the framework, so there are bound to be a few typos. If you find any, I'd appreciate it if you could let me know!
Posted in Tutorial | 4 Comments »
18th March 2007
The good news: Zend Framework version 0.9 came out today
The bad news: There's a typo in Zend/Db/Table/Row/Abstract.php! (Issue is ZF-1080)
To fix it, add a < at the start of the first line of Zend/Db/Table/Row/Abstract.php so that it reads:
<?php
Oh well…
Posted in PHP, Zend Framework | 5 Comments »
10th March 2007
For those of you not following along on the fw-general mailing list, the Zend.php file along with its Zend class has now gone! This is good news as the Zend class was schizophrenic and provided functions responsible for file loading, registry, debugging and version information! Another side effect is that the entire Zend Framework is stored within the Zend directory making those who use svn:externals on their lib directory happier.
We now have new classes:
- Zend_Loader (holds loadClass(), loadFile() etc.)
- Zend_Debug (holds dump())
- Zend_Version (holds VERSION constant and compareVersion())
and Zend_Registry now has a static getInstance() method.
Another change is that the static filter methods in Zend_Filter are gone to be replaced with the Zend_Validate and Zend_Filter family of classes. Now, each filter is its own class and you can chain them together using the new Zend_Filter class. It's much more flexible, but feels much more verbose too, especially when you have to instantiate a lot of different filters for filtering a form. I suspect that someone will come up with a nice solution to filtering forms at some point though. Also, Zend_Filter_Input is also gone, though this isn't surprising as it didn't work with the newer MVC code anyway
Top Tip: Don't bother with Zend_Filter_Int. It's faster and much less typing to just cast to an int directly!
I've updated the subversion code of my tutorial to work with the latest svn of the Framework, for those of you who may be interested. Be aware that in anticipation of some other stuff that Matthew is working on, I've rewritten it to use header/footer php files for each action's view template. Another change I've made is to remove the dependency on hard-coded URLs for the CSS files, href and form method attributes. I now use getBaseUrl() to collect the correct path and go from there and so you can now run the tutorial from any directory and it'll "just work"! I'm unlikely to update the tutorial text until 0.9 is out though as there is quite a lot happening this cycle.
The transition work was quite easy:
- Replace include "Zend.php" with include "Zend/Loader.php"
- Replace all calls to Zend::loadClass() with Zend_Loader::loadClass()
- Replace all uses of Zend_Filter_Input with a call to the correct Zend_Filter_Xxx class and
use $this->_request->getPost('{name}') to get the data from the form.
The main gotcha that I found was that the dump() function doesn't work until you remember to Zend_Loader::loadClass('Zend_Debug')! That's fairly obvious really, but does make using autoload that much more worthwhile :)
Update: Andries Seutens has more details!
Posted in PHP, Zend Framework | 6 Comments »
5th March 2007
A few people have asked about updating my Getting Started tutorial for version 0.8 of the Zend Framework.
I finally had a chance to check the code and it worked fine with no changes (as expected!)
Darren, one of my colleagues as recently gone through the tutorial for me and found some typos, so I have put out a new version (1.2.4) that fixes these. I've also updated the code too to make it slightly cleaner.
Posted in Tutorial | 10 Comments »