Last active
December 24, 2015 15:29
-
-
Save selvinortiz/6821005 to your computer and use it in GitHub Desktop.
Craft:Record:getInstance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Craft; | |
class Plugin_BaseRecord extends BaseRecord | |
{ | |
public static function getInstance(BaseModel $model=null) | |
{ | |
$record = get_called_class(); | |
$record = new $record; | |
if ($model) { | |
$props = $model->getAttributes(); | |
if ($props && count($props)) { | |
foreach ($props as $prop => $value) { | |
$record->$prop = $value; | |
} | |
} | |
} | |
return $record; | |
} | |
} | |
// Elsewhere in your service layer | |
$record = Plugin_Record::getInstance($model); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment