Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/142464-zend_db_table/
Share on other sites

  • 2 weeks later...

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!

Link to comment
https://forums.phpfreaks.com/topic/142464-zend_db_table/#findComment-758121
Share on other sites

  • 2 weeks later...

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.

Link to comment
https://forums.phpfreaks.com/topic/142464-zend_db_table/#findComment-764804
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/142464-zend_db_table/#findComment-770238
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.