Created
December 30, 2016 09:11
-
-
Save mohsin/26475c87e0dd1a5761d57d0e4a0f20a9 to your computer and use it in GitHub Desktop.
The Controller
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 Mohsin\Mobile\Controllers; | |
use Cookie; | |
use BackendMenu; | |
use Backend\Classes\Controller; | |
use Mohsin\Mobile\Models\Variant; | |
/** | |
* Installs Back-end Controller | |
*/ | |
class Installs extends Controller | |
{ | |
public $implement = [ | |
'Backend.Behaviors.FormController', | |
'Backend.Behaviors.ListController' | |
]; | |
public $formConfig = 'config_form.yaml'; | |
public $listConfig = 'config_list.yaml'; | |
protected $variant_id; | |
public function __construct() | |
{ | |
parent::__construct(); | |
BackendMenu::setContext('Mohsin.Mobile', 'mobile', 'installs'); | |
$this -> variant_id = Cookie::get('variant_id', 1); | |
$this->prepareVars(); | |
} | |
/** | |
* Prepares the list data | |
*/ | |
public function prepareVars() | |
{ | |
$this->vars['variants'] = Variant::lists('description','id'); | |
$this->vars['variant_id'] = $this -> variant_id; | |
$this->vars['variant_name'] = $this->vars['variants'][$this -> variant_id]; | |
} | |
public function listExtendQuery($query) | |
{ | |
$query->withVariant($this -> variant_id); | |
} | |
public function onVariantChange() | |
{ | |
$this -> variant_id = post('index'); | |
Cookie::queue('variant_id', $this -> variant_id, 120); | |
return $this->listRefresh(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment