更新时间:2023-10-04 09:36:22
这些是实现所需结果的步骤。
These are the steps to achieve the required result.
在您的generator.yml中定义一个表方法
Define a table method in your generator.yml
config:
actions: ~
fields: ~
list:
display: [news_id, title, category_name]
table_method: doSelectJoinCategory
将doSelectJoinCateory添加到您的NewsTable.class.php
Add doSelectJoinCateory to your NewsTable.class.php
class NewsTable extends Doctrine_Table
{
...
public static function doSelectJoinCategory($query)
{
return $query->select('r.*, c.cateogry_name')
->leftJoin('r.Category c');
}
}
您需要覆盖排序查询你的actions.class.php
You need to override the sort query in your actions.class.php
class newsActions extends autoNewsActions
{
...
protected function addSortQuery($query)
{
if (array(null, null) == ($sort = $this->getSort()))
{
return;
}
if (!in_array(strtolower($sort[1]), array('asc', 'desc')))
{
$sort[1] = 'asc';
}
switch ($sort[0]) {
case 'category_name':
$sort[0] = 'c.category_name';
break;
}
$query->addOrderBy($sort[0] . ' ' . $sort[1]);
}
默认生成器主题将要求您在操作中覆盖isValidSortColumn .class.php
The default generator theme will require that you override the isValidSortColumn in actions.class.php
protected function isValidSortColumn($column)
{
return Doctrine_Core::getTable(‘Payment’)->hasColumn($column) || $column == ‘cateogry_name’;
}
您需要覆盖生成器主题才能显示排序链接图标,因为它需要排序字段才是真实的数据库映射字段。编辑你的symfony_dir / lib / plugins / sfDoctrinePlugin / data / generator / sfDoctrineModule / admin / template / templates / _list_th_tabular.php:
You will need to override the generator theme to display sort link and icons as it requires the sort field to be real database mapped field. edit your symfony_dir/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/admin/template/templates/_list_th_tabular.php :
更改此行
<?php if ($field->isReal()): ?>
为此:
<?php if ($field->isReal() || $field->getConfig('sortBy')): ?>
希望能帮助你