symfony 1.4:有关从父类访问子类的问题

发布于 2024-10-06 02:52:55 字数 2980 浏览 1 评论 0原文

我有这个架构:

  shop_products:
    _attributes: { phpName: ShopProduct }
    products_id: { phpName: Id, type: INTEGER, size: '11', primaryKey: true, autoIncrement: true, required: true }
    products_quantity: { phpName: Quantity, type: INTEGER, size: '4', required: true }
    products_model: { phpName: Model, type: VARCHAR, size: '12', required: false }
    products_image: { phpName: Image, type: VARCHAR, size: '64', required: false }
    products_price: { phpName: Price, type: DECIMAL, size: '15', scale: '4', required: false, defaultValue: '0.0000' }
    products_date_added: { phpName: DateAdded, type: TIMESTAMP, required: true }
    products_last_modified: { phpName: LastModified, type: TIMESTAMP, required: false }
    products_date_available: { phpName: DateAvailable, type: TIMESTAMP, required: false }
    products_weight: { phpName: Weight, type: DECIMAL, size: '5', scale: '2', required: true }
    products_carati: { phpName: Carati, type: FLOAT, required: false, defaultValue: '1' }
    products_status: { phpName: Status, type: TINYINT, size: '1', required: true }
    manufacturers_id: { phpName: ManufacturerId, type: INTEGER, size: '11', required: false, foreignTable: shop_manufacturers, foreignReference: manufacturers_id, onDelete: SETNULL }
    products_ordered: { phpName: Ordered, type: INTEGER, size: '11', required: true, defaultValue: '0' }


  shop_categories:
    _attributes: { phpName: ShopCategory }
    categories_id: { phpName: Id, type: INTEGER, size: '11', primaryKey: true, autoIncrement: true, required: true }
    categories_image: { phpName: Image, type: VARCHAR, size: '64', required: false }
    parent_id: { phpName: ParentId, type: INTEGER, size: '11', required: true, defaultValue: '0', foreignTable: shop_categories, foreignReference: categories_id, onDelete: CASCADE, onUpdate: CASCADE }
    sort_order: { phpName: SortOrder, type: INTEGER, size: '3', required: false }
    date_added: { phpName: DateAdded, type: TIMESTAMP, required: false }
    last_modified: { phpName: LastModified, type: TIMESTAMP, required: false }



  shop_categories_description:
    _attributes: { phpName: ShopCategoryDescription }
    categories_id: { phpName: CategoryId, type: INTEGER, size: '11', primaryKey: true, required: true, defaultValue: '0', foreignTable: shop_categories, foreignReference: categories_id, onDelete: CASCADE, onUpdate: CASCADE }
    language_id: { phpName: LanguageId, type: INTEGER, size: '11', primaryKey: true, required: true, defaultValue: '1', foreignTable: culture, foreignReference: id, onDelete: CASCADE, onUpdate: CASCADE }
    categories_name: { phpName: Name, type: VARCHAR, size: '32', required: true }

然后,我从 ShopProducts 模型创建了一个管理模块,但是当我尝试访问它时,它说:

“ShopCategory”类必须实现 要渲染的“__toString”方法 一个“sfWidgetFormPropelChoice”小部件

如您所见,类别名称所在的模型是 ShopCategoriesDescription。那么,我如何从 ShopCategory 模型类中获取类别名称?

哈维尔

SF 1.4/推进

i have this schema:

  shop_products:
    _attributes: { phpName: ShopProduct }
    products_id: { phpName: Id, type: INTEGER, size: '11', primaryKey: true, autoIncrement: true, required: true }
    products_quantity: { phpName: Quantity, type: INTEGER, size: '4', required: true }
    products_model: { phpName: Model, type: VARCHAR, size: '12', required: false }
    products_image: { phpName: Image, type: VARCHAR, size: '64', required: false }
    products_price: { phpName: Price, type: DECIMAL, size: '15', scale: '4', required: false, defaultValue: '0.0000' }
    products_date_added: { phpName: DateAdded, type: TIMESTAMP, required: true }
    products_last_modified: { phpName: LastModified, type: TIMESTAMP, required: false }
    products_date_available: { phpName: DateAvailable, type: TIMESTAMP, required: false }
    products_weight: { phpName: Weight, type: DECIMAL, size: '5', scale: '2', required: true }
    products_carati: { phpName: Carati, type: FLOAT, required: false, defaultValue: '1' }
    products_status: { phpName: Status, type: TINYINT, size: '1', required: true }
    manufacturers_id: { phpName: ManufacturerId, type: INTEGER, size: '11', required: false, foreignTable: shop_manufacturers, foreignReference: manufacturers_id, onDelete: SETNULL }
    products_ordered: { phpName: Ordered, type: INTEGER, size: '11', required: true, defaultValue: '0' }


  shop_categories:
    _attributes: { phpName: ShopCategory }
    categories_id: { phpName: Id, type: INTEGER, size: '11', primaryKey: true, autoIncrement: true, required: true }
    categories_image: { phpName: Image, type: VARCHAR, size: '64', required: false }
    parent_id: { phpName: ParentId, type: INTEGER, size: '11', required: true, defaultValue: '0', foreignTable: shop_categories, foreignReference: categories_id, onDelete: CASCADE, onUpdate: CASCADE }
    sort_order: { phpName: SortOrder, type: INTEGER, size: '3', required: false }
    date_added: { phpName: DateAdded, type: TIMESTAMP, required: false }
    last_modified: { phpName: LastModified, type: TIMESTAMP, required: false }



  shop_categories_description:
    _attributes: { phpName: ShopCategoryDescription }
    categories_id: { phpName: CategoryId, type: INTEGER, size: '11', primaryKey: true, required: true, defaultValue: '0', foreignTable: shop_categories, foreignReference: categories_id, onDelete: CASCADE, onUpdate: CASCADE }
    language_id: { phpName: LanguageId, type: INTEGER, size: '11', primaryKey: true, required: true, defaultValue: '1', foreignTable: culture, foreignReference: id, onDelete: CASCADE, onUpdate: CASCADE }
    categories_name: { phpName: Name, type: VARCHAR, size: '32', required: true }

Then, I have created an admin module from the ShopProducts model, but when i try to go to it it says:

Class "ShopCategory" must implement a
"__toString" method to be rendered in
a "sfWidgetFormPropelChoice" widget

As you can see, the model where the names of the categories are, is ShopCategoriesDescription. So, how could i get the name of the categories from the ShopCategory model class?

Javier

sf 1.4/propel

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

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

发布评论

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

评论(1

冰葑 2024-10-13 02:52:55

这是一个标准错误,与父/子关系无关。通常,您只需向 lib/model 文件夹中的 ShopCategory.php 文件添加一个 __toString() 方法。

public function __toString()
{
    return $this->getCategoryName();
}

现在,由于您已从 shop_category 表中提取了类别名称,因此您需要创建一个函数来获取 shop_categories_description,该函数是shop_category 的子级并且是正确的区域性,以便您可以返回类别名称。

That's a standard error that has nothing to do with parent/child relationships. You normally just need to add to the ShopCategory.php file in the lib/model folder a __toString() method

public function __toString()
{
    return $this->getCategoryName();
}

Now since you've pulled out the category name from the shop_category table you need to create a function that gets the shop_categories_description that is a child of the shop_category and is the correct culture so that you have a category name to return.

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