Beispiel #1
0
 /**
  * Returns a named Model object
  *
  * @param   string $name     The Model name. If null we'll use the modelName
  *                           variable or, if it's empty, the same name as
  *                           the Controller
  * @param   array  $config   Configuration parameters to the Model. If skipped
  *                           we will use $this->config
  *
  * @return  Model  The instance of the Model known to this Controller
  */
 public function getModel($name = null, $config = array())
 {
     if (!empty($name)) {
         $modelName = strtolower($name);
     } elseif (!empty($this->defaultModel)) {
         $modelName = strtolower($this->defaultModel);
     } else {
         $modelName = strtolower($this->name);
     }
     if (!array_key_exists($modelName, $this->modelInstances)) {
         $appName = $this->container->application->getName();
         if (empty($config)) {
             $config = $this->config;
         }
         $this->container['mvc_config'] = $config;
         $this->modelInstances[$modelName] = Model::getInstance($appName, $modelName, $this->container);
     }
     return $this->modelInstances[$modelName];
 }
Beispiel #2
0
 /**
  * Returns a named Model object
  *
  * @param   string $name     The Model name. If null we'll use the modelName
  *                           variable or, if it's empty, the same name as
  *                           the Controller
  * @param   array  $config   Configuration parameters to the Model. If skipped
  *                           we will use $this->config
  *
  * @return  Model  The instance of the Model known to this Controller
  */
 public function getModel($name = null, $config = array())
 {
     if (!empty($name)) {
         $modelName = strtolower($name);
     } elseif (!empty($this->modelName)) {
         $modelName = strtolower($this->modelName);
     } else {
         $modelName = strtolower($this->view);
     }
     if (!array_key_exists($modelName, $this->modelInstances)) {
         $appName = $this->container->application->getName();
         if (empty($config)) {
             $config = $this->config;
         }
         if (empty($name)) {
             $config['modelTemporaryInstance'] = true;
         } else {
             // Other classes are loaded with persistent state disabled and their state/input blanked out
             $config['modelTemporaryInstance'] = false;
             $config['modelClearState'] = true;
             $config['modelClearInput'] = true;
         }
         $this->container['mvc_config'] = $config;
         $this->modelInstances[$modelName] = Model::getInstance($appName, $modelName, $this->container);
     }
     return $this->modelInstances[$modelName];
 }