示例#1
0
 /**
  * The function executes controller built on its name and arguments.
  * 
  * @static
  * @access public
  * @param string $className The controller class name.
  * @param array $args The arguments array.
  * @return string The result of executed controller.
  */
 public static function executeController($className, array $args = array())
 {
     $Controller = null;
     $res = array('method' => null, 'args' => array(), 'argsText' => '');
     for ($i = 0; $i < count($args); $i++) {
         $arr = array_slice($args, 0, count($args) - $i);
         $name = $className . '_' . implode('_', $arr);
         if (Autoload::exist($name) !== false) {
             $Controller = new $name();
             $Controller->setView();
             if ($Controller->isHidden()) {
                 continue;
             }
             $res = self::buildParams($Controller, array_slice($args, count($args) - $i));
             break;
         }
     }
     if (!$Controller) {
         $Controller = new $className();
         $Controller->setView();
         $res = self::buildParams($Controller, $args);
     }
     return $Controller->runMethod($res['method'], $res['args'], $res['argsText']);
 }