如何在 symfony 中定义模型字段的值?

发布于 2024-09-08 11:36:27 字数 363 浏览 1 评论 0原文

我正在为我在 symfony 工作的公司构建一个应用程序,尽管如此,该应用程序在我们公司之外可能非常有用,所以我们决定以更通用的形式编写它,这样我们就可以使其成为多个公司的应用程序。我面临的问题是如何为每个模型 (company_id) 中的字段定义默认值,因此我们不需要每次要添加数据时都选择属于哪家公司。谁能帮助我吗? 我已经尝试过了

class TestForm extends BaseTestForm
{

    function configure()
    {
        $this->setDefault('company_id', '1');
    }
}

,当我提交表单时,我得到了模型的缺失值......

I'm building an app for the company I work for in symfony, non the less the app might be pretty useful outside our company so we decided to write it in a more general form so we can make it multi company. I'm facing a problem on how to define a default value for a field that is going to be in every single model (company_id) so we don't need to select which company we belong to every time we want to add data. can anyone help me?
I've tried

class TestForm extends BaseTestForm
{

    function configure()
    {
        $this->setDefault('company_id', '1');
    }
}

and when I submit the form I get a missing value for model ....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲影 2024-09-15 11:36:27

当然,在 processForm 之前和 $this->form = new TestForm(); 之后的操作中,我做到了。

我用过:

公共函数executeCreate(sfWebRequest $request)
{

...
$this->form->getObject()->setCompanyId('1');
...

<代码>}

I did it, in the action of course, before the processForm and after the $this->form = new TestForm();

I used:

public function executeCreate(sfWebRequest $request)
{

...
$this->form->getObject()->setCompanyId('1');
...

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文