Last active
August 29, 2015 14:05
-
-
Save mxub/0eb3f2702cb318feab37 to your computer and use it in GitHub Desktop.
First try to ease up CraftCMS Plugin Development with more generic save action
This file contains 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 SomePluginController extends BaseController | |
{ | |
// Save Form | |
public function actionSaveSomething() | |
{ | |
$this->requirePostRequest(); | |
$form = craft()->request->getPost(); | |
if ($id = craft()->request->getPost('someId')) { | |
$model = craft()->somePlugin->getSomething($id); | |
} else { | |
$model = craft()->somePlugin->newSomething(); | |
} | |
foreach($model->attributeNames as $attribute){ | |
$model->$attribute = $form[$attribute]; | |
} | |
// ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment