我在表单加载时收到此错误:
“Flipbook”上的未知记录属性/相关组件“title”
事情是......我不知道“标题”来自哪里。我在架构和数据库中将其设置为career_title
。构建模型并且基类是正确的。
这是我的行动:
public function executeEdit(sfWebRequest $request)
{
if (get_class($this->getRoute()) == 'sfDoctrineRoute') {
/* edit action */
$flipbook = $this->getRoute()->getObject();
}
else {
/* add action */
$flipbook = new Flipbook();
}
$this->form = new FlipbookForm($flipbook);
if ($request->isMethod('post')) {
$this->form->bind($request->getParameter('flipbook'));
if ($this->form->isValid()) {
$this->form->save();
$this->getUser()->setFlash('message_success', 'Flipbook saved');
return $this->redirect('@flipbook_edit?id=' .
$this->form->getObject()->get('id') .
($request->getParameter('preview') ? '&preview=1' : ''));
}
}
}
如果我从$flipbook
中删除$this->form = new FlipbookForm($flipbook);
变量,我会获得一个成功渲染的表单,但我需要对象数据来重新填充输入字段。
我只是不知道为什么它会在对象上找到“标题”。我没有在任何地方引用(我不认为)。有任何想法吗?错别字?建议?
如果我需要提供更多代码,请告诉我。
以下是添加的类的 yml架构:
Generic:
actAs: [ Timestampable ]
columns:
updated_by: { type: integer }
created_by: { type: integer }
published: { type: boolean, default: 0 }
relations:
creator:
class: sfGuardUser
foreignAlias: created_users
local: created_by
onDelete: "SET NULL"
last_updater:
class: sfGuardUser
foreignAlias: updated_users
local: updated_by
onDelete: "SET NULL"
flipbook:
url: /flipbook
param: { module:
Flipbook:
tableName: flipbook
inheritance:
extends: Generic
type: concrete
columns:
career_title: { type: string(255) }
career_associations: { type: clob }
skills: { type: string(255) }
skills_associations: { type: clob }
program: { type: string(255) }
program_associations: { type: clob }
draft_id: { type: integer(10) }
如果需要,最后是模板:
<?php echo $form->renderFormTag(url_for($form->getObject()->isNew() ? '@flipbook_add' : ('@flipbook_edit?id=' . $form->getObject()->get('id'))), array('method' => 'post', 'id' => 'edit_form', 'name' => 'edit_form', 'class' => 'generic_form job_form')) ?>
<?php echo $form['id'] ?>
<div class="content-box">
<div class="box-body">
<div class="box-header clear">
<h2>Flipbook</h2>
</div>
<div class="box-wrap clear" style="display: block;">
<?php echo $form ?>
</div><!-- end of box-wrap -->
</div> <!-- end of box-body -->
</div>
<div class="buttons_row right main_actions">
<?php include_partial('global/apply_changes_button', array('form' => $form)) ?>
<?php include_partial('global/publish_button', array('form' => $form)) ?>
</div>
</form>
<?php include_partial('global/preview', array('form' => $form)) ?>
路由:
flipbook, action: index }
flipbook_add:
url: /flipbook/add
param: { module: flipbook, action: edit }
flipbook_edit:
url: /flipbook/edit/:id
param: { module: flipbook, action: edit }
param: { module: flipbook, action: edit }
class: sfDoctrineRoute
options: { model: Flipbook, type: object }
requirements:
id: \d+
sf_method: [get, post]
堆栈追踪:
stack trace at () in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record/Filter/Standard.php line 55 ...
public function filterGet(Doctrine_Record $record, $name)
{
throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property
/ related component "%s" on "%s"', $name, get_class($record)));
}
}
更新
这仍然没有真正解决,所以我想保持它开放一点,看看是否有人可以诊断问题。我解决这个问题的方法是在架构中将career_title
更改为title
。我重建了模型和表格,一切正常。关于为什么会发生这种情况的任何进一步说明都有利于这一事业。