I’ve been using Doctrine a lot in my own work, and recently found myself itching to have tighter integration between Zend and Doctrine when it comes to user logins. Luckily, Zend provides a very simple interface with regards to Zend_Auth. This way, it’s easy to decouple your persistence layer (in my case Doctrine) from the authentication layer. I’ve borrowed from Palo Verede’s wonderful article on Doctrine and Zend_Auth and I invite you to check his blog out.
Grab a copy of the project or browse the repository.
Also, a big thank you to ServerGrove for extending their support of Zendcasts for January. ServerGrove specializes in Zend Framework hosting and they’ve offered a 10% rebate on hosting with coupon code “zc”. If you’re looking for a host, be sure to check them out (referral). They’ve also added an additional coupon for “Mini Hosting” plans, get $2 off by using code “zcmini”.

Hi Jon,
I’ve tried to implement my doctrine auth adapter base on Palo Verede’s post a while back. but I had some issues with it myself. It’s great to see you showing us how to make a working solution from zendcasts.
However there’s something I want to share with the rest of the community too. My made an implementation with the use of ZendX_Doctrine_Auth_Adapter from the ZendX incubator.
Because of the length of the explanation, instead of posting my alternative solution here, I’ve just written a blog post at http://blog.elinkmedia.net.au/2010/01/24/zf-authentication-using-doctrine/
It’ll be great if I can get your opinions on my implementation.
Hy Jim,
I think you put together a great post with a solid implementation. My only comment is that with this design, you’ve now coupled the object creation code to your Controller. On Monday I’ll be posting the IndexController code that will actually use the Zend_Auth_Adaoter written in this tutorial. I’d prefer this approach simply because after you’ve performed the authenticate() method, you don’t have to do any storage->write() business, but simply let Zend_Auth do its thing.
Hi Jon,
You are spot on. I should be able to pull logic inside the _getAuthAdapter function out of the controller, and put in a login service class, or something like that. What do you think?
These tutorials are very useful… I’m going through all of them and really appreciate the level of detail.
Keep up the good work!
Jasper
Hey,
Really great tutorials!
I downloaded the source code and I got a mysql error when trying to reload the tables. The mysql string was output to the cmd prompt, so I copied it into mysql query browser.
I started with, create table user, as was shown in the command prompt, but i noticed that user was a reserved mysql word, I tried putting user in backticks in the yml, but that actually created a file called `user`.php… Alas, I just changed schema.yml to create userS, and everything worked great. You the man, Jon!
Great
. You was looking for how to configure modules right ?
I am not sure whether this will completely work . I was just playing around it .
This is something I hacked after seeing your video . I will be trying to do more tricks on it . And as an experienced person you may be able to refactor it . Not sure whether you have tried and dropped it though .
here it comes . After the config is loaded in doctrine.ph
$config = $application->getOption(‘doctrine’);
add the below code
$length = strlen( APPLICATION_PATH );
if(is_array($_SERVER['argv']) ) {
$modulePosition = array_keys( $_SERVER['argv'] , 'module');
if ( !empty( $modulePosition ) ) {
$moduleName = $_SERVER['argv'][$modulePosition[0]+1];
if ( is_dir( APPLICATION_PATH . "/modules/$moduleName" ) ) {
foreach( $config as $key => $value ) {
$config[$key] = APPLICATION_PATH . "/modules/$moduleName" . substr_replace($value, '', 0, $length);
}
}
}
}
I assume people will be calling like ./doctrine test module blog
Not sure whether doctrine has something like module calling . Hope not , else we can change . I am just playing so may be wrong too . I am interested to hear what you think about this .
Thanks
Hari K T
For module specific doctrine models I have came up with a solution for doctrine.php .
You guys can check it out at http://harikt.com/content/integrating-doctrine-zendframework-modules .
Let me know your comments
@Francis
You solve my problem.(with sql export and import encoding in sequel pro)
Thank’s a lot:)
@Hari KT
I just read over http://www.doctrine-project.org/projects/orm/1.2/docs/manual/yaml-schema-files%3Afeatures-%26-examples/1_1#packages
and remembered the module issue here.
The above mentioned article describes how to specify the doctrine model targets in file system via schema yaml file and the package option.
CU
@szsoftware
That’s good
. I was learning doctrine . So the solution was at that time what I thought .
now .
Thanks for notifying me . Will look more into it . Brought the Doctrine Book
people want to introduce so many tools? like docorine, Apache Ant. They are really really confuse my small brain!!!!!!!!!!!!
Please limit the scope!!!
why you use “docorine” to generate a record in the database? isn’t easier to just input the record in your phpAdmin?
If you use docorine, you generate another degree of complexity to my brain!! I hate complexity!
@Nicolas: the less software we have to write, the more interesting software we have time to write
These tools are intimidating at first (I feel the same way sometimes), but they really do make your life a lot easier in the long run. When you’re using Doctrine, you have a single place to go if you want to change your database schema. If you’re unit testing your code (which you should), without Doctrine, you would have at least 3 different places to reflect that change (test db, dev db, models). That’s a lot of pointless running around every time you want to add a column!