2

i am using Zend Framework to build a web interface for setting up ACL - permission rights - for users of a custom CMS. Since the ACL data is spread in 5 tables(users, groups, permissions, urls=action+controller, nice permission name for the user to understand) and i have only one controller with the four basic CRUD(create, list, update, delete) operations i was wondering what is the best way to do it?

All the examples in my books i've seen that each model extend Zend_Db_Table_Abstract and thus represents one table.

I was thinking i have to do a model that doesn't extend zend_db_table_abstract and then write the queries that i need by hand thus limiting myself to mysql database only?

p.s. please do not argue over the acl database structure

thank you

1 Answer 1

3

The definition of the Table Data Gateway pattern is

An object that acts as a Gateway to a database table. One instance handles all the rows in the table.

That's why you won't see it used any differently in Zend Framework. It's a Data Source Architectural Patterns while the thing you are asking about is a Domain specific class.

What you are encountering is Impedance Mismatch, meaning your Business Objects dont match the structure of your Database Design. The common solution is to use a DataMapper or an ORM to handle that for you.

The other solution would be to create a View in your database that joins the tables in a way that maps 1:1 to your required business objects. Then add a Zend_Db_Table for that view. You'd still have to come up with custom create, update, delete logic though. That's not data mapping though, but if you don't have any Business/Domain classes to map to, it's fine.

Sign up to request clarification or add additional context in comments.

5 Comments

so if i write the model's 4 functions(getAll, deleteById, create, updateById) by hand that would be equivalent to data mapping correct?
@max4ever I am not sure what your definition of model is. The model is not just the database. The database is the persistence layer. It's one part of the Model, but it's not THE model. There may be several other layers in the Model as well.
sorry, i ment the model as the M from the MVC pattern, i don't think the view in the database will be allowed, so instead of building a view in the database i could just build the same abstraction using "select ... from ..." queries in the 4 functions i described above, right ? :/
@max4ever but to answer your question: your mapper would be a mediator between the domain layer and the persistence layer. It should know how to map between domain and persistence layer. That means, it should know which methods to call on the domain and the persistence layer objects to transfer data between them. It should not contain the logic to speak to the database or any logic of the domain object.
@max4ever Yes, you could do that. Strictly speaking, that wouldn't be a DataMapper then though but a custom Table Data Gateway. If you dont have dedicated Domain layer in your Model, that's fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.