What I was doing was something like this (trimmed down):
public function updateAction()
{
$id = $filterInt->filter($this->_getParam('id'));
$data = array(
'ref' => $this->_getParam('ref'),
'type' => $this->_getParam('type'),
'title' => $this->_getParam('title'),
'keywords' => $this->_getParam('keywords'),
'description' => $this->_getParam('description'),
'template' => $this->_getParam('template'),
'ranking' => $this->_getParam('ranking'),
'body' => $this->_getParam('body')
);
$where = $this->_database->quoteInto('id = ?', $id);
$rows_affected = $this->_contentTable->update($data, $where);
// Some other bits were here but are innocent of wrongdoing
// Send back to the edit form
//$this->_forward('edit', 'content', null, array('id' =>
$id));
<--- Here lies the culprit
$this->_redirect('/content/edit/id/' . $id); <--- Replacing
with
this solved it
}
What was happening was the database row would be updated but many
of the
fields were blank.
I'm currently using Zend_Layout but this was happening (seemingly
erratically) beforehand.
So my question is: Why might this be happening?
It suggests that _forward is somehow repeating the database update
but
without the original _POST data?
Depends on what your ContentController::editAction() does -- and since
that's not in the code snippet above, I can't really give you an
answer.
All _forward() does is dispatch another action. It does nothing with
the
database, and it doesn't clear any request parameters. My guess is
that
editAction() is doing something that alters the table. Send that
method,
and perhaps I can be of more help.
Yeah my guess was a huge long-shot as I know that _forward() has
nothing to do with the database.
Here is my editAction in all its embarrassing prototype stage:
public function editAction()
{
$filterInt = new Zend_Filter_Int;
$id = $filterInt->filter($this->_request->getParam('id'));
// Get a hierarchical category tree
$this->view->tree = $this->_contentToContentTable-
>getTree($this->_contentToContentTable->fetchTree(), 0);
$this->view->form_action = empty($id) ? '/content/create/' :
'/content/update/id/' . $id . '/';
$this->_database = $this->getInvokeArg('database');
$this->view->types = $this->_contentTable-
>getEnumOrSet('type');
$this->view->templates = array('default');
// Get the content
$where = $this->_database->quoteInto('id = ?', $id);
$row = $this->_contentTable->fetchRow($where);
if (null !== $row) {
$this->view->edit_content = $row->toArray();
// Get the categories that this content belongs to
$where = $this->_contentToContentTable->getAdapter()-
>quoteInto('child_id =?', $row->id);
$content_categories = $this->_contentToContentTable-
>fetchAll($where);
$contentCategoriesArray = $content_categories->toArray();
$imploder = new Menu_Array_Imploder;
$implodedCategories = $imploder->implode2D(',',
$contentCategoriesArray, 'parent_id');
$this->view->contentCategories = explode(',',
$implodedCategories);
// Get the creator of the content
include_once 'models/UserTable.php';
$userTable = new UserTable();
$creator = $row->findParentRow($userTable, 'Creator');
$this->view->creator = $creator->toArray();
// Get any files "attached" to this content
$uploader = new Menu_Upload(getcwd() . '/content/' .
$id . '/');
$this->view->attachments = $uploader->getFiles();
} else {
$this->view->contentCategories = array();
}
}
It should hopefully show that it's only doing select queries.
I'm not really looking for you to look too deep into this Matthew as I
know you've got a few things to be getting on with! I'm really just
posting to see if I get an "aha, the same happened to me, perhaps
it's ...". If I had more time I'd be looking into it a bit more.
Thanks for your help,
Nick