moon 111 Posted January 26, 2009 Share Posted January 26, 2009 I have started using ZF and I was wondering: do you usually have a class for each of your tables, or do you use the built in classes (Zend_Db_Select etc.) in your controllers? Also, I've found it very difficult to have Table relationships in the classes and Zend's documentation has been no help. Thanks, - Moshe P.S. If anyone farmiliar with ZF can help me out over E-mail, or MSN when I need help, it would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/142464-zend_db_table/ Share on other sites More sharing options...
gethinw Posted February 9, 2009 Share Posted February 9, 2009 I'd be quite interested to see what people say in reply to this. I'm quite new to MVC style programming, and this in particular is something I've struggled with getting my head around. FWIW I haven't actually ended up using Zend_Db_Table much recently, but what I've generally ended up doing is having a Model class for each source of data, which might be one table, or could be a combination of tables (using JOIN or whatever), and extending the built in classes, keeping as much of them as possible, but altering any bits which are necessary, to keep the controllers as small as possible - one of the key ideas behind ZF is that you should aim for a 'skinny controller' (ie as little code as possible in the controller - it should basically just get data from the model and pass it to the view (and vice versa if appropriate), but do as little data manipulation as possible). That probably doesn't help much really... If you give us a better idea of what you're trying to do we might be able to provide more direct guidance! Quote Link to comment https://forums.phpfreaks.com/topic/142464-zend_db_table/#findComment-758121 Share on other sites More sharing options...
milesap Posted February 18, 2009 Share Posted February 18, 2009 Each table would have it's own class, because you want to separate the Model from the Component in the MVC architecture. Let's say your User table in MySQL has a last modified field. Since the table has it's own class, the Model can update the last modified field everytime you update that row, rather than you having to do it in each query. Quote Link to comment https://forums.phpfreaks.com/topic/142464-zend_db_table/#findComment-764804 Share on other sites More sharing options...
JustinM01 Posted February 24, 2009 Share Posted February 24, 2009 I usually just extend Zend_Db_Table_Abstract. Like this: class SomeTable extends Zend_Db_Table_Abstract { protected $_name = 'table_in_your_db'; protected $_primary = 'column_name_of_your_primary_key'; } Its very simple. This allows me to use Zend_Db_Select very easily along with updates, inserts, and deletes. $tableObj = new SomeTable(); $select = $tableObj->select(); $select->where(array("$id = $someId", "time" => "UNIX_TIMESTAMP(time)")); $row = $tableObj->fetchRow($select); Sure, I could make an actual function on the table to do the above seamlessly, but I haven't yet. It works, and it works well. It really is up to you and what you're comfortable with. So, yes, I do make separate classes for each of my tables. It allows me to do the above and get fancy if I so choose. Quote Link to comment https://forums.phpfreaks.com/topic/142464-zend_db_table/#findComment-770238 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.