Doctrine Behavior / Templates: Is there a way overwrite or load data into the invoking Doctrine_Record from a Doctrine_Template?
Hy!
I'm new to the Doctrine library. I'm trying to take advantage of the Doctrine Behavior (Templating) system to build a Authenticable behavior but I ran into a few problems.
This is how i wanted to declare it:
class BaseAdminUser extends Doctrine_Record{
public function setTableDefinition(){
// ...
}
public function setUp(){
// ...
$this->actAs(new Doctrine_Template_Authenticatable());
}
}
This is how i wanted to use it:
In my admin bootstrap file:
// ...
$admin = new AdminUser();
if(!$admin->login_check()){
redirect("login.php");
}else{
// $admin->id is available
}
In my admin login.php page:
// ...
if($data = $_POST){
$admin->login($data);
}
I wanted my template to use Native PHP Sessions (using $_SESSION
) to do the following:
- upon login set a session and save the record
Doctrine_Core::HYDRATE_ARRAY
in it - upon instantiation of Record and Template check if the session data exists and load the invoking Record with the id from the session
One approach i tried was to re-route the $invoker. That doesn't work.
class Doctrine_Template_Authenticatable extends Doctrine_Template{ // ... public function setUp(){ // ... if(isset($session_data['id'])){ $invoker = &$this->getInvoker(); $invoker = $this->getTable()->find($session_data['id']); } } // ... }
I've looked trough the Doctrine_Record API Documentation and i could not find a function which would load (hydrate) a different table row into a object based on id or otherwise.
There'sfromArray($arr)
and hydrate($arr, $overwrite)
:
Doctrine_Record::fromArray(string array, bool deep))
Doctrine_Record::hydrate(array data, boolean overwriteLocalChanges)
But that is fake and would just load the data without the id.
$this->getInvoker()->hydrate($session_data);
// (...)
echo $admin->id; // empty
$this->getInvoker()->fromArra开发者_高级运维y($session_data);
// Uncaught exception 'Doctrine_Table_Exception' with message 'Unknown relation alias id'
My question is:
Is there a way overwrite or load data into the invokingDoctrine_Record
from a Doctrine_Template
?
精彩评论