我在ModelTable
内部,需要Model
名称。例如:在EventTable
的情况下,我需要知道它实例化的模型——Event
。
在内部,以下函数已经实例化了正确的Model
:
class EventTable extends Doctrine_Table
{
public function findBySomething($something)
{
// Will return a Event
return $this->createQuery('s')->fetchOne();
}
}
我想做的事:
class EventTable extends Doctrine_Table
{
public function findBySomething($something)
{
$modelName = $this->getModelName();
echo "I will create a ".$modelName; // Will display Event
return $this->createQuery('s')->fetchOne();
}
}
如何从表中检索模型名称?
每个表(Doctrine/Table.php)都有一系列可用选项:
protected $_options = array(
'name' => null,
'tableName' => null,
'sequenceName' => null,
'inheritanceMap' => array(),
'enumMap' => array(),
'type' => null,
'charset' => null,
'collate' => null,
'treeImpl' => null,
'treeOptions' => array(),
'indexes' => array(),
'parents' => array(),
'joinedParents' => array(),
'queryParts' => array(),
'versioning' => null,
'subclasses' => array(),
);
因此,您可以使用检索型号名称
$this->getOption('name');