Skip to content

Instantly share code, notes, and snippets.

@maxxst
Last active August 29, 2015 14:05
Show Gist options
  • Save maxxst/0eb3f2702cb318feab37 to your computer and use it in GitHub Desktop.
Save maxxst/0eb3f2702cb318feab37 to your computer and use it in GitHub Desktop.
First try to ease up CraftCMS Plugin Development with more generic save action
<?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