[eluser]goFrendiAsgard[/eluser]
What I want? a simple CRUD capability with CodeIgniter, HMVC & Doctrine
What I've tried?
I made a module inside modules directory Here is the directory structure:
application:
modules
lab
controllers
module.php
models
mod_module.php
views
Here is the codes inside mod_module.php
Code:
namespace lab\models;
/**
* @Entity @Table(name="mod_module")
*/
class Mod_module{
/**
* @Id @Column(type="integer") @GeneratedValue
*/
private $id;
/**
* @Column(type="string", length=50, nullable=false)
*/
private $menu;
/**
* @Column(type="string", length=50, nullable=false)
*/
private $module;
public function id($value=NULL)
{
return is_null($value) ? ($this->id) : ($this->id = $value);
}
public function menu($value=NULL)
{
return is_null($value) ? ($this->menu) : ($this->menu = $value);
}
public function module($value=NULL)
{
return is_null($value) ? ($this->module) : ($this->module = $value);
}
}
?>
I can edit some record by performing this :
Code:
$module = $this->doctrine->em->find('lab\models\mod_module', $key);
$module->menu($menuValue);
$module->module($moduleValue);
$this->doctrine->em->persist($module);
$key contains the id of a specific record in mod_module table. $menuValue and $moduleValue are the new values of the respective fields.
It worked as expected,
But whenever I perform remove, it is always failed
Code:
$module = $this->doctrine->em->find('lab\models\mod_module', $key);
if($module){
$this->doctrine->em->remove($module);
$this->doctrine->em->flush();
}
The record doesn't deleted, I've check the variables value via var_dump, and I think nothing wrong.
Another thing, if I use DQL instead of "remove" and "flush", it will work as expected, th record deleted.....
Code:
$dql = "DELETE
FROM lab\models\mod_module tb
WHERE tb.id = ?1";
$this->doctrine->em->createQuery($dql)
->setParameter(1, $key)
->execute();
What I expect? Not much, I want that "remove" and "flush" worked,.... I can use DQL, but I think "remove" and "flush" make my codes easier to read,.....
Thank you in advance, ~goFrendiAsgard