【发布时间】:2010-09-10 14:18:03
【问题描述】:
我知道在前端使用 admin generator.yml 可能有点奇怪,但每个页面都是列表或编辑页面,这绝对是最简单的事情。
在努力编写登录模块后,我安装了 sfDoctrineGuardPlugin 并使用关系将它们链接到我的主用户表。数据库中的所有内容都依赖于这张表,并且数据已经在当前的活动站点上建立了 8 个月多一点,我需要保留它。
我目前的问题是,一旦有人登录并将 ID 存储在警卫系统中,我需要所有页面来过滤所有结果,包括列表和编辑。
有没有一种简单的方法可以做到这一点,还是我需要为每个列表使用 table_method?
上述唯一的问题是 ID 出现在地址中,我需要它来确保人们无法查看不应该查看的数据。
另外,这可能很快就会改变,目前表是 MyISAM 以使用更好的自动增量,可以让它由用户增量,这样每个人都从一个开始。但是它似乎不做外键,所以当我编写代码将其转换为 INNOBDB 时,地址中的 ID 变得更加重要,因为人们无法更改。
Owner:
columns:
id: { type: integer(4), primary: true, autoincrement: true }
slname: { type: string(64), notnull: true }
uuid: { type: string(36), notnull: true }
e_mail: { type: string(64) }
user: { type: string(16) }
pass: { type: string(40), notnull: true }
subscription: { type: integer(4), default: '0', notnull: true }
registered: { type: integer(1), default: '0', notnull: true }
relations:
Subscription: { local: subscription, foreign: id }
User: { class: sfGuardUser, foreign: id, local: id, type: one, onDelete: cascade, foreignType: one, foreignAlias: Owner }
一旦插件正常工作,我计划从上表中删除密码并使用默认密码并强制每个人进行新的通行证。
编辑:
感谢 Ben,我认为模板可以正常工作。无论如何它都会在列中添加到数据库中。
class Doctrine_Template_Owned extends Doctrine_Template
{
protected $_options = array(
'name' => 'owner_id',
'type' => 'integer',
'length' => 11,
'options' => array(
'default' => 0,
'notnull' => true
)
);
public function setTableDefinition()
{
$this->hasColumn($this->_options['name'], $this->_options['type'], $this->_options['length'], $this->_options['options']);
$this->addListener(new Doctrine_Template_Listener_Owned($this->_options));
}
}
但是听者似乎不会被调用。
class Doctrine_Template_Listener_Owned extends Doctrine_Record_Listener
{
protected $_options = array();
public function __construct(array $options)
{
$this->_options = $options;
}
public function preDqlSelect(Doctrine_Event $event)
{
$params = $event->getParams();
$field = $params['alias'] . '.' . $this->_options['name'];
$query = $event->getQuery();
if (( ! $query->isSubquery() || ($query->isSubquery() && $query->contains(' ' . $params['alias'] . ' '))) && ! $query->contains($field)) {
$query->addPendingJoinCondition(
$params['alias'], $field . ' = ' . sfContext::getInstance()->getUser()->getGuardUser()->getId()
);
}
}
}
监听器的代码是删除时间表和布尔检查的软删除代码。不过,这条线并没有出现在开发栏中。
【问题讨论】: