My Take on a Zend Framework Tutorial
I thought I’d turn my hand to writing a tutorial… As both readers of my blog will have noticed by now, writing prose isn’t my strongest point, but hey! you don’t have to read it :)
I ended up doing it as a PDF as I found writing it in a wordprocessor easier than anything else I tried. It also ended up quite long!
The PDF is available at http://www.akrabat.com/zend-framework-tutorial, so please leave any comments/corrections here. Thanks!
Nicely written, clear tutorial Rob and it was quite gratifying for me to see that I'd set things up in much the same way you describe.
A few small things I'd like to mention:
Your php_flag .htaccess settings…
zf-tutorial/.htaccess
RewriteEngine on
RewriteRule .* index.php
php_flag magic_quotes_gpc off
php_flag register_globals off
…will cause issues for anyone running php as cgi/phpsuexec where you cannot manipulate the php.ini settings within .htaccess. They should do it in a custom php.ini.
Do you find any specific benefit to "registering" the post in the bootstrap…
Zend::register('post', new Zend_Filter_Input($_POST));
Now we can get at a post variable with the following code:
$post = Zend::registry('post');
…versus just going…
$post = new Zend_Filter_Input($_POST);
…in the controller? There isn't anything wrong with it but it just seems a small additional layer and a little extra to take in when getting started.
Oh and this mention; "after creating a Zend_Filter_Input for $_POST, $_POST is then set to null" is very useful, one I hadn't taken note of and means you need to be careful to check for the presence of $_POST BEFORE using Zend_Filter_Input so you could well be caught out by doing this…
$post = new Zend_Filter_Input($_POST);
…then later in your code doing this…
if( !empty( $_POST ) )
…which would always be checking against a NULL'd $_POST.
Thanks for taking the time to put this together.
Thanks for the feedback Nick.
I didn't know about the .htaccess thing in cgi.
Regarding registering post and get in the bootstrap, I did that because, in my "real" application, my current router looks up stuff in get as it doesn't use rewriting at all. Thus, I needed to retrieve the $_GET in both the router and the controller action. Seemed logical to do it right at the beginning.
It also has a "best practice" benefit in that you can't "cheat" and use $_GET['myvar'] anywhere in your application, as $_GET is null before the dispatcher is called.
I'll try and update the tutorial with the feedback I've received by the end of the week.
Regards,
Rob…
Very nice tutorial Rob, thanks. I wonder if someone could help. After running v.1.0, I come out with the following error: Any ideas???
Thanks, Antonis.
Warning: Zend_View::include(./application/views) [function.include.html]: failed to open stream: Permission denied in G:Apache2htdocszf-tutoriallibraryZendView.php on line 46
Warning: Zend_View::include() [function.include.html]: Failed opening './application/views' for inclusion (include_path='.;./library/;./application/models') in G:Apache2htdocszf-tutoriallibraryZendView.php on line 46
Great tutorial, but I still dont understand how the models work. i.e. when I have a model for some newsposts how can I combine those posts with the right category (thats a different model I think).
Ow, and at page 11: $this->actionTemplate should be $view->actionTemplate.
The rest is Great!
Rob, would you be interested in including a section in your tutorial on how to get up and running on IIS? I've written something up based on the experience that I've had with ZF on IIS and I'd be happy to just hand it over to you to fit into the tutorial that you've written.
Duane,
I'm tempted to include IIS support, but without using ISAPI_Rewrite, I
found that I had to create a new router class to handle routing of GET
parameters.
My code is here:
If I get some time, I'll write up how I got IIS support working. Will be
interesting to compare with your solution.
I must say thank you for taking the time to provide one of the best practical tutorials.
I would appreciate very much if you can help to answer how to process multiple row entries on a single form i.e. the form you provided in you code has one row. If we havd one form that has 10 rows how will we process these entries to add it to the database? e.g.
James Morrison Undiscovered
Asfaw Maru Out of Africa
Joan Smith On The Road
Comments are now closed – please comment here.
Thanks!