/** Construct */
 public function __construct($module)
 {
     $this->response = new aregistry();
     $this->_in_ajax = loader::in_ajax();
     $this->context = $module;
     $this->request = core::lib('request');
     $this->renderer = core::lib('renderer');
     $this->params = $this->request->get_ident();
     $this->postdata = $this->request->filespost();
     $this->base_url = $this->context->get_editor_base_url();
     // action, colection_model (%module%_%action%_controller)
     // pre-init
     $this->construct_before();
     $this->init_mode();
     if ($this->with_model()) {
         /**
          * Force load deps when edit item
          */
         if ($this->mode == 'form') {
             $this->model_deps = true;
         }
         $this->collection_model = empty($this->collection_model) ? substr(substr(get_class($this), strlen($this->context->get_name()) + 1), 0, -11) : $this->collection_model;
         if (!isset($this->grid_name)) {
             $this->grid_name = 'grid-' . $this->params->m . '-' . $this->params->c;
             /*
             // @todo make grids unique ids
             if ($this->request->postget('grid')) {
              . '-' . functions::url_hash(microtime(1)); //str_replace('_', '-', $this->collection_model);
             }
             */
         }
         if ($this->collection !== false) {
             $this->collection = $this->create_collection();
         } else {
             $this->collection = abs_collection::get_null_collection();
         }
         if ($this->model_deps) {
             $this->collection->with_deps($this->model_deps);
         }
         // apply editor model style
         $this->set_collection_format($this->get_mode());
         $this->get_grid_filters();
         $this->prepare_grid_filters();
     }
     // is item submitted?
     $this->is_submited = (bool) $this->request->post(self::SUBMIT_CONTROL);
     // op=modify old compat
     if ($this->is_submited) {
         $this->params->op = 'modify';
         $this->submit_type = $this->request->post(self::SUBMIT_CONTROL);
     }
     // post-init
     $this->construct_after();
 }
 /**
  * Run action from file    
  * @param array|string array('action', 'file')
  * @param mixed for testing, otherwise controller params used
  */
 function run_file_action($name, $params = null)
 {
     $action = '';
     $file = '';
     $is_raw_file = false;
     if (is_array($name)) {
         $action = $name['action'];
         $file = $name['file'];
         if (isset($name['_file'])) {
             $file = $name['_file'];
             $is_raw_file = true;
         }
     } else {
         $file = $action = $name;
     }
     /*
     if (!empty($name['section'])) {
         $action = $name['section'] . '/' . $action;
     }
     */
     $action = str_replace('/', '_', $action);
     $fname = $file;
     //$is_raw_file ? $file : str_replace('_', '/', $file);
     $file = $this->get_context()->get_root() . 'actions/' . $fname . '.php';
     if (!file_exists($file)) {
         throw new controller_exception('Action file not found ' . $file);
     }
     fs::req($file);
     $class = $action . '_action';
     $class = core::get_instance()->modules()->ns($this->context->get_name(), $class);
     core::dprint(array("[CONTROLLER::RUN_FILE] %s from %s", $class, $file));
     if (!class_exists($class, 0)) {
         throw new router_exception('Action class not exists ' . $class);
     }
     if (empty($params)) {
         $params = $this->_params;
     }
     $action = new $class($this, $params);
     $action->run();
 }
Exemple #3
0
 /**
  * Route request
  * 
  * Warn! no exceptions
  * 
  * @return bool false if no routes found
  * @throws controller_exception, router_exception
  */
 function route($parts)
 {
     $this->_uri = implode('/', $parts);
     if (is_callable(array($this, 'route_before'))) {
         $this->route_before($parts);
     }
     core::dprint(array('[route] %s using defaut router, mod: %s', $this->_uri, $this->context->get_name()));
     // give up loading routes if set in routers class
     if (empty($this->_routes)) {
         $this->_routes = $this->load_routes();
     }
     if (empty($this->_routes)) {
         core::dprint('Empty routes in ' . get_class($this), core::E_ERROR);
         return false;
     }
     foreach ($this->_routes as $id => $route) {
         // normalize
         if (!isset($route['match']) && !isset($route['regex'])) {
             $route['match'] = $id;
         }
         if (!isset($route['action'])) {
             $route['action'] = $id;
         }
         if (!isset($route['type'])) {
             $route['type'] = 'method';
         }
         // class
         if (!isset($route['template'])) {
             $route['template'] = $id;
         }
         if ($route['action'] instanceof Closure) {
             $route['type'] = 'inline';
         }
         if ($route['type'] == 'method') {
             $route['action'] = str_replace('/', '_', $route['action']);
         }
         // append section to match if any
         // if (isset($route['section']) && !empty($route['match']))    $route['match']     = $route['section'] . '/' . $route['match'];
         $this->_filters = array();
         $back_uri = $this->_uri;
         // match filters
         // all filters created before dispatch!
         $this->match_filters($route);
         // route
         $params = null;
         if ($this->_debug) {
             core::dprint('.. route ' . $id);
             core::dprint_r($route);
         }
         if ($this->_is_route_matched($route, $params)) {
             // pure ajax routes
             if (isset($route['ajax']) && true !== loader::in_ajax()) {
                 throw new router_exception('Invalid query. Code.A6299');
             }
             if (isset($route['auth']['level'])) {
                 if ($route['auth']['level'] > core::lib('auth')->get_user()->level) {
                     throw new router_exception('Access denied. Code.A6298');
                 }
             }
             core::dprint(array('Route matched "%s"', $id));
             $this->_route = $route;
             $this->context->get_controller()->run($route, $params);
             $this->run_filters();
             return true;
         }
         // restore uri, loop again?
         $this->_uri = $back_uri;
     }
     return false;
 }