Prado\Data\ActiveRecord\TActiveRecord::createRecord PHP Method

createRecord() public static method

If the initial data is empty, the AR object will not be created and null will be returned. (You should use the "new" operator to create the AR instance in that case.)
Since: 3.1.2
public static createRecord ( $type, $data ) : TActiveRecord
return TActiveRecord the initialized AR object. Null if the initial data is empty.
    public static function createRecord($type, $data)
    {
        if (empty($data)) {
            return null;
        }
        $record = new $type($data);
        $record->_recordState = self::STATE_LOADED;
        return $record;
    }

Usage Example

コード例 #1
0
ファイル: TMappedStatement.php プロジェクト: pradosoft/prado
 /**
  * Apply result mapping.
  * @param array a result set row retrieved from the database
  * @param object the result object, will create if necessary.
  * @return object the result filled with data, null if not filled.
  */
 protected function applyResultMap($row, &$resultObject = null)
 {
     if ($row === false) {
         return null;
     }
     $resultMapName = $this->_statement->getResultMap();
     $resultClass = $this->_statement->getResultClass();
     $obj = null;
     if ($this->getManager()->getResultMaps()->contains($resultMapName)) {
         $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject);
     } else {
         if (strlen($resultClass) > 0) {
             $obj = $this->fillResultClass($resultClass, $row, $resultObject);
         } else {
             $obj = $this->fillDefaultResultMap(null, $row, $resultObject);
         }
     }
     if (class_exists('TActiveRecord', false) && $obj instanceof TActiveRecord) {
         //Create a new clean active record.
         $obj = TActiveRecord::createRecord(get_class($obj), $obj);
     }
     return $obj;
 }
All Usage Examples Of Prado\Data\ActiveRecord\TActiveRecord::createRecord