Tutorial: Getting Started with the Zend Framework 1.0
This tutorial is intended to give a very basic introduction to using the Zend Framework to write a simple database driven application.
NOTE: This tutorial has been tested on version 1.0.0 of the Zend Framework. It stands a very good chance of working with later versions. It is unlikely to on any version prior to version 1.0.0 due to dependency on the ViewRenderer action helper.
English version: Dowload the PDF (v1.4.5).
Simplified Chinese version by Jason Qi (offsite): Visit Jason's download area.
French version by Guillaume Rossolini (offsite): Débuter avec le Zend Framework.
Polish version by Kubek Bartosz (offsite): Pierwsze kroki z Zend Framework.
Russian version by Alex Musayev (offsite): Russian Translation (PDF)
Czech version by Petr Parimucha (offsite): CzechTranslation
Brazillian Portuguese version by Ricardo Klein (offsite): Getting Started with Zend Auth_pt-BR
Latvian version by Ingus (offsite): Ievads Zend Framework
Slovakian version by Igor Hlina (offsite): Začíname so Zend Frameworkom - tutoriál
Translations for previous versions of this tutorial:
Brazillian Portuguese version by Adler Medrado: Iniciando com Zend Framework (1.3.0).
German translation by Daniel Messer: Einstieg in das Zend Framework: PDF (v1.3.0).
Danish translation by Stig Benning: I gang med Zend Framework: PDF (v1.3.4).
Spanish translation by Claudio Cossio (offsite): Desarrollo de Aplicaciones con Zend Framework: PDF (v1.3.3).
Indonesian version by Riki Risnandar: Tutorial Awal dengan Zend Framework PDF (v.1.2.3)
Italian version by Fabrizio Frosali: Primi passi con il Framework Zend (off site).
Code
The associated code is available:
- My Subversion repository
- Zip file of tutorial (~9KB)
- Zip file of tutorial including ZF1.0.1 (~2.3MB)
Changelog
- 1.4.5
- Made the dependencies on mod_rewrite and .htaccess files more obvious.
- 1.4.4
- Use createRow() to create an "empty" album as noticed by Terry Stalker. Also, fixed reference to $_SERVER[’REQUEST_METHOD’] as reported by balu!
- 1.4.3
- Further updates so that the flow makes sense!
- 1.4.2
- Updates to support version 1.0.0. of the Zend Framework
- 1.4.1
- Updates to support version 1.0.0. RC2of the Zend Framework
- 1.4.0
- Updates to support version 1.0.0. RC1 of the Zend Framework.
- 1.3.4
- Improvements to the English found by Guillaume Rossolini.
- 1.3.3
- Another typo! Found by Wayne Roesner.
- 1.3.2
- More typos fixed. Found initially by Ludo, then many others ;)
- 1.3.1
- Now using isPost() as suggested by sleek. Also filed typos found by Jason Qi.
- 1.3.0
- Significant reworking to support version 0.9 of the Zend Framework.
- 1.2.4
- Typographical fixes found by Darren Chandler. This version has been tested on 0.8 of the Zend Framework.
- 1.2.3
- Updated notes on which versions of the Zend Framework are supported, now that I've tested on 0.7.
- 1.2.2
- Fixed more typographical and contextual issues found by Jason Qi.
- 1.2.1
- First typo found by Jason Qi.
- 1.2.0
- Updated tutorial for version 0.6 of the Zend Framework.
- 1.1.1
- Fixed setting of the include path.
Fixed multiple typos found by Brendon Kozlowski. - 1.1.1
- Fixed initiation of the Front Controller in index.php.
- 1.1.0
- Updated tutorial for version 0.2 of the Zend Framework.
- 1.0.5
- Added some troubleshooting information about using setRewriteBase().
- 1.0.4
- Maybe I've finally nailed down the path to IndexController.php!
- 1.0.3
- More minor fixes. Thanks Thanks Holger and Develucas! Added note about only working with 0.1.5.
- 1.0.2
- Typo fix. Thanks Chris!
- 1.0.1
- Multiple minor fixes. Thanks Nathan, Nick, Matthew and everyone else!
- 1.0
- Original version
August 18th, 2006 at 13:13 #
Thanks for this great tutorial!
greets from germany
ed
August 18th, 2006 at 14:32 #
Great tutorial!
I've been looking for this, and it has helped me tremendously!
August 18th, 2006 at 21:22 #
Great work, thanks :D
August 19th, 2006 at 05:08 #
thank you for the tutorial :)
August 19th, 2006 at 12:14 #
great tutorial, now i want to use zend framework but my hosting have php 4.* :P
thank you for the tutorial :)
August 21st, 2006 at 11:26 #
zip file 1.0.1 does not exist :(
August 21st, 2006 at 21:07 #
Great tutorial, but I still don't 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 (that's a different model I think).
Ow, and at page 11: "$this->actionTemplate" should be "$view->actionTemplate".
The rest is Great!
August 22nd, 2006 at 05:55 #
Linked download is the old PDF (v1.0)
Download the new PDF (v.1.0.1):
http://www.akrabat.com/wp-content/uploads/getting-started-with-the-zend-framework_101.pdf
August 22nd, 2006 at 10:55 #
zip file 1.0.1 does not exist :(
August 22nd, 2006 at 18:51 #
Sorry, but I'm also having trouble with not finding the ZIP… Otherwise, great tutorial!
August 23rd, 2006 at 20:51 #
Sorry, been away for a few days on holiday (without a computer!)
I've fixed the links. The changes I made were to the PDF, not the zip file, but I updated the post incorrectly.
You should now be able to dowload a version 1.0.1 of the PDF.
August 24th, 2006 at 12:24 #
i have problems in 6th page. When i try to test IndexController with a url like http://localhost/zf_tutorial/index/add i'm notice with:
Fatal error: Uncaught exception Zend_Controller_Action_Exception with message 'IndexController::norouteAction() does not exist and was not trapped in __call().' in c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Action.php:92 Stack trace: #0 c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Action.php(92): Zend_Controller_Action::__call() #1 c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Action.php(114): IndexController->__call('norouteAction', Array) #2 c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Dispatcher.php(185): IndexController->run(Object(Zend_Controller_Dispatcher), Object(Zend_Controller_Dispatcher_Token)) #3 c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Dispatcher.php(136): Zend_Controller_Dispatcher->_dispatch(Object(Zend_Controller_Dispatcher_Token), true) #4 c:\arquivos de programas\apache group\Apache\htd in c:\arquivos de programas\apache group\Apache\htdocs\zf_tutorial\library\Zend\Controller\Action.php on line 92
August 24th, 2006 at 20:02 #
Carlo,
Do you have a function called addAction() in your IndexController class?
August 28th, 2006 at 04:46 #
Thank you for your excellent tutorial.I'd like to transelate it into Chinese,Can you grant me this privilege?
August 28th, 2006 at 10:28 #
etng,
Please feel free to translate to Chinese, as long as you credit me as the original author.
September 6th, 2006 at 06:12 #
I'm going through your tutorial right now, and so far it's awesome. One note though - I've had trouble with the initial mod_rewrite rules for when this app exists in a subdirectory. When I changed the rules to this for the zf-tutorial/.htaccess file it worked:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ /~danServe/zf-tutorial/index.php
Is there a better way to do this?
fyi: I'm running this via Apache 1.3 on Tiger, using PHP 5.1.x
Thanks!
September 6th, 2006 at 20:08 #
Hi Dan,
From what I can tell, the automatic working out of the base URL by the RewriteRouter doesn't work in certain cases.
There's no real current solution yet, so fixing the rewrite rules seems as good a way as any to me.
September 9th, 2006 at 16:07 #
Great work! Really got me into working with the Zend-Framework. Thanks!
One note though: In the 'IndexController' in your 'addAction' you are not setting the id-property of the album, resulting in a "Property not found…"-error in the HTML-page as the value for the hidden Id-field. This is not a problem in the code, since the id-field is not considered when adding an album, but if someone looks at the HTML-code, it's ugly.
(Running the code on a PHP-5.1.4 with Hardening-Patch.)
September 10th, 2006 at 20:15 #
Thanks for that Holger!
September 11th, 2006 at 16:41 #
hai Rob i'm from holland i vound your tutorial super.I want to ask je of you can make a tutorial with INNER JOIN. Thanks
September 11th, 2006 at 18:43 #
Hi Noury,
Who knows what the future will bring :)
Regards,
Rob…
September 12th, 2006 at 18:00 #
great job!
September 15th, 2006 at 21:46 #
Hai rob Can i do this:
$view->homepage = $homepage->fetchAll("SELECT * FROM homepage");
—————————–
function indexAction()
{
$view = Zend::registry('view');
$homepage = new Homepage();
$view->homepage = $homepage->fetchAll();
$view->homepageactionTemplate = 'homepageIndex.tpl.php';
$rubrieken = new Rubrieken();
$view->rubrieken = $rubrieken->fetchAll();
$view->rubriekenactionTemplate = 'rubriekenIndex.tpl.php';
echo $view->render('site.tpl.php');
}
September 16th, 2006 at 07:28 #
Noury,
I don't see why not. Obviously, you have to render() both homepageactionTemplate and rubriekenactionTempate from within site.tpl.php.
September 17th, 2006 at 18:51 #
HOlla ROB How are you?
Do you have any idee how i use join() in your tutorial.
Thanks
September 17th, 2006 at 21:40 #
On page 4, you say: "Note that we do not put in the ?> at the end of the file as it is not needed and leaving it out ca prevent some hard-to-debug errors."
This is the first time I have heard of this. Where can I find more info on this concept?
September 18th, 2006 at 09:19 #
Hi Jared,
http://framework.zend.com/manual/en/coding-standard.php-file-formatting.html mentions it at the top.
Regards,
Rob…
September 18th, 2006 at 09:20 #
Noury,
What you do you mean?
Regards,
Rob…
September 20th, 2006 at 08:36 #
I have problem with tutorial.
its probably in this line: render($this->actionTemplate); ?>
message is:
Warning: Zend_View::include(./application/views\) [function.Zend-View-include]: failed to open stream: Permission denied in D:\new_wamp\www\zf_tutorial\library\Zend\View.php on line 46
Warning: Zend_View::include() [function.include]: Failed opening './application/views\' for inclusion (include_path='.;./library/;./application/models') in D:\new_wamp\www\zf_tutorial\library\Zend\View.php on line 46
September 20th, 2006 at 08:38 #
render($this->actionTemplate); ?>
its on page 9. Probably script cut part of line so i put spaces now.
September 20th, 2006 at 15:33 #
Hmm… that's odd as it implies that the actionTemplate variable is empty.
September 27th, 2006 at 15:48 #
Good looking tutorial although I cannot get anything other than IndexController working.
I need multiple possibilities for the controller, as mentioned in the tutorial, but not added.
Example:
/ - uses index controller IndexController.php indexAction method
/index/add should use IndexController.php addAction method
/dummy - should use DummyController.php indexAction method
/dummy/new should use DummyController.php newAction method
How would you set this up using the router if necessary ?
September 28th, 2006 at 16:37 #
Hallo rob,
Would you like to tell me hoe i can use join().
I don't know where i put join() and how.
I have a news table and a user table. Every news a written by a user:
class news extends Zend_Db_Table{}.
class user extends Zend_Db_Table{}.
thank you very much
Nour
October 12th, 2006 at 13:07 #
Hi,
I have this error using the tutorial:
Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in C:\wamp\www\zf-tutorial\library\Zend\Db\Adapter\Pdo\Abstract.php:80 … I didn't put the stack trace
I'm in page 14 (version 104)
October 12th, 2006 at 13:18 #
kico,
You need to enable PHP's MySQL extension in the php.ini file.
Regards,
Rob…
October 12th, 2006 at 14:06 #
Rob:
I already did, I'm using WAMP5, that was the first thing i thought too, but still nothing
Regards
October 12th, 2006 at 14:06 #
I'm using ZendStudio 5.1 too
October 12th, 2006 at 14:23 #
kiko,
Have you also enabled the PDO MySQL extension?
Rob…
October 12th, 2006 at 14:28 #
I did that too…
Regards
October 12th, 2006 at 14:51 #
Rob:
I could connect to mysql using prado framework, so the driver works
but still have the same error using Zend
regards
October 12th, 2006 at 17:00 #
problem solved
i just had to restart windows, i don't know what was it, but its fixed
thank you
October 13th, 2006 at 07:24 #
Kico,
That's very odd. Glad it's solved though!
Rob…
October 15th, 2006 at 02:43 #
Thx for the tutorial, helps a lot because it gives you the basics of understanding how this framework works, not very in-depth… initially i had v.10 (which had the bug of $this instead of $view, and only after i've figured out myself i got to see v101). Still, sometimes I have doubts about real applications needsing the whole structure, because it could be a terrible overload on a machine to have, let's say, 300 sites (simple, small ones) running with zend framework. Some preliminary tests showed me a good degree of slowing down everything, and a pretty high increasing of memory consumption. It is obviously, extremely good for organizing everything very well, and all maintenance/upgrades. And very good to know all the things in order to have a better overview of large apps, but probably most of the people will not even take the time to look for a tutorial, and, in case they don't find one like yours, they'll give up zend framework, and continue using some older ones, tested and known.
Regards,
Dragos
October 15th, 2006 at 12:04 #
Well, another error I've found right now on page 13, under "Listing Albums". It says: zf-tutorial/application/views/IndexController.php with the lines function __construct()…. Well, it happens that this is not the controller we're looking for, but instead, that controller resides in /application/controllers/IndexController.php
Same thing couple of lines below, again, where we add the code for instantiating and fetching the albums list… Please correct the tutorial, man, as it will never bring people to something usable (but I still appreciate a lot your effort, so let's make it work as well as it could).
Regards
Dragos
October 15th, 2006 at 12:10 #
oops, sorry, I've only now found the v1.0.4 :) .. it was too visible to see it, my apologies please
October 15th, 2006 at 18:48 #
Hi Dragos,
Thanks for the comments. As you can see, I've tried to sort out the typos and I'm vaguely hopeful that 1.0.4 is typo free. Of course, if you find anything, please let me know and I'll fix it!
Regards,
Rob…
October 17th, 2006 at 13:47 #
same problem as Comments#29 (but on linux), variable was empty
I changed
$this->actionTemplate = 'indexIndex.tpl.php';
into
$view->actionTemplate = 'indexIndex.tpl.php';
and it works fine…
October 17th, 2006 at 17:50 #
Hi there,
I want to add my thanks for a great tutorial. I do have a problem however. Exactly the same error as described in comment 12. I do have the IndexController.php file setup as in the tutorial and have a function called AddAction in the Controller class.
I can access zf_tutorial/ which echos 'in IndexController::indexAction()' but zf_tutorial/index/add or zf_tutorial/index/edit result in the error:
Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::norouteAction()…etc
I'm running php PHP 5.1.6 and Apache 1.3 on Mac OSX 10.4.7 with Zend Framework 0.1.5
I've double checked everything and can't figure it out. Would appreciate any suggestions.
Thanks
October 17th, 2006 at 21:59 #
Problem solved. It was to do with having my application in a subfolder although I tried all of the fixes suggested above and nothing seemed to work. In the end I added this to the bootstrap file:
$route->setRewriteBase('/~my_osx_username/zf_tutorial');
Working fine now
October 18th, 2006 at 07:17 #
Hi Dave,
From what I've learnt so far, I think that setRewriteBase() is the most reliable way to get rewrite routing working. I'll update the tutorial soonish to reflect this.
Regards,
Rob…
October 18th, 2006 at 07:23 #
Tom,
Which page of the tutorial, in which version?
Regards,
Rob…
October 19th, 2006 at 09:21 #
Hi Rob!!
I have the same problem as Dave described.
Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in C:\wamp\www\zf_tutt\library\Zend\Db\Adapter\Pdo\Abstract.php:8..etc
where should I make the changes ??
Thnx for a great tut.
October 19th, 2006 at 09:33 #
Hasan,
You need to ensure that the mysql driver and the PDO mysql driver are enabled in your php.ini.
Regards,
Rob…
October 23rd, 2006 at 15:56 #
Done!! I use WAMP, I made the changes in wamp/PHP/php.ini and it didn't work. But when I made the changes in C:\wamp\Apache2\bin\php.ini i start to work .
Thnx again ..
Hasan..
October 23rd, 2006 at 16:06 #
Multiple php.ini files in a system can cause a world of pain. Glad you got it sorted!
Regards,
Rob…
October 31st, 2006 at 14:34 #
Posting this in case anyone else has similar difficulties…
Apache/2.0.59 (Unix) Server
PHP Version 5.1.6
MySQL API 5.0.22
I am stuck at page 6 in the tutorial (zf-tutorial/application/controllers/IndexController.php).
I am having the same fatal error as some other folks (see mssg 12 & 48), but their solutions in my environment haven't removed the error.
FYI, I just reviewed my directory structure and code against your Subversion repository. No difference for the pertinent components/code that I see (but am sure there is something).
In index.php.addRoute(), I can change the default action to get each function to display its message as the default or Index action (wierd).
That is,
if:
$route->addRoute('edit', ':controller/:action/id/:id',array('controller' => 'index','action' => 'index'));
then:
1. requesting wwwroot(aka html)/zf-tutorial displays "in IndexController::indexAction()"
2. requesting wwwroot(aka html)/zf-tutorial/index displays "in IndexController::indexAction()"
3. requesting wwwroot(aka html)/zf-tutorial/add encounters norouteAction() - fatal error
if:
$route->addRoute('edit', ':controller/:action/id/:id',array('controller' => 'index','action' => 'add'));
then:
1. requesting wwwroot(aka html)/zf-tutorial displays "in IndexController::addAction()"
2. requesting wwwroot(aka html)/zf-tutorial/index displays "in IndexController::addAction()"
3. requesting wwwroot(aka html)/zf-tutorial/add encounters norouteAction() - fatal error
So this seems like one of those scope problems that always give me headaches. :-)
Anyway still reading the manual and going in circles.
October 31st, 2006 at 21:54 #
John
Have you tried setting the rewrite base?
$router->setRewriteBase('/zf-tutorial');Regards,
Rob…
November 1st, 2006 at 13:13 #
Thanks for the response.
I wasn't clear in my post yesterday and I did not give you a full picture. Sorry.
My guess is the problem is likely environmental since none of the coding solutions here, Craig Shiflett's site or the Manual seem to get me a proper result.
To answer your question, 'Yes'. When I try to setRewriteBase, this message results"
mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.
The operations seems to want more than 10 redirects?
MaxRedirects is 10 which is the most this server allows apparently. Guess I can submit a support ticket to find out more.
Thanks.
November 6th, 2006 at 17:50 #
Are the .htaccess files with 'deny from all' even necessary? Wouldn't the 'RewriteRule .* index.php' catch any access to the application and libraries directories and interpret the request through the index.php file, or am I missing something?
November 6th, 2006 at 19:16 #
Justin,
You are almost certainly right as there aren't anre RewriteCond's to allow through files that exist on the hard drive.
Regards,
Rob…
November 7th, 2006 at 08:45 #
I still use "deny from all" too ;). Totally unnecessary but it just feels safer, and it does no harm either.
November 7th, 2006 at 15:37 #
same error like #12 comment
error on requested page http://localhost/zf_tutorial/index/add
solved thus:
just replace
$router->setRewriteBase($baseUrl);
with subfolder tutorial
like this one
$router->setRewriteBase('/zf_tutorial');
"""
Apache/1.3.33 (Win32) PHP/5.1.6
November 7th, 2006 at 18:59 #
he Rob, you promised us to write a login script with zf.
November 7th, 2006 at 19:42 #
Noury,
I haven't forgotten!
Regards,
Rob…
November 8th, 2006 at 21:42 #
Hey Rob, Great tutorial.
I'm having an issue however:
Fatal error: Uncaught exception 'Zend_Exception' with message 'File "Album.php" was not found.' in /var/www/zend.onlinedyno.com/library/Zend.php:190
I first thought maybe I had set things up incorrectly as I went through your tutorial but then I downloaded your code and reset config.ini to my values and I get the same error.
Any thoughts?
Thanks,
Matt
November 8th, 2006 at 22:27 #
Quick followup. I was able to get past my error by adding the following to my .htaccess
php_value include_path .:/var/www/zend.onlinedyno.com/zf-tutorial/application/models/
Doesn't seem like the best solution so let me know if I'm missing something obvious.
November 8th, 2006 at 22:42 #
Hey Rob, I swear I'm not trying to spam your blog but here's a solution I found that works for $baseUrl. I think it should work as long as your application is in the root of a site.
$baseUrl = substr($_SERVER['DOCUMENT_ROOT'],strrpos($_SERVER['DOCUMENT_ROOT'],'/'));
November 9th, 2006 at 06:21 #
Hi Matt!
In your index.php you should have included application/models into the include-path with a statement like:
I'm wondering if the set up you are using means that when running index.php, the current working directory is not the same directory as the one that index.php is in.
To check, change this bit to:
and see if that works.
It still seems that getting the right baseURL is very much system dependant :(
Regards,
Rob…
November 9th, 2006 at 18:04 #
Hey Rob,
I'm a bit perplexed. After working with it a bit and removing my php_value from .htaccess here's what I ended up with:
set_include_path(get_include_path().PATH_SEPARATOR.'./library/'.PATH_SEPARATOR. './application/models');
And then if I echo get_include_path() afterwards I get:
.:/usr/share/php:./library/:./application/models
The original set include gave me a get_include_path() of:
.:./library/:./application/models.:/usr/share/php
I don't see the difference other than the order but it absolutely won't work with the original path and it works flawlessly with my modified one. Ah wait… There's an extra . after models in the original. That's what is breaking it. We need another PATH_SEPARATOR in there so it becomes:
set_include_path('.' . PATH_SEPARATOR . './library/'
. PATH_SEPARATOR . './application/models'. PATH_SEPARATOR
. get_include_path());
Other than that, your tutorial has really sparked my interest in the framework. I wish it was a bit more mature but they're off to a great start with it!
November 13th, 2006 at 10:36 #
If anyone else is getting the following error:
Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::norouteAction() does not exist and was not trapped in __call().'
Have a look at this revision. Seems to work well for me. The problem seems to occur only when using _redirect() to redirect the user back to the indexAction(). Instead of redirecting, why not just executing it?
Here's the revised code:
http://pastebin.com/823169 (Note the highlighted portion.)
November 13th, 2006 at 19:51 #
Hey Dave,
I just defined a noRouteAction that gives a 404 error.
November 14th, 2006 at 04:52 #
Matt,
What happens then when you just point to your root directory without passing an entire :controller/:action string?
For example, try http://www.yourdomain.com instead of http://www.yourdomain.com/index/index. The noRouteAction() method should be called, I'd guess. If that is the case, that would render your application unusable for anyone that doesn't know an exact path to your main index. That's precisely what happens when I try the same - unless I have done something wrong here, and I think my code is pretty sound.
Additionally, I am not very fond of error pages. I chose to redirect to the main index in case of a 404.
If you are interested, you can take a look at my slightly more complicated example (which uses the Smarty template engine instead of Zend_View) here: http://harbinger.pastebin.com/823168
Keep in mind that this script is work in progress and don't be too harsh in juding. :)
November 14th, 2006 at 06:19 #
I think the problem is that there's a bug in the tutorial, right at the bottom of index.php:
should be:
Otherwise, the normal router is used rather than the the rewrite one.
I've updated the PDF and the zip file.
Regards,
Rob…
November 14th, 2006 at 08:23 #
Thanks, Rob. Looks like we all missed this one. It's so hard keeping it straight, though, when the design of the application changes like this and the developers are slow to update documentation. Still… Zend Framework is living up to the hype.
November 16th, 2006 at 10:59 #
Hi!!
Does anything of this tutorial changes with the new zf 0.2 release??
reguards
November 16th, 2006 at 17:01 #
Yes Hasan,
That's why I released a new version :)
Regards,
Rob…
November 20th, 2006 at 22:37 #
This is not the venue, but my asking stems from the goodness of this tutorial.
First though…
Thanks for this tutorial; it has been such a great help (education, motivation, etc.)!
It works so well in my Unix test environment that I took the plunge and set up a local WAMP environment.
Voila! The same code would not work under Windows. I'd get an Undefined Property error on the $config object.
Here is the offending code that works pefectly in UNIX, but not in Windows:
db->adapter, $config->db->config->asArray());
Zend_Db_Table::setDefaultAdapter($db);
?>
In a ZF manual code sample, I found that Config.php and Config/Ini.php are required
(http://framework.zend.com/manual/en/zend.config.html#zend.config.introduction).
Applying this change to my WAMP environment fixed the problem… why?
(please don't say, "Windows is like that!" heeh =) )
I bet I still have some configuration issue in the local WAMP environment. Still looking.
Anyway, here is the segment that works in WAMP.
db->adapter, $config->db->config->asArray());
Zend_Db_Table::setDefaultAdapter($db);
?>
Thanks
November 20th, 2006 at 22:39 #
Oops, that code sample did not post very well.
November 21st, 2006 at 06:18 #
John,
I wrote the tutorial using my Windows box running Apache 2, so it's not a generic Windows problem. There's no reason why you would have to require Config.php as Config/Ini.php will include it for you.
Out of interest, are you running APC or something similar on Windows?
Regards,
Rob…
November 22nd, 2006 at 06:19 #
When I click on 'Add new album'
I got this
http://localhost/zf_tutorial/index/add
Not Found
The requested URL /zf_tutorial/index/add was not found on this server.
Apache/2.0.59 (Win32) PHP/5.1.6 Server at localhost Port 80
Thanks.
November 22nd, 2006 at 06:27 #
Jason,
If I was to guess, I'd say that there's a mod_rewrite problem.
Regards,
Rob…
November 22nd, 2006 at 10:22 #
OH THANK YOU THANK YOU THANK YOU! it had just what i needed to know about! :)
- now i only need one thing. How to work with the rewrite router controller from the config file.
November 22nd, 2006 at 12:46 #
Hi,
Thanks for the tutorial.
Does $this->_action->getParams() inherently use Zend_Filter_Input ?
Obviously using the bootstraping principal, my URL will look something like:
example.com/Foo/Bar/id/45
Which will give me id=>45 from getParams().
However, this input still needs to be filtered, new Zend_Filter_Input($_GET) won't give me id=>45 unless I build my URL as:
example.com/Foo/Bar?id=45.
Your thoughts would be appreciated.
Thanks
Andrew
November 22nd, 2006 at 13:33 #
Andrew,
As far as I know, getParams() doesn't use Zend_Filter_Input, so you should put it through one of the Zend_Filter methods first.
Regards,
Rob…
November 22nd, 2006 at 15:43 #
Thanks that works great, I've got a little internal app coming up in the next month or so, I'm going to use the opportunity to flex the framework a little.
It all looks very positive, and, with Zend behind it, it's got legs.
Andrew
November 22nd, 2006 at 19:59 #
I agree with comment #69. I needed to add either of the following two things after .application/models :
1.) Add a '/' after ./application/models OR
2.) Add . PATH_SEPARATOR after './application/models'
Thank you for the tutorial!
November 23rd, 2006 at 06:10 #
Hi Rob,
How can I solve the mod_rewrite problem?
BTW, another questions is
When I type http://mysite/ I can see the right page.
When I type http://mysite/index.php, nothing showes up.
Thanks a lot.
Jason.
November 23rd, 2006 at 07:44 #
Hi Rob,
Sorry, I solved that problem by modifying my httpd.conf file to enable mod_rewrite and allow apache to access .htaccess.
But now, whenever I click "add new album", nothing showes up.
I only can see "http://mysite/zf-tutorial/index/add" in the address bar of the firefox.
Thanks.
Jason.
November 23rd, 2006 at 07:50 #
oh, I read someone else's comments and tried to replace $baseUrl by '/zf-tutorial' and everything works fine now!!!
Thanks for your great tutorial!!!
What I did in the index.php are:
//$router->setRewriteBase($baseUrl);
$router->setRewriteBase('/zf-tutorial');
But still, when I type "http://mysite/index.php" and get nothing.
Jason.
November 24th, 2006 at 06:45 #
I found http://mysite/index works.
So if index.php can be converted to index somewhere, it will be great.
November 24th, 2006 at 08:11 #
Jason,
Are there any error messages in your Apache error log ?
Regards,
Rob…
November 24th, 2006 at 10:05 #
Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Pdo/Abstract.php:80 Stack trace: #0 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Abstract.php(146): Zend_Db_Adapter_Pdo_Abstract->_connect() #1 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Abstract.php(309): Zend_Db_Adapter_Abstract->query('DESCRIBE album', NULL) #2 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Pdo/Mysql.php(86): Zend_Db_Adapter_Abstract->fetchAll('DESCRIBE album') #3 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Table.php(181): Zend_Db_Adapter_Pdo_Mysql->describeTable('album') #4 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Table.php(123): Zend_Db_Table->_setup() #5 /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/application/controllers/IndexController.php(15): Zend_Db_Table->__constru in /usr/local/apache-1.3.36/htdocs/somedomain.com/dev/library/Zend/Db/Adapter/Pdo/Abstract.php on line 80
I have PDO installed
PDO
PDO support enabled
PDO drivers sqlite2
PHP Extension 20050922
I am still not able to connect to database. Can u pls help me with this.
Thnx
Pooja
November 24th, 2006 at 14:51 #
Hi Poogja,
Have you installed the MySQL PDO driver?
i.e. extension=php_pdo_mysql.dll or extension=php_pdo_mysql.so (depending on system!)
Regards,
Rob…
November 24th, 2006 at 18:46 #
Rob,
There is no related error message in the apache error log file.
I have two WAMPs, one is winxp pro sp2+apache 2.0.59+php5.1.6
when I type index.php there is nothing shows up
another one is winxp home sp2+apache 1.3.37+php5.1.6
when I type index.php there is error message shows up as follow
Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::norouteAction() does not exist and was not trapped in __call().' in c:\zf-tutorial\library\Zend\Controller\Action.php:92 Stack trace: #0 c:\zf-tutorial\library\Zend\Controller\Action.php(114): Zend_Controller_Action->__call('norouteAction', Array) #1 c:\zf-tutorial\library\Zend\Controller\Dispatcher.php(185): Zend_Controller_Action->run(Object(Zend_Controller_Dispatcher), Object(Zend_Controller_Dispatcher_Token)) #2 c:\zf-tutorial\library\Zend\Controller\Dispatcher.php(136): Zend_Controller_Dispatcher->_dispatch(Object(Zend_Controller_Dispatcher_Token), true) #3 c:\zf-tutorial\library\Zend\Controller\Front.php(254): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Dispatcher_Token)) #4 c:\zf-tutorial\index.php(46): Zend_Controller_Front->dispatch() #5 {main} thrown in c:\zf-tutorial\library\Zend\Controller\Action.php on line 92
November 25th, 2006 at 08:06 #
Rob,
Sorry, the info in the last post is not clear.
Today, when I back home, I checked apache 2.0.59's error log, found error message like this (looks like same with apache1.3.37 which shows in the browser)
[Sat Nov 25 00:01:03 2006] [error] [client 192.168.1.100] PHP Fatal error: Uncaught exception 'Zend_Controller_Action_Exception' with message 'IndexController::norouteAction() does not exist and was not trapped in __call().' in C:\\zf-tutorial\\library\\Zend\\Controller\\Action.php:92\nStack trace:\n#0 C:\\zf-tutorial\\library\\Zend\\Controller\\Action.php(114): Zend_Controller_Action->__call('norouteAction', Array)\n#1 C:\\zf-tutorial\\library\\Zend\\Controller\\Dispatcher.php(185): Zend_Controller_Action->run(Object(Zend_Controller_Dispatcher), Object(Zend_Controller_Dispatcher_Token))\n#2 C:\\zf-tutorial\\library\\Zend\\Controller\\Dispatcher.php(136): Zend_Controller_Dispatcher->_dispatch(Object(Zend_Controller_Dispatcher_Token), true)\n#3 C:\\zf-tutorial\\library\\Zend\\Controller\\Front.php(254): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Dispatcher_Token))\n#4 C:\\zf-tutorial\\index.php(49): Zend_Controller_Front->dispatch()\n#5 {main}\n thrown in C:\\zf-tutorial\\library\\Zend\\Controller\\Action.php on line 92
November 25th, 2006 at 08:55 #
Jason,
Fancy zipping up your project and emailing it to me?
Regards,
Rob…
November 26th, 2006 at 04:31 #
Rob,
I sent it to you.
Thanks.
December 2nd, 2006 at 23:21 #
The Polish translation links, in fact, to the Italian version and vice versa.
December 3rd, 2006 at 08:39 #
Doh!
Thanks R.V! I've updated :)
Regards,
Rob…
December 8th, 2006 at 22:36 #
Rob,
This is the best tutorial I've seen for a long time! It is very clear and everything works first time. Coming from a Java and more recently Ruby on Rails background, I was very frustrated by PHP for the lack of a good MVC framework. The Zend framework has now changed this.
Thank you for a brilliant introduction to this technology!
Bruno
December 9th, 2006 at 08:38 #
Thanks for your kind words, Bruno!
Regards,
Rob…
December 11th, 2006 at 13:57 #
Yes, very nice tutorial!
To exercise the Zend MVC framework, I've
used the 'chat tutorial' code. They, in turn,
use a 'library incubator' sub-directory to
contain ZF code (so that each using app contains
a private copy of ZF).
My comment/question is that it would be neat
if ZF provided a method to make it easy for
the using-app to retrieve/display the VERSION of
ZF that is in use (and show a URL-link to where it comes from,etc), so that one coulld easily see
what version is being used.
Meanwhile, anyone know WHERE to look in the sub-tree to determine what version of ZF is
located there?
TIA…
Dave
December 13th, 2006 at 21:25 #
Dave,
To be hones, I haven't a clue if the current release version is in the tree.
Regards,
Rob…
December 17th, 2006 at 06:44 #
getting error:
Catchable fatal error: Argument 1 passed to Zend_Controller_Action::__construct() must be an instance of Zend_Controller_Request_Abstract, none given, called in /www/zf-tutorial/application/controllers/IndexController.php on line 6 and defined in /www/zf-tutorial/library/Zend/Controller/Action.php on line 92
when run index.php
December 17th, 2006 at 16:59 #
About previous 104. There is no errors in the code. I just by mistake used latest (on that date) frame version that has a few changes that don't work with the example.
This tutorial is a great work to introduce even experienced programmers to MVC framework. Keep going Rob!
December 20th, 2006 at 18:02 #
Hello Rob
i ahve been using ur tutorial as a base for my application
I m quiete xcited about this
I have a query .
i have a controler file called ProjectDetailsControlled.php
where in the indexAction function
i have the follwoing code
$config1 = new Zend_Config_Ini('../application/config.ini', 'general');
Zend::register('config1′, $config1);
// setup database
$newdb = Zend_Db::factory($config1->db->adapter, $config1->db->config->asArray());
$select=new Zend_Db_Select($db);
$select->from('projectproduct', 'projectproduct.projectproductid');
$select->from('product', 'product.title as tt');
$select->from('project','project.projectid');
$select->where('project.projectid = ?', $id);
$select->where('projectproduct.projectid = project.projectid');
$select->where('projectproduct.productid = product.productid');
//$result = $db->fetchRow($select);
$result = $db->fetchAll($select);
$view->result = $result;
$view->actionTemplate = 'projectDetails.tpl.php';
echo $view->render('site.tpl.php');
Now in the projectDetails.tpl.php
i have this code
result as $rst) {
echo $this->escape($rst['tt']);
}?>
The above query should return 3 records
but i m not able to get the code working properly
Can u pls tell how i can use the data from the above query in my projectDetails.tpl.php file
Thnx
Pooja
December 20th, 2006 at 18:07 #
looks like i sorted it out
It was some syntac errrr
Thnx
December 20th, 2006 at 19:25 #
Pooja,
I'm glad you sorted it!
Regards,
Rob…
December 21st, 2006 at 16:57 #
hey Rob,
first i wanna thank you for this great tutorial, im totaly new to zend framework and your tutorial was a great help :)
im using version 0.6.0 of zend framework, i had to make some changes to make it work.. still i have some problems:
- the edit action wont work, i have a notice "Undefined property: IndexController::$_action…" and an error "Call to a member function getParams() on a non-object in…"
- another problem is that only firefox can show the page, in IE i get a blank page.
Thx
December 21st, 2006 at 19:05 #
Hi Abdou,
I've started working on a version of the tutorial for v0.6. You can see where I've got to by checking out the svn version at http://svn.akrabat.com/svn/zf-tutorial/trunk/
Regards,
Rob…
December 22nd, 2006 at 10:25 #
Hi Rob,
The code is still not working, i took the editAction() from your svn version the error i get is the same :
"Fatal error: Call to a member function getParam() on a non-object in…"
plus, IE doesnt show anything.
I guess i have to use earlier version of the framework, but if i had to, what are consequences ? does it have some bugs or security holes ?
December 22nd, 2006 at 12:10 #
Hi Abdou,
Have you updated your index.php as per the svn version?
Which line is the "Call to a member function getParam() on a non-object" error happening on?
Regards,
Rob…
December 22nd, 2006 at 12:53 #
Hi Rob,
i just updated my index.php, the difference with yours is the router, i was using one (i wonder why you're not using it :) ), the error is still the same, and its happening on this line:
"87 $id = (int)$this->_request->getParam('id', 0);"
I commented the same line, and put a value for $id, ten i had the same error, but this time its about this line:
"98 $this->_response->setBody($view->render('site.tpl.php'));"
Error -> "Call to a member function setBody() on a non-object"
Thx for help.
December 22nd, 2006 at 19:54 #
Hi Abdou,
Did you change __construct() in your index controller to init() as in the svn file ?
Regards,
Rob…
December 22nd, 2006 at 20:46 #
Hi Rob,
The problem is solved now :) i had to change the _construct() of course.
Thank you a lot…
December 22nd, 2006 at 20:58 #
Great news Abdou!
Regards,
Rob…
January 5th, 2007 at 10:19 #
I have a problem:
When I do http://localhost/zf/index/add everything is ok. But if I do http://localhost/zf/foo/add is not working (and I have the FooController.php file with the add method). It gives me the 404 error. Even if I define noRouteAction in the IndexController, it gives the same error.
I have the site in sub-directory zf, and I have the setBaseUrl('/zf') in the controller.
v0.6
Can you help me?
Ricardo
January 5th, 2007 at 13:15 #
Great tutorial.. thanks :) it should be included in Zend Framework documents…
this tutorial is clear and explain every detail in every line..
January 5th, 2007 at 13:26 #
Ricardo, do you define the FooController in FooController.php like this one ?
class FooController extends Zend_Controller_Action
January 8th, 2007 at 19:58 #
Should one use appendBody() vs setBody() since there could have been other headers, exceptions, etc. written from other parts of the application before hitting this controller?
January 8th, 2007 at 20:34 #
Will,
I suspect that it depends on your application as to whether any given controller action is "in charge" of the response enough to use setBody() in preference to appendBody(). Generally, that will depend on if you use plugins or _forward(). (At a guess, anyway!)
Regards,
Rob…
January 11th, 2007 at 03:27 #
please help me in this tutorial. im getting error 404 http://localhost/zf-tutorial1/index/add/ but when im in this page http://localhost/zf-tutorial1/ in work. what do you think i must do? thanks in advance..
January 11th, 2007 at 08:14 #
Hi Anthony,
Is your Apache set up correctly to read the .htaccess file? At a guess you haven't got the correct AllowOverride setting in your httpd.conf file.
Regards,
Rob…
January 11th, 2007 at 08:27 #
Fatal error: Class 'Album' not found in C:\Program Files\xampp\htdocs\zf-tutorial\application\controllers\IndexController.php on line 13
what would be the solution for this,please help. thanks
January 11th, 2007 at 08:32 #
Thony,
At a guess, you haven't set the path to your models/ directory correctly in index.php.
Regards,
Rob…
January 13th, 2007 at 14:09 #
I just updated to 0.6 from 0.2 and had a bunch of errors I needed to fix. Mostly changing stuff in the view from if($view->error) to if(isset($view->error)) and so on, but I also needed to change how the router was setup so I came back to your site for the new tutorial and copied the new lines. These lines are:
$baseUrl = substr($_SERVER['PHP_SELF'], 0, strpos($_SERVER['PHP_SELF'], '/index.php'));
$frontController = Zend_Controller_Front::getInstance();
$frontController->setBaseUrl($baseUrl);
$frontController->setControllerDirectory('../app/controllers');
$frontController->throwExceptions(true);
Now though, I can't get any actions in IndexController to work. For example, site.com/test will not go to the action "test" in IndexController, but instead it will error and say that it can't find TestController.php. All I want to do is use noRouteAction in IndexController for a 404 page.
January 13th, 2007 at 14:11 #
It would seem that I'm having the same problem as Ricardo and anthony.
January 13th, 2007 at 14:17 #
Here's some more info.
site.com/index goes to the IndexAction in IndexController
site.com/index/test goes to the TestAction in IndexController
site.com/index/foobar goes to the noRouteAction in IndexController
site.com/ goes to the IndexAction in IndexController
site.com/test says it can't find TestController.php
site.com/foobar says it can't find FoobarController.php
January 13th, 2007 at 14:56 #
Hi Kyle,
The Dispatcher has changed in 0.6 and you need to write a front controller plugin to handle this situation.
Regards,
Rob…
January 13th, 2007 at 15:15 #
It seems more like a bug to me than a feature I need to add back in myself.
January 13th, 2007 at 15:50 #
While I'm sure Rob has seen it, there's an explanation of why it's this way now here: http://www.nabble.com/forum/ViewPost.jtp?post=7662411&framed=y&skin=16154
Catching the exception and redirecting was what I had started to do anyway, and if it's good enough for Matt it's good enough for me.
January 13th, 2007 at 15:53 #
Hi Kyle,
I subscribe to the mailing list and was going to dig through my archives later to see what I could find. Thanks for finding it for me :)
Regards,
Rob…
January 13th, 2007 at 16:40 #
I went with Matt's method to check if the route isDispatchable() which also stops it from erroring if the user tries to execute an action that is a private function. So better all round I think.
January 13th, 2007 at 19:02 #
A couple questions:
1) Since there's now init() to automatically execute stuff when a controller is started, is there a similar thing to automatically execute stuff afterwards?
2) Is there a reason why I shouldn't be using __autoload or is it just not in your tutorial to keep it simple or PHP4 compliant?
3) When you use the predefined methods to get data from a database, such as findAll(), fetchCol(), etc you get the data back like $table->field, but if you build your own methods with select() you get it back in an array like $table['field']. It's kind of irritating that I get my data in two different formats so is there a way to make these match? I assume it's something to do with Zend_Db_Table_Rowset.
4) Would you consider doing some mini tutorials about using some basic stuff like cookies, sessions, etc? It took me 20 mins reading the manual to get all the information I needed to use cookies and I still don't know if I'm doing it properly. I could do them the old fashioned way but then I wouldn't be learning anything.
January 13th, 2007 at 19:09 #
Hi,
1) postDispatch() or __destruct(). Note that there is a preDispatch() too.
2) nope - feel free to use __autoload if you want to :)
3) I agree. Yeah it is to do with Zend_Db_Table_Rowset and is a right pain!
4) Yeah, mini tutorials will come along when I get some spare time. I'm completely swamped at the moment though :(
Regards,
Rob…
January 13th, 2007 at 21:11 #
So there's no solution to #3? The manual says that you will rarely need to call Zend_Db_Table_Rowset manually. So if it can be called manually then what can we do with it? Can it be used change the data before a model outputs it?
Thanks for your tutorial though. I've been using it to get every version since 0.1.4 or earlier going. Sure it doesn't go into any depth but it gets you going and then you can google around for more complicated things.
January 14th, 2007 at 17:42 #
Hi Kyle,
At the moment, I iterate over the array and turn it into an array of stdClasses with the altered field names as would be used by Zend_Db_Table_Rowset. This is clearly not the right way to do it though!
Regards,
Rob…
January 15th, 2007 at 03:12 #
I am on a shard hosting env. I have the pdo_mysql problem:
Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The mysql driver is not currently installed' in /home/username/lib/Zend/Db/Adapter/Pdo/Abstract.php:88
I have the following in my php.ini:
extension=pdo.so
extension=mysql.so
extension=pdo_mysql.so
magic_quotes_gpc = Off
register_globals = off
January 15th, 2007 at 03:13 #
Oh, I forgot, here is the phpinfo() output:
'./configure' '–with-xml' '–enable-bcmath' '–enable-calendar' '–with-curl' '–with-dom' '–with-dom-xslt' '–with-dom-exslt' '–enable-exif' '–enable-ftp' '–with-gd' '–with-jpeg-dir=/usr/local' '–with-png-dir=/usr' '–with-xpm-dir=/usr/X11R6′ '–with-gettext' '–with-imap=/usr/local/imap-2004g' '–enable-mbstring' '–enable-mbstr-enc-trans' '–enable-mbregex' '–with-mcrypt' '–enable-memory-limit' '–with-mhash' '–enable-magic-quotes' '–with-mysqli' '–with-mysql=/usr' '–with-openssl' '–enable-discard-path' '–with-pear' '–enable-xslt' '–with-xslt-sablot' '–enable-sockets' '–enable-track-vars' '–with-ttf' '–with-freetype-dir=/usr' '–enable-gd-native-ttf' '–enable-versioning' '–enable-wddx' '–with-xmlrpc' '–with-zlib' '–prefix=/usr/local/php5′ '–exec-prefix=/usr/local/php5′ '–program-suffix=5′ '–enable-force-cgi-redirect' '–enable-discard-path'
January 15th, 2007 at 09:38 #
Hi Mike,
The problem is that your host has not enabled the PDO extension. You could try using the Zend_Db adapater for mysqli which is in the incubator.
Regards,
Rob…
January 15th, 2007 at 11:56 #
hi, thanks for the tutorial! - i was just wondering if there are a way to select from more tables. Lets say i have a table called albums, and one called artists. I have a modeler for both tables and i can select from both individual…
But what i cant do is select from both at the same time like this,
$albums = new album();
$albums->fetchAll();
$artists = new artist();
$artists->fetchAll();
- so lets say i want data from both i'll have to do it manual by using the database object and the select function
January 15th, 2007 at 12:03 #
wops, pushed before i was done writing :)
but i was wondering if there are a way to get by this with the use of the modeler? i've been looking around and cant seem to find a solution to this. It seems like the pdo CAN do query's simultaneity but i dont know if the zend framework has the same features. I cant seem to find anything about it in the manual
January 16th, 2007 at 04:50 #
i've been playing with this demo, on a windows box and linux. windows box path creation is messed up using the wrong slashes assuming linux. and then linux path creation is not working either.
great framework
January 16th, 2007 at 06:00 #
Ranza,
You need a class that implements the ActiveRecord design pattern. Zend_Db_Table doesn't do this, so you either need to roll your own or work around it until something is added to the Zend Framework.
As far as I remember, Bill Karwin is looking at the database components in the 0.8 time frame.
Regards,
Rob…
January 16th, 2007 at 06:04 #
Jim,
What do you mean by "Windows box path creation is messed up"? The tutorial specifically uses the PATH_SEPARATOR constant to ensure that it does work.
If you mean directory separator, then PHP on Windows can understand that / is a directory separator just like \ is.
Regards,
Rob…
January 16th, 2007 at 22:53 #
thank you for the tutorial
Great work!
January 23rd, 2007 at 16:27 #
Hi Rob,
problem at page 6 :
I changed the .htaccess in C:\Programmi\Apache Software Foundation\Apache2.2\htdocs ( document root) this way:
RewriteEngine on
RewriteBase /zf_tutorial
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
php_flag magic_quotes_gpc off
When I type http://localhost/ I can see the right page.
When I type http://localhost/index/ I can see the right page.
When I type http://localhost/index/add I see always " in IndexController::IndexAction()";
It seems that (apache /ZF ) redirect to defalt index action.
what the problem ?
thanks giorgio
January 29th, 2007 at 18:57 #
Any future release of the tutorial for the 0.7.0 release of the ZendFramework?
January 29th, 2007 at 19:10 #
Good point!
I'm nearly sure that it works "as is" with 0.7, but I'd better test ;)
Regards,
Rob…
January 31st, 2007 at 13:05 #
Hi,
Home page is loading fine. When i press on 'Add new album' link (http://localhost/zf-tutorial/index/add)
"The page cannot be found" error page is coming
ZF Version : 0.7
February 7th, 2007 at 10:41 #
Hi,
After i copied 'Zend' folder and Zend.php to zf-tutorial\library\
tutorial is working fine :-)
thanks
San.
February 7th, 2007 at 12:29 #
Hi San,
Glad to hear it!
Regards,
Rob…
February 7th, 2007 at 22:55 #
Hi Rob!
I would like to extend the application and make a view page to each album.
Offcource i use viewAction() and i make something like
function viewAction() {
$view =Zend::registry('view');
$view->title = "view the doc";
$doc = new Doc(); //i have change that,it's ok do not confuced
$view->docs = $doc->fetchAll();
$view->actionTemplate='indexView.tpl.php';
$this->_response->setBody($view->render('site.tpl.php'));
}
and in the indexView.tpl.php i use
escape($this->doc->name);?>
byt it looks like that is not so simple and i take Notice: Undefined property: Zend_View::$doc in …
Can you help me a while?
thanks!
February 13th, 2007 at 03:26 #
hi Rob,
I've been trying to use your tutorial and try to run it but why I always got this error :
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message '"index.php" controller does not exist' in D:\project\oprekzend\library\Zend.php:229 Stack trace: #0 D:\project\oprekzend\library\Zend\Controller\Dispatcher.php(386): Zend::exception('Zend_Controller…', '"index.php" con…') #1 D:\project\oprekzend\library\Zend\Controller\Front.php(725): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #2 D:\project\oprekzend\index.php(16): Zend_Controller_Front->dispatch() #3 {main} thrown in D:\project\oprekzend\library\Zend.php on line 229
I'm using W2K with IIS and PHP 5.1.4
thanks..
February 13th, 2007 at 06:27 #
Hi Baugus,
What's the URL that you are trying to access?
Regards,
Rob…
February 14th, 2007 at 04:13 #
192.168.0.1/oprekzend/index.php
February 14th, 2007 at 06:30 #
Bagus,
I think that the base url is not being set to the correct value.
Try adding:
After:
in index.php.
Regards,
Rob…
February 15th, 2007 at 04:06 #
I finally use setBaseUrl('/oprekzend/index.php')
and it's done..
but now when accessing page :
- http://192.168.0.1/zend/index/add,or
- http://192.168.0.1/zend/index/edit, or
- http://192.168.0.1/zend/index/delete
show page cannot be display at my browser..
I think this problem because I'm using IIS W2K ?
February 15th, 2007 at 08:28 #
Hi Bagus,
You now need to sort out ISAPI_Rewrite. There's more on the wiki at http://framework.zend.com/wiki/x/1Q.
Alternatively, you should find that URLs of the form http://192.168.0.1/oprekzend/index.php?controller=index&action=edit should work.
Regards,
Rob…
February 15th, 2007 at 15:00 #
English version has incorrect link to old 1.2.2.
February 15th, 2007 at 16:26 #
Thanks glumac!
Fixed.
Regards,
Rob…
February 16th, 2007 at 01:45 #
Hi,
First I would like to thank you for this great tutorial, may be the next step would be to include smarty and Ajax.
Second, when I tried calling http://www.mysite.com/zend/index.php, I got an error IndexPHPControllerPHP not found. So I investigated the root cause and traced it in the dispatcher, what I did was adding this line:
$frontController->getDispatcher()->setWordDelimiter('.php');
before
$frontController->throwExceptions(true);
I am wondering if this is safe to do that in Framework 0.7. By the way the fix to this same problem mentioned in here http://framework.zend.com/issues/browse/ZF-835 didn't work for me.
-Ali
February 16th, 2007 at 19:44 #
Rob,
Can you please tell me why you didn't approve my posting?
thanks,
-Ali
February 16th, 2007 at 20:18 #
Hi Ali,
Probably because I pressed the wrong button! I've approved it now. Sorry!
Regards,
Rob…
February 23rd, 2007 at 15:05 #
I ran into this very weird error. When i deploy the website on my production server i get this error as if it looks for my index controller in some weird dir.
ive tryed to set a basedir, give it absolute urls to the folders and so on. Do you have any idear of what causes this error?
error:
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message '"index" controller does not exist' in /home/frontier/library/Zend.php:229 Stack trace: #0 /home/frontier/library/Zend/Controller/Dispatcher.php(386): Zend::exception('Zend_Controller…', '"index" control…') #1 /home/frontier/library/Zend/Controller/Front.php(725): Zend_Controller_Dispatcher->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #2 /home/frontier/public_html/index.php(43): Zend_Controller_Front->dispatch() #3 {main} thrown in /home/frontier/library/Zend.php on line 229
my index.php: http://pastebin.dk/index.php?show=3054
February 26th, 2007 at 13:24 #
Great work. Looking forward to a 0.8 update ;-)
February 26th, 2007 at 22:42 #
ok, for ZF 0.8 :
(It's not a bug, it's a feature)! Zend_Controller_RewriteRouter was renamed to Zend_Controller_Router_Rewrite.
March 5th, 2007 at 04:22 #
Glen,
Where do I use Zend_Controller_RewriteRouter in the tutorial?
Regards,
Rob…
March 5th, 2007 at 04:23 #
christian,
Missing indexController.php or permissions problem?
Regards,
Rob…
March 5th, 2007 at 09:21 #
ah i found the problem. the controller looks for IndexController.php, not indexController.php :) - i coded the thing on my macbook and apache isnt case sensitive. My production server is a linux which IS case sensitive :)
kinda bad mistake sorry!
March 5th, 2007 at 14:14 #
Christian,
ah! done that too :(
Regards,
Rob…
March 7th, 2007 at 17:00 #
Just went through the tutorial, very clear. Thanks.
Unfortunately I downloaded a nightly snapshot rather than 0.8 and the Zend_Filter_Input class has been deprecated (and removed from the source tree) eight days ago.
I cannot find any documentation on how the replacement solution should be implemented, but thought you should know. If you find anything, I'd appreciate a response too!
Thanks
Alan
March 7th, 2007 at 21:13 #
Alan,
You can use $_POST directly in the action functions and remove all reference to Zend_Filter_Input in the index.php.
Have a look at Zend_Validate to do the validation bits. It's not static, so you have to create an instance of the Zend_Validate_XXX class first and then call it's check() method.
Hope that gives you some pointers.
Regards,
Rob…
March 18th, 2007 at 18:20 #
0.9.0 has affected the tutorial as components are deprecated. So far Zend::loadClass (index.php lines 10-15)
Zend_Filter_Input (index.php line 15)
Zend::register (index.php lines 18-19).
I keep referring back to this tutorial because it work so well. Thanks for keeping up with it.
March 18th, 2007 at 19:45 #
And then I find this article… doh!
http://akrabat.com/2007/03/10/goodbye-zendphp/
Once again, thanks for all your work and help.
March 18th, 2007 at 19:51 #
Hi John,
New version of the tutorial is in the works :)
The latest SVN version of the tutorial code at http://svn.akrabat.com/svn/zf-tutorial/trunk/ works with 0.9 after you fix the typo in Zend/Db/Table/Row/Abstract.php.
Regards,
Rob…
March 21st, 2007 at 16:16 #
Hi Rob,
I tried to use your tutorial, but my ZF is 0.9.0 and it not worked…
What can I do to make it works??
Regards,
José
March 21st, 2007 at 21:39 #
How bout 0.9.0 Beta MVC tutorial?
March 22nd, 2007 at 01:02 #
Look up just above your comments to #176, guys. He is working on a 0.9.0 version and it will be out shortly.
March 22nd, 2007 at 16:45 #
Hi, I downloaded version 0.8.0 and at the IndexAdd action, the follow error occurs:
Fatal error: Uncaught exception 'Zend_Controller_Response_Exception' with message 'Cannot send headers; headers already sent' in D:\www\projeto\lib\Zend\Controller\Response\Abstract.php:240 Stack trace: #0 D:\www\projeto\lib\Zend\Controller\Response\Abstract.php(125): Zend_Controller_Response_Abstract->canSendHeaders(true) #1 D:\www\projeto\lib\Zend\Controller\Action.php(607): Zend_Controller_Response_Abstract->setRedirect('/projeto/', 302) #2 D:\www\projeto\application\controllers\IndexController.php(45): Zend_Controller_Action->_redirect('/') #3 D:\www\projeto\lib\Zend\Controller\Action.php(392): IndexController->addAction() #4 D:\www\projeto\lib\Zend\Controller\Dispatcher\Standard.php(211): Zend_Controller_Action->dispatch('addAction') #5 D:\www\projeto\lib\Zend\Controller\Front.php(750): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #6 D:\www\projeto\index.php(44): Zend_Controller_Front->dispatch() #7 {main} thrown in D:\www\projeto\lib\Zend\Controller\Response\Abstract.php on line 240
I think its because line "$this->_redirect('/');" but I don't know how to fix it…
March 22nd, 2007 at 16:50 #
How to get the source code??? how to use these SVN stuff?
March 24th, 2007 at 04:25 #
I was getting the error:
Uncaught exception 'Zend_View_Exception' with message 'script 'index/index.phtml' not found in path' in /Volumes/Storage/SYSTEM/wwwroot/zend/library/Zend/View/Abstract.php:594
until I changed the line
$view->setScriptPath(realpath('./application/views'));
to
$view->setScriptPath(realpath('./application/views/scripts'));
when trying to use your 26th revision in your zf-tutoiral with zend framework 0.9.0 … should I not had to have done this?
March 24th, 2007 at 09:03 #
Jose, first get a copy of subversion (svn). You can get Rob's latest code with the command:
svn co http://svn.akrabat.com/svn/zf-tutorial/branches/1.2/
March 24th, 2007 at 14:14 #
Scott,
It's a bug in revision 26. We don't need to create the view in the bootstrap any more. Revision 27 fixes it.
Regards,
Rob…
March 24th, 2007 at 17:20 #
Can't download rev27 or perhaps don't know how to use svn.
I'm having a lot of problems with include path. I had to set up a separate path file to require_once each class file, for some reason I can't include the entire dir. Also having the same problem with Abstract.php (post 182), but I don't know how to fix (adding 'scripts' didn't work).
March 24th, 2007 at 18:22 #
Rob,
Thanks for the response, I checked out Rev 27 and that worked without modification…actually, that is not true. I had the same problem as Matt in setting the include path…I used his include_path that he showed in post 69 (I am running a MAMP setup in OSX, just so you know). This is a great tutorial and trying to fix bugs is what makes me understand the framework that much better, thanks for your hard work!
March 24th, 2007 at 18:57 #
Scott,
Great - I'm glad 27 fixed that one!.
With any luck 28 fixes the include path issue.
Regards,
Rob…
March 25th, 2007 at 02:10 #
Just downloaded version 1.3.0
After adjusting pathing to match my need to store things outside the root, it works perfectly. Took all of 10 minutes.
Now to see if I can break (err) use it again as a study guide. :-)
Once more… Thanks loads.
March 25th, 2007 at 07:43 #
The best Tutorial. This should be included in zend as the official tutorial.
March 26th, 2007 at 10:28 #
Great tutorial!
I would like to report a minor typo - the hyperlink at the top of page 5 refers to http://localhost/zf_tutorial/
instead of
http://localhost/zf-tutorial/
Regards
March 27th, 2007 at 18:10 #
At first I couldn't get the delete functionality to work. Already thought it was strange the tutorial referred to a zf-tutorial/application/views/indexDelete.tpl.phpp template, which doesn't seem to fit in with the rest of the structure.
It worked as soon as I applied the changes in the delete template that was made before, located at zf-tutorial/application/views/scripts/index/delete.phtml.
March 29th, 2007 at 06:22 #
I too am getting the same error as Jose #180 - I too think it has something to do with the $this->_redirect('/');
Can't send headers error.
Looking forward to a solution.
March 29th, 2007 at 06:41 #
Jeff,
Headers already sent issues are usually related to echoing out something before the call to _redirect().
Out of interest, do you have a closing ?> followed by a couple of blank lines anywhere?
Regards,
Rob…
March 29th, 2007 at 07:50 #
Hi Rob
Thanks for getting back to me so quickly - no, no closing ?> and no blank lines anywhere.
It just stops at the redirect, I can echo something out right before but not before the 'return;'
I've copied the code below:
Cheers
Jeff
public function editusersAction()
{
$this->view->pageTitle = 'edit this users';
$this->view->section = ";
$this->view->setCSS = ";
$this->view->action = 'edit';
$this->view->button = 'update';
$this->view->userTypeLabel = 'you are a';
$this->view->users = new stdClass();
$db = Zend_Registry::get('dbAdapter');
// set up null values
$id = $this->getRequest()->getParam('id');
$sql = $db->select();
$sql->from('users', '*');
$sql->where('users.id =?', $id);
$this->view->users = $db->fetchRow($sql);
$userTypeSql = $db->select();
$userTypeSql->from('user_types', '*');
$this->view->userTypes = $db->fetchAll($userTypeSql);
if ($this->getRequest()->isPost()) {
Zend_Loader::loadClass('Zend_Filter_StripTags');
$filter = new Zend_Filter_StripTags();
// set the post variables
$now = date('Y-m-d H:i:s');
$id = (int)$this->_request->getPost('id');
$user_type_id = trim($filter->filter($this->_request->getPost('user_type_id')));
$username = trim($filter->filter($this->_request->getPost('username')));
$password = trim($filter->filter($this->_request->getPost('password')));
$email = trim($filter->filter($this->_request->getPost('email')));
$verified = trim($filter->filter($this->_request->getPost('verified')));
$last_updated = $now;
$deleted = trim($filter->filter($this->_request->getPost('deleted')));
$preferred_name = trim($fil