Exemplo n.º 1
0
 /**
  * Dynamic get Component
  *
  * @param string $key
  */
 public function __get($key)
 {
     $className = 'Cola_Com_' . ucfirst($key);
     if (Cola::loadClass($className)) {
         return $this->{$key} = new $className();
     } else {
         throw new Cola_Exception("No component like {$key} defined");
     }
 }
Exemplo n.º 2
0
 /**
  * Dynamic get helper
  *
  * @param string $key
  */
 public function __get($key)
 {
     $className = 'Cola_Helper_' . ucfirst($key);
     if (Cola::loadClass($className)) {
         return $this->{$key} = new $className();
     } else {
         throw new Exception("No helper like {$key} defined");
     }
 }
 /**
  * Instantiated model
  *
  * @param string $name
  * @param string $dir
  * @return Cola_Model
  */
 protected function model($name = null, $dir = null)
 {
     if (null === $name) {
         return $this->model;
     }
     null === $dir && ($dir = $this->_modelsHome);
     $class = ucfirst($name) . 'Model';
     if (Cola::loadClass($class, $dir)) {
         return new $class();
     }
     throw new exception("Can't load model '{$class}' from '{$dir}'");
 }
Exemplo n.º 4
0
 /**
  * Widget
  *
  * @param string $name
  * @param array $data
  * @return Cola_Com_Widget
  */
 public function widget($name, $data = null)
 {
     if (empty($this->_widgetsHome) && ($widgetsHome = Cola::config('_widgetsHome'))) {
         $this->_widgetsHome = $widgetsHome;
     }
     $class = ucfirst($name) . 'Widget';
     if (!Cola::loadClass($class, $this->_widgetsHome)) {
         throw new Cola_Exception("Can not find widget:{$class}");
     }
     $widget = new $class($data);
     return $widget;
 }
<?php

error_reporting(E_ALL);
define('APP_DIR', dirname(__FILE__));
require '../Cola/Cola.php';
require './config.inc.php';
$cola = Cola::getInstance();
// 获得类名
if (isset($_GET['c'])) {
    $className = ucfirst($_GET['c']) . 'Controller';
} else {
    $className = 'IndexController';
}
// 获得方法名
if (isset($_GET['a'])) {
    $actionName = $_GET['a'] . 'Action';
} else {
    $actionName = 'indexAction';
}
try {
    Cola::loadClass($className, './controllers');
    $dispatchInfo = array('controller' => $className, 'action' => $actionName);
    $cola->setDispatchInfo($dispatchInfo);
    $cola->dispatch();
} catch (Exception $e) {
    // 处理404
    header("HTTP/1.0 404 Not Found");
    header("Status: 404 Not Found");
    header('Location:404.html');
}
Exemplo n.º 6
0
 /**
  * Instantiated model
  *
  * @param string $name
  * @param string $dir
  * @return Cola_Model
  */
 protected function model($name, $dir = null)
 {
     null === $dir && ($dir = Cola::config('_modelsHome'));
     $class = ucfirst($name) . 'Model';
     if (Cola::loadClass($class, $dir)) {
         return new $class();
     }
     throw new exception("Can't load model '{$class}' from '{$dir}'");
 }