POST method for handling custom model item actions.

@param string $modelName
@param int    $id

@return JSON
7363
public function customModelItemAction($modelName, $id = null)
    {
        $config        = app('itemconfig');
        $actionFactory = app('admin_action_factory');
        $model         = $config->getDataModel();
        $model         = $model::find($id);
        $actionName    = $this->request->input('action_name', false);

        //get the action and perform the custom action
        $action = $actionFactory->getByName($actionName);
        $result = $action->perform($model);

        //override the config options so that we can get the latest
        app('admin_config_factory')->updateConfigOptions();

        //if the result is a string, return that as an error.
        if (is_string($result)) {
            return response()->json(array('success' => false, 'error' => $result));
        }
        //if it's falsy, return the standard error message
        elseif (!$result) {
            $messages = $action->getOption('messages');

            return response()->json(array('success' => false, 'error' => $messages['error']));
        } else {
            $fieldFactory  = app('admin_field_factory');
            $columnFactory = app('admin_column_factory');
            $fields        = $fieldFactory->getEditFields();
            $model         = $config->getModel($id, $fields, $columnFactory->getIncludedColumns($fields));

            if ($model->exists) {
                $model = $config->updateModel($model, $fieldFactory, $actionFactory);
            }

            $response = array('success' => true, 'data' => $model->toArray());

            //if it's a download response, flash the response to the session and return the download link
            if (is_a($result, 'Symfony\Component\HttpFoundation\BinaryFileResponse')) {
                $file    = $result->getFile()->getRealPath();
                $headers = $result->headers->all();
                $this->session->put('administrator_download_response', array('file' => $file, 'headers' => $headers));

                $response['download'] = route('admin_file_download');
            }
            //if it's a redirect, put the url into the redirect key so that javascript can transfer the user
            elseif (is_a($result, '\Illuminate\Http\RedirectResponse')) {
                $response['redirect'] = $result->getTargetUrl();
            }

            return response()->json($response);
        }
    }
413144
public function putAction(Request $request, $id)
    {
        $jsonData = $request->getContent();
        $data = json_decode($jsonData, true);

        // Id should be taken of request uri.
        $data['id'] = $id;

        $targetGroup = $this->deserializeData(json_encode($data));
        $targetGroup = $this->getTargetGroupRepository()->save($targetGroup);
        $this->getEntityManager()->flush();

        return $this->handleView($this->view($targetGroup));
    }
952750
public function getById($id)
    {
        $modelResult = $this->getRequest()->request(
            'GET',
            $this->getRequestUrl(sprintf('models/%s', $id))
        );

        return $this->getModelFromResult($modelResult);
    }
433567
public function results($modelName)
    {
        $dataTable = app('admin_datatable');

        //get the sort options and filters
        $page        = $this->request->input('page', 1);
        $sortOptions = $this->request->input('sortOptions', array());
        $filters     = $this->request->input('filters', array());

        //return the rows
        return response()->json($dataTable->getRows(app('db'), $filters, $page, $sortOptions));
    }
1159164
public function viewAction(Request $request, $id)
    {
        $manager = $this->get('opifer.content.content_manager');
        $content = $manager->getRepository()->find($id);

        $content = $this->get('jms_serializer')->serialize($content, 'json');

        return new Response($content, 200, ['Content-Type' => 'application/json']);
    }
842431
public function jsonAction(Request $request, $managerName)
    {
        $data = $this->get(ONGRFilterManagerExtension::getFilterManagerId($managerName))
            ->handleRequest($request)
            ->getSerializableData();

        $response = new JsonResponse($data);

        if ($request->query->has('pretty')) {
            $response->setEncodingOptions(JSON_PRETTY_PRINT);
        }

        return $response;
    }
1241762
public function run($id, $name)
    {
        /** @var \bariew\postAbstractModule\models\Item $model */
        $model = $this->controller->findModel($id);
        if ($model->deleteFile($name)) {
            Yii::$app->session->setFlash('success', Yii::t('app', 'File successfully deleted'));
        } else {
            Yii::$app->session->setFlash('error', Yii::t('app', 'File delete error'));
        }
        return $this->controller->redirect(Yii::$app->request->referrer);
    }
392097
public function edit($id)
    {
        // Get the model instance
        $item = $this->findOrFail($id);

        // Respond to AJAX requests for a single item with JSON
        if (Request::ajax()) {
            return Response::json($item);
        }

        // Look for overriden views
        $this->overrideViews();

        // Populate form
        Former::populate($item);
        Former::withRules($this->getRules());

        // Initialize localization
        with($localize = new Localize)
            ->item($item)
            ->title(Str::singular($this->title));

        // Make the sidebar
        $sidebar = new Sidebar($item);
        if (!$localize->hidden()) {
            $sidebar->addToEnd($localize);
        }

        // Render view
        return $this->populateView($this->show_view, [
            'item' => $item,
            'localize' => $localize,
            'sidebar' => $sidebar,
            'parent_id' => $this->parent ? $this->parent->getKey() : null,
        ]);
    }
714208
public function get($id)
	{
		$this->getResponse()
			->setStatusCode(Response::STATUS_CODE_200);
		
		$data = $this->getModel()->get($id, $this->getServiceLocator());
		
		return $data;
		
		return new JsonModel(array(
			'data' => $data
		));
	}
1059562
public function actionAssign($id)
    {
        $items = Yii::$app->getRequest()->post('items', []);
        $model = $this->findModel($id);
        $success = $model->addChildren($items);
        Yii::$app->getResponse()->format = 'json';

        return array_merge($model->getItems(), ['success' => $success]);
    }
1059639
public function actionCustomUpdate($id = '')
    {
        $model = Options::findOne(['id' => $id]);
        if (yii::$app->getRequest()->getIsPost()) {
            if ($model->load(yii::$app->getRequest()->post()) && $model->save()) {
                yii::$app->getSession()->setFlash('success', yii::t('cms', 'Success'));
                return $this->redirect(['custom']);
            } else {
                $errors = $model->getErrors();
                $err = '';
                foreach ($errors as $v) {
                    $err .= $v[0] . '<br>';
                }
                yii::$app->getResponse()->format = Response::FORMAT_JSON;
                return [
                    'err_msg' => $err,
                ];
            }
        } else {
            yii::$app->getResponse()->format = Response::FORMAT_HTML;
            echo '<div class="" id="editForm">';
            echo '<div class="ibox-content">';
            $form = ActiveForm::begin(['options' => ['name' => 'edit']]);
            echo $form->field($model, 'name')->textInput();
            echo $form->field($model, 'input_type')->dropDownList(Constants::getInputTypeItems());
            echo $form->field($model, 'tips')->textInput();
            echo $form->field($model, 'autoload')->dropDownList(Constants::getYesNoItems());
            echo $form->field($model, 'value')->textInput();
            echo $form->field($model, 'sort')->textInput();
            echo $form->defaultButtons();
            ActiveForm::end();
            echo '</div>';
            echo '</div>';
        }
    }
212931
public function actionClick($id) 
	{
		$model=$this->loadModel($id);
		if($id == null || $model == null)
			$this->redirect(Yii::app()->createUrl('site/index'));
		else {
			BannerClicks::insertClick($model->banner_id);
			$this->redirect($model->url);
		}
	}
1070516
public function show($id)
    {
        $parameters = $this->request->getParameters();
        $model = $this->repository->getItem($id, $parameters);
        return $this->modelResponse($model);
    }
1144930
public function fromField(Request $request, ModelConfigurationInterface $model, $field, $id = null)
    {
        if (! is_null($id)) {
            $item = $model->getRepository()->find($id);
            if (is_null($item) || ! $model->isEditable($item)) {
                return new JsonResponse([
                    'message' => trans('lang.message.access_denied'),
                ], 403);
            }

            $form = $model->fireEdit($id);
        } else {
            if (! $model->isCreatable()) {
                return new JsonResponse([
                    'message' => trans('lang.message.access_denied'),
                ], 403);
            }

            $form = $model->fireCreate();
        }

        /** @var File $element */
        if (is_null($element = $form->getElement($field))) {
            throw new NotFoundHttpException("Field [{$field}] not found");
        }

        $rules = $element->getUploadValidationRules();
        $messages = $element->getUploadValidationMessages();
        $labels = $element->getUploadValidationLabels();

        /** @var \Illuminate\Contracts\Validation\Validator $validator */
        $validator = Validator::make($request->all(), $rules, $messages, $labels);

        $element->customValidation($validator);

        if ($validator->fails()) {
            return new JsonResponse([
                'message' => trans('lang.message.validation_error'),
                'errors'  => $validator->errors()->get('file'),
            ], 400);
        }

        $file = $request->file('file');

        $filename = $element->getUploadFileName($file);
        $path = $element->getUploadPath($file);
        $settings = $element->getUploadSettings();

        $result = $element->saveFile($file, $path, $filename, $settings);

        /* When driver not file */
        return new JsonResponse($result);
    }
1244788
public function actionView($id)
    {
        $model = $this->findModel($id);

        return $this->render('view', ['model' => $model, 'items' => $this->getItems($id)]);
    }
1283684
public function save($modelName, $id = null)
    {
        // Custom page_type
        $this->request->merge([
            'pagetype' => ".blade.php",
        ]);

        return parent::save($modelName, $id);
    }
277382
public function actionAssign($id)
    {
        $items = Yii::$app->getRequest()->post('items', []);
        $model = new Assignment($id);
        $success = $model->assign($items);
        Yii::$app->getResponse()->format = 'json';
        return array_merge($model->getItems(), ['success' => $success]);
    }