Zend Framework: Cannot save a row unless it is connected

Recently I was working on developing an application in PHP using Zend Framework, and when I tried to do an action that used the database in an previously serialized object that extends the class Zend_Db_Table_Row_Abstract – stored in a session, for example – an exception was thrown with the following message:

Cannot save a row unless it is connected

A small snippet of code that represents the problem:

$namespace = new Zend_Session_Namespace('signinData');
$user = $namespace->user;
$user->save();


The solution is simple and is in the documentation of the method setTable() in Zend_Db_Table_Row_Abstract class:

Set the table object, to re-establish a live connection to the database for a row that has been de-serialized.

What should be done is to call the object setTable() method by passing a new instance of the table to which the object refers.

Then the solution based on initial example:

$namespace = new Zend_Session_Namespace('signinData');
$user = $namespace->user;
$user->setTable(new App_Model_UserTable());
$user->save();

Thus, the exception ceases to be thrown when I try to save the user.

About these ads

5 comentários sobre “Zend Framework: Cannot save a row unless it is connected

  1. Pingback: Tweets that mention Zend Framework: Cannot save a row unless it is connected « Gustavo Straube -- Topsy.com

  2. I’m having a problem related to this one too, except that after I call the setTable() method my whole row becomes null! It’s driving me nuts.
    In fact, I CAN save() after the object is deserialized even though the documentation an everybody else says otherwise!

  3. Pingback: Zend_Db_Table_Row and Zend_Cache | jameshd – web ramblings

  4. Hi! Thanks for the awesome post.
    In my case, I had a Row in session because every data in a whole module varies from this parent row.
    But in this row I had a user_id, and I stored in session with the user.name (from another table called `user`), being a column that doesn’t live in this table.
    The problem is: when I try to hydrate the object setting the table to find a dependent rowset, Zend Framework throws the Exception “The specified Table does not have the same columns as the Row”, as I don’t have a userName in the real table.

    Anyway, what I’m telling you guys, that just like me, stored a Row in session, is that you should better store a DTO or a ValueObject, and when you need it as a row, fetch it. Otherwise you will lose your whole morning as I did :/

    Again, thanks for the post.

Deixe uma resposta

Preencha os seus dados abaixo ou clique em um ícone para log in:

WordPress.com Logo

Você está comentando usando sua conta WordPress.com. Sair / Mudar )

Imagem do Twitter

Você está comentando usando sua conta Twitter. Sair / Mudar )

Foto do Facebook

Você está comentando usando sua conta Facebook. Sair / Mudar )

Conectando a %s