开发者

symfony 1.4: question about accessing a child class from a parent class

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, re开发者_如何学Goquired: 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜