Commits

Denis Medved committed dd60b21

fix issues #6. And Formating code.

Comments (0)

Files changed (1)

gii/fixture/FixtureCode.php

 		$this->scandir($path);
 		$templatePath = Yii::getPathOfAlias('application.gii.fixture.templates.default');
 		$tableNames = array();
-		foreach ($this->_models as $modelName){
+		foreach ($this->_models as $modelName)
+		{
 			$class     = pathinfo($modelName,PATHINFO_FILENAME);
 			$obj       = new $class;
-			if($obj instanceof CActiveRecord){
-				$tableName    = $obj->tableName();
-				$writeTo = Yii::getPathOfAlias($this->fixturePath).DIRECTORY_SEPARATOR.$obj->tableName().'.php';
-				if(!in_array($tableName, $tableNames) && !file_exists($writeTo)){
+			if ($obj instanceof CActiveRecord)
+			{
+				//fix issues #6 reported by "oceatoon"
+				$prefix = $obj->getDbConnection()->tablePrefix;
+				$tableName = str_replace(array('{{','}}'), array($prefix,''),$obj->tableName());
+				$writeTo = Yii::getPathOfAlias($this->fixturePath).DIRECTORY_SEPARATOR.$tableName.'.php';
+				if (!in_array($tableName, $tableNames) && !file_exists($writeTo))
+				{
 					$tableNames[] = $tableName;
-					if(!empty($this->rowsLimit)){
+					if (!empty($this->rowsLimit))
+					{
 						$criteria        = new CDbCriteria();
 						$criteria->limit = intval($this->rowsLimit);
 						
 						$models = $class::model()->findAll($criteria);
-					}else
+					} else
 						$models = $class::model()->findAll();
-					if(isset($models))
-						$this->files[] = new CCodeFile(
-								$writeTo,
-								$this->render($templatePath . DIRECTORY_SEPARATOR . 'fixture.php', array('models' => $models))
-							);
+					
+					$this->files[] = new CCodeFile(
+							$writeTo,
+							$this->render($templatePath . DIRECTORY_SEPARATOR . 'fixture.php', array('models' => $models))
+						);
 				}
 			}
 		}
 	 */
 	protected function scanDir($path){
 		foreach (scandir($path) as $file)
-			if('.' !== $file && '..' !== $file)
-				if(is_file($filename = $path . DIRECTORY_SEPARATOR . $file) && 'php' === pathinfo($file,PATHINFO_EXTENSION))
+			if ('.' !== $file && '..' !== $file)
+				if (is_file($filename = $path . DIRECTORY_SEPARATOR . $file) && 'php' === pathinfo($file,PATHINFO_EXTENSION))
 					$this->_models[] = $file;
-				else if(is_dir($filename)){
+				else if (is_dir($filename))
+				{
 					Yii::import($this->modelPath . '.' . $file . '.*');
 					$this->scanDir($filename);
 				}