我知道它可能會使用戶在前端的管理generator.yml稍微奇怪,但每個頁面是一個列表或編輯頁面,它絕對是最簡單的事情。symfony sfDoctrineGuardPlugin generator.yml過濾user_id
在努力編寫日誌模塊之後,我安裝了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 }
一旦插件正常工作,我打算從上面的表中刪除密碼,並使用默認的密碼,並強制大家做出新的通行證。
編輯:
感謝本我有模板工作我認爲。無論如何,它都會添加到數據庫中。
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()
);
}
}
}
該監聽器的代碼是刪除了時間表和布爾檢查的軟刪除代碼。該行不會出現在開發欄中。
謝謝本。我已經添加了我寫給帖子的代碼。儘管模板接縫正在工作,並且正確地將該列添加到數據庫,但偵聽器不會。 – Kye 2010-09-12 15:06:26
請參閱編輯reql_callbacks。 – benlumley 2010-09-13 07:28:32
非常感謝Ben。沒有你的幫助,我對symfony一無所知。 – Kye 2010-09-13 08:16:08