/**
  * Prepare execute hook.
  *
  * @throws \UnexpectedValueException
  * @return void
  */
 protected function prepareExecute()
 {
     parent::prepareExecute();
     $this->user = $this->container->get('user');
     $this->lang = $this->container->get('language');
     $this->model = $this->getModel($this->viewItem);
     $this->table = $this->model->getTable($this->viewItem, $this->prefix . 'Table');
     // Determine model
     if (!$this->model instanceof CrudModel) {
         throw new \UnexpectedValueException(sprintf('%s model need extend to CrudModel', $this->name));
     }
     // Determine the name of the primary key for the data.
     if (empty($this->key)) {
         $this->key = $this->table->getKeyName();
     }
     // To avoid data collisions the urlVar may be different from the primary key.
     if (empty($this->urlVar)) {
         $this->urlVar = $this->key;
     }
 }
Example #2
0
 /**
  * Method to get a model object, loading it if required.
  *
  * @param   string  $name     The model name. Optional.
  * @param   string  $prefix   The class prefix. Optional.
  * @param   array   $config   Configuration array for model. Optional.
  * @param   boolean $forceNew Force get new model, or we get it from cache.
  *
  * @return  object  The model.
  */
 public function getModel($name = null, $prefix = null, $config = array(), $forceNew = false)
 {
     return parent::getModel($name, $prefix, array('ignore_request' => true), $forceNew);
 }