LDAP instead of SQL ?

Hi everybody,

I have to update an old PHP framework to a brand new MVC-compliant one.

I took a look at the PHP frameworks and Yii really impressed me. Automatic code generation with PHP/Ajax form validation is great. Thumbs up guys!

There’s still one point that bothers me. The framework uses a mix of mySQL and LDAP to store data. I managed to create models directly from mySQL. But I did not find how to integrate LDAP.

I’m not talking about authentication. The LDAP contains “model” data that is used inside the framework. They used LDAP because they needed to maintain the “database” in sync across multiple machines and LDAP allowed to do that easily.

I’d like to know if it will be easy to have my models talk to an LDAP server and if I still can have form validation, etc,.

Any clues or pointers are welcome.

Thanks !

I don’t know much about LDAP, but i was in a similar situation when i had to connect some of my models to a remote webservice. For a start you could e.g. extend your LDAP models from CModel (which provides the validation framework) and build in your own custom validation methods that somehow connect to the LDAP server.

You could also add some find/save methods. It might also make sense to have a intermediate base class for all your LDAP models (e.g. LdapBaseModel extends CModel) with code that all your concrete LDAP models will share.

I know, this is a very abstract advice. But maybe it gives you some idea, what kind of thinking is useful, when you build your applications with Yii.

Thanks Mike,

I understood that my "LdapBaseModel" should not inherit from CActiveRecord.

But, why can’t it inherit from CFormModel instead of CModel ? Doesn’t CFormModel add additional “features” that I may use in my LDAP stuff ?

Cheers

Sure, why not. Frankly speaking i’m also not sure, why Yii has the separation of CModel + CFormModel, and why CActiveRecord extends from CModel. In my opinion a CActiveRecord should be a “full featured” form model plus some DB extras.

If you look a the current implementation you see, that it’s the attributeNames() method that does not allow for merging CFormModel into CModel: attribute names are either form model attributes or db column names, but not a mixture of both. This architecture makes it not so easy to merge CFormModel and CModel. Maybe this will change in a later release.

But that should not affect your LDAP models much for now. I’d look at the implementation of CFormModel to get some ideas how you could incorporate your LDAP attributes.

Actually, I succeeded in formatting an LDAP query result into a CArrayDataProvider and I displayed it into a zii.widgets.grid.CGridView .

It works but it is really ugly : My model inherits from CFormModel and has a single function "load" that sets up the connection and formats the result.

I need to have a clean design with a model validation like in CActiveRecord… Something with search/create/delete/modify/relations capabilities.

To do so, I tried to understand the source code of CActiveRecord.php but it is too hard. Too many dependencies.

Does someone know of a simpler Model class that uses arrays, or xml files, or so, instead of sql databases for example ?

If not, what are the functions that I should implement in my model to have something that is compatible with widgets, form validation, etc.

thanks !

Hi Rayene,

did you start developing your own Model class for LDAP access?

I have to develop a admin area based only on LDAP.

Maybe we can develop a base class together.

Bye

Yes sure… If someone else is interested, please join us -> moving to private mode

I’ve developed an extension called ldaprecord to access ldap data.

Maybe you can give it a trial.

Bye