Example #1
0
 /**
  * Constructor
  *
  */
 public function __construct($dataObject = null)
 {
     $this->logger = new Logger(get_class($this));
     //Los models
     if (isset($this->defaultUses)) {
         foreach ($this->defaultUses as $model) {
             $varName = $model;
             $varName[0] = strtolower($varName[0]);
             $this->{$varName} = ModelFactory::getModel($model);
         }
     }
     if (isset($this->uses)) {
         foreach ($this->uses as $model) {
             $varName = $model;
             $varName[0] = strtolower($varName[0]);
             $this->{$varName} = ModelFactory::getModel($model);
         }
     }
     if ($dataObject == null) {
         $dataObject = str_replace('Model', "", get_class($this));
         $this->dataObject = $dataObject;
     } else {
         if ($dataObject != "") {
             $this->dataObject = $dataObject;
         }
     }
 }
    /**
     * This is the default 'index' action that is invoked
     * when an action is not explicitly requested by users.
     */
    public function actionIndex()
    {

        $i = 0;
        //check last category segment
        while (isset($_GET['cat' . ++$i])) {}

        $alias = isset($_GET['cat' . --$i]) ? $_GET['cat' . $i] : 'index';

        //find category by alias
        $this->category = Category::model()->published()->findByAttributes(array('alias' => $alias));

        if ($this->category == NULL) {
            //if $alias is no category alias, may be it's model alias and $prev_alias it's category alias
            $prev_alias = isset($_GET['cat' . --$i]) ? $_GET['cat' . $i] : false;

            if ($prev_alias == false)
                $this->redirect('/errors/not_found');
            
            $this->category = Category::model()->published()->findByAttributes(array('alias' => $prev_alias));

            if ($this->category == NULL)
                $this->redirect('/errors/not_found');

            $_GET['alias'] = $alias;
        }

        $this->model = ModelFactory::getModel($this->category);

        if ($this->model == NULL)
            $this->redirect('/errors/not_found');

        //see parent render function
        $this->render('index');

        //simple speed demonstration :-)
        echo Y::stats();
    }
Example #3
0
 /**
  * 
  * @param $db
  * @return model array of the table
  */
 public function getAll($db = null)
 {
     $this->check_db_die($db, __METHOD__);
     $rows = $this->_db->fetchAll("SELECT * FROM {$this->table_name}");
     $ret = array();
     foreach ($rows as $k => $row) {
         $m = ModelFactory::getModel($this->class_name, $db);
         $m->setDbrow($row);
         $ret[] = $m;
     }
     return $ret;
 }
Example #4
0
 /**
  * Contructor initializes $viewBaseDir and loads all Helpers and
  * models.
  * Then it initializes i18n support.
  */
 public function __construct()
 {
     $this->viewBaseDir = CLASSPATH . "/views/";
     //Los models
     if (isset($this->defaultUses)) {
         foreach ($this->defaultUses as $model) {
             $varName = $model;
             $varName[0] = strtolower($varName[0]);
             $this->{$varName} = ModelFactory::getModel($model);
         }
     }
     if (isset($this->uses)) {
         foreach ($this->uses as $model) {
             $varName = $model;
             $varName[0] = strtolower($varName[0]);
             $this->{$varName} = ModelFactory::getModel($model);
         }
     }
     //Los helpers
     if (isset($this->defaultHelpers)) {
         foreach ($this->defaultHelpers as $helper) {
             $varName = $helper;
             $varName[0] = strtolower($varName[0]);
             $this->{$varName} = HelperFactory::getHelper($helper);
             $this->{$varName}->startUp($this);
         }
     }
     if (isset($this->helpers)) {
         foreach ($this->helpers as $helper) {
             $varName = $helper;
             $varName[0] = strtolower($varName[0]);
             $this->{$varName} = HelperFactory::getHelper($helper);
             $this->{$varName}->startUp($this);
         }
     }
     //i18n
     $i18nFileName = strtolower(str_replace("Controller", "", get_class($this))) . '.' . $this->viewLocale . '.po';
     I18nHelper::getInstance()->loadPoFile(I18N_PATH . '/' . $i18nFileName);
 }