本文整理汇总了PHP中sfLoader::getModelDirs方法的典型用法代码示例。如果您正苦于以下问题:PHP sfLoader::getModelDirs方法的具体用法?PHP sfLoader::getModelDirs怎么用?PHP sfLoader::getModelDirs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfLoader
的用法示例。
在下文中一共展示了sfLoader::getModelDirs方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMapBuilderClasses
/**
* Loads map builder classes.
*
* This method is ORM dependant.
*
* @throws sfException
*/
protected function loadMapBuilderClasses()
{
// we must load all map builder classes to be able to deal with foreign keys (cf. editSuccess.php template)
$classes = sfFinder::type('file')->ignore_version_control()->name('*MapBuilder.php')->in(sfLoader::getModelDirs());
foreach ($classes as $class)
{
$class_map_builder = basename($class, '.php');
$maps[$class_map_builder] = new $class_map_builder();
if (!$maps[$class_map_builder]->isBuilt())
{
$maps[$class_map_builder]->doBuild();
}
if ($this->className == str_replace('MapBuilder', '', $class_map_builder))
{
$this->map = $maps[$class_map_builder];
}
}
if (!$this->map)
{
throw new sfException('The model class "'.$this->className.'" does not exist.');
}
$this->tableMap = $this->map->getDatabaseMap()->getTable(constant($this->className.'Peer::TABLE_NAME'));
}
示例2: getRelatedClass
public static function getRelatedClass($class, $middleClass)
{
$column = self::getRelatedColumn($class, $middleClass);
// we must load all map builder classes
$classes = sfFinder::type('file')->ignore_version_control()->name('*MapBuilder.php')->in(sfLoader::getModelDirs());
foreach ($classes as $class) {
$class_map_builder = basename($class, '.php');
$map = new $class_map_builder();
$map->doBuild();
}
$tableMap = call_user_func(array($middleClass . 'Peer', 'getTableMap'));
return $tableMap->getDatabaseMap()->getTable($column->getRelatedTableName())->getPhpName();
}
示例3: dumpData
/**
* Dumps data to fixture from one or more tables.
*
* @param string directory or file to dump to
* @param mixed name or names of tables to dump (or all to dump all tables)
* @param string connection name
*/
public function dumpData($directory_or_file = null, $tables = 'all', $connectionName = 'propel')
{
$sameFile = true;
if (is_dir($directory_or_file)) {
// multi files
$sameFile = false;
} else {
// same file
// delete file
}
$this->con = Propel::getConnection($connectionName);
// get tables
if ('all' === $tables || is_null($tables)) {
// load all map builder classes
$files = sfFinder::type('file')->ignore_version_control()->name('*MapBuilder.php')->in(sfLoader::getModelDirs());
foreach ($files as $file) {
$mapBuilderClass = basename($file, '.php');
$map = new $mapBuilderClass();
$map->doBuild();
}
$dbMap = Propel::getDatabaseMap($connectionName);
$tables = array();
foreach ($dbMap->getTables() as $table) {
$tables[] = $table->getPhpName();
}
} else {
if (!is_array($tables)) {
$tables = array($tables);
}
}
$dumpData = array();
// load map classes
array_walk($tables, array($this, 'loadMapBuilder'));
//$tables = $this->fixOrderingOfForeignKeyData($tables);
foreach ($tables as $tableName) {
$tableMap = $this->maps[$tableName]->getDatabaseMap()->getTable(constant($tableName . 'Peer::TABLE_NAME'));
$hasParent = false;
$haveParents = false;
$fixColumn = null;
foreach ($tableMap->getColumns() as $column) {
$col = strtolower($column->getColumnName());
if ($column->isForeignKey()) {
$relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName());
if ($tableName === $relatedTable->getPhpName()) {
if ($hasParent) {
$haveParents = true;
} else {
$fixColumn = $column;
$hasParent = true;
}
}
}
}
if ($haveParents) {
// unable to dump tables having multi-recursive references
continue;
}
// get db info
$resultsSets = array();
if ($hasParent) {
$resultsSets = $this->fixOrderingOfForeignKeyDataInSameTable($resultsSets, $tableName, $fixColumn);
} else {
$resultsSets[] = $this->con->executeQuery('SELECT * FROM ' . constant($tableName . 'Peer::TABLE_NAME'));
}
foreach ($resultsSets as $rs) {
if ($rs->getRecordCount() > 0 && !isset($dumpData[$tableName])) {
$dumpData[$tableName] = array();
}
while ($rs->next()) {
$pk = $tableName;
$values = array();
$primaryKeys = array();
$foreignKeys = array();
foreach ($tableMap->getColumns() as $column) {
$col = strtolower($column->getColumnName());
$isPrimaryKey = $column->isPrimaryKey();
if (is_null($rs->get($col))) {
continue;
}
if ($isPrimaryKey) {
$value = $rs->get($col);
$pk .= '_' . $value;
$primaryKeys[$col] = $value;
}
if ($column->isForeignKey()) {
$relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName());
if ($isPrimaryKey) {
$foreignKeys[$col] = $rs->get($col);
$primaryKeys[$col] = $relatedTable->getPhpName() . '_' . $rs->get($col);
} else {
$values[$col] = $relatedTable->getPhpName() . '_' . $rs->get($col);
}
} elseif (!$isPrimaryKey || $isPrimaryKey && !$tableMap->isUseIdGenerator()) {
//.........这里部分代码省略.........
示例4: dumpData
/**
* Dumps data to fixture from one or more tables.
*
* @param string directory or file to dump to
* @param mixed name or names of tables to dump (or all to dump all tables)
* @param string connection name
*/
public function dumpData($directory_or_file = null, $tables = 'all', $connectionName = 'propel')
{
$sameFile = true;
if (is_dir($directory_or_file)) {
// multi files
$sameFile = false;
} else {
// same file
// delete file
}
$this->con = Propel::getConnection($connectionName);
// get tables
if ('all' === $tables || is_null($tables)) {
// load all map builder classes
$files = sfFinder::type('file')->name('*MapBuilder.php')->in(sfLoader::getModelDirs());
foreach ($files as $file) {
$mapBuilderClass = basename($file, '.php');
$map = new $mapBuilderClass();
$map->doBuild();
}
$dbMap = Propel::getDatabaseMap($connectionName);
$tables = array();
foreach ($dbMap->getTables() as $table) {
$tables[] = $table->getPhpName();
}
} else {
if (!is_array($tables)) {
$tables = array($tables);
}
}
$dumpData = array();
// load map classes
array_walk($tables, array($this, 'loadMapBuilder'));
$tables = $this->fixOrderingOfForeignKeyData($tables);
foreach ($tables as $tableName) {
$tableMap = $this->maps[$tableName]->getDatabaseMap()->getTable(constant($tableName . 'Peer::TABLE_NAME'));
// get db info
$rs = $this->con->executeQuery('SELECT * FROM ' . constant($tableName . 'Peer::TABLE_NAME'));
while ($rs->next()) {
$pk = $tableName;
$values = array();
foreach ($tableMap->getColumns() as $column) {
$col = strtolower($column->getColumnName());
if ($column->isPrimaryKey()) {
$pk .= '_' . $rs->get($col);
} else {
if ($column->isForeignKey()) {
$relatedTable = $this->maps[$tableName]->getDatabaseMap()->getTable($column->getRelatedTableName());
$values[$col] = $relatedTable->getPhpName() . '_' . $rs->get($col);
} else {
$values[$col] = $rs->get($col);
}
}
}
if (!isset($dumpData[$tableName])) {
$dumpData[$tableName] = array();
}
$dumpData[$tableName][$pk] = $values;
}
}
// save to file(s)
if ($sameFile) {
file_put_contents($directory_or_file, Spyc::YAMLDump($dumpData));
} else {
$i = 0;
foreach ($tables as $tableName) {
if (!isset($dumpData[$tableName])) {
continue;
}
file_put_contents(sprintf("%s/%03d-%s.yml", $directory_or_file, ++$i, $tableName), Spyc::YAMLDump(array($tableName => $dumpData[$tableName])));
}
}
}