示例#1
0
 function test_controller_exists()
 {
     $c_exists =& NController::exists('page');
     $this->assertTrue($c_exists, 'Page Controller exists()');
     $c =& NController::singleton('page');
     $this->assertInstanceOf('PageController', $c);
     $c2 =& NController::singleton('page');
     $this->assertSame($c, $c2, "NController::singleton() returns a reference to the same object");
     unset($c2);
     $class_name = $c->getClassName('page');
     $this->assertEquals($class_name, "PageController", "getClassName returns proper name");
 }
示例#2
0
 /**
  * Instantiates and invokes the controller if it's available.
  *
  * @access private
  * @param string $controller
  * @param string $action				the action to be performed
  * @param string $parameter
  * @return null
  *
  */
 function _invoke($controller, $action, $parameter = null)
 {
     if (!$this->app_dir) {
         $controller = 'page';
     }
     if (!NController::exists($controller)) {
         $this->error($controller, $action);
     }
     $ctrl =& NController::factory($controller);
     if (!$action && method_exists($ctrl, 'index')) {
         $action = 'index';
     }
     if (!$this->app_dir && !in_array($action, $ctrl->public_actions)) {
         $action = 'index';
     }
     $method = Inflector::camelize($action);
     $ctrl->action = $action;
     if ($ctrl->login_required === true || is_array($ctrl->login_required) && (in_array($action, $ctrl->login_required) || in_array($method, $ctrl->login_required))) {
         include_once 'n_auth.php';
         $ctrl->_auth = new NAuth();
     }
     if (!$ctrl->checkUserLevel()) {
         header('Location:/' . APP_DIR . '/');
         exit;
     }
     // do the method
     if (!$this->app_dir && $controller == 'page') {
         $model =& $ctrl->getDefaultModel();
         // /_page8 redirection support (BC fix)
         if (preg_match('|^/_page(\\d+)|', $this->url, $matches)) {
             $parameter = $matches[1];
             if ($page_info = $model->getInfo($parameter)) {
                 header('Location:' . $ctrl->getHref($page_info) . ($this->params ? '?' . $this->paramsToString() : ''));
                 exit;
             }
         }
         if ($action != 'menus') {
             $parameter = $ctrl->models['page']->URLToID($this->url);
         }
     }
     if (method_exists($ctrl, $method)) {
         $ctrl->{$method}($parameter);
         if ($ctrl->auto_render) {
             $ctrl->render();
         }
     } else {
         $this->error($ctrl, $method);
     }
     unset($ctrl);
 }