protected function ajax($data, $type = 'json') { switch (strtoupper($type)) { case 'JSON': // 返回JSON数据格式到客户端 包含状态信息 pt::show(json_encode($data), 'application/json'); break; case 'JSONP': // 返回JSON数据格式到客户端 包含状态信息 $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : 'ptcms_jsonp'; pt::show($handler . '(' . json_encode($data) . ');', 'application/json'); break; case 'EVAL': // 返回可执行的js脚本 pt::show($data); break; default: // 用于扩展其他返回格式数据 } exit; }
public static function autoload($class) { $classfile = strtolower(str_replace('_', '/', $class)); if (in_array($classfile, array('controller', 'view', 'dispatcher', 'cache', 'model', 'plugin', 'storage', 'widget', 'log'))) { pt::import(PT_PATH . '/core/' . $classfile . '.php'); } elseif (substr($classfile, 0, 6) == 'driver') { pt::import(PT_PATH . '/' . $classfile . '.php'); } elseif (substr($classfile, -10) == 'controller') { if (!pt::import(APP_PATH . '/' . MODULE_NAME . '/controller/' . substr($classfile, 0, -10) . '.php')) { pt::import(APP_PATH . '/common/controller/' . substr($classfile, 0, -10) . '.php'); } } elseif (substr($classfile, -5) == 'model') { if (!pt::import(APP_PATH . '/common/model/' . substr($classfile, 0, -5) . '.php')) { pt::import(APP_PATH . '/' . MODULE_NAME . '/model/' . substr($classfile, 0, -5) . '.php'); } } elseif (substr($classfile, -6) == 'widget') { if (!pt::import(APP_PATH . '/common/widget/' . substr($classfile, 0, -6) . '.php')) { pt::import(APP_PATH . '/' . MODULE_NAME . '/widget/' . substr($classfile, 0, -6) . '.php'); } } elseif (substr($classfile, -6) == 'plugin') { pt::import(APP_PATH . '/common/plugin/' . substr($classfile, 0, -6) . '.php'); } else { pt::import(PT_PATH . '/library/' . $classfile . '.php') or pt::import(APP_PATH . '/common/library/' . $classfile . '.php') or pt::import(APP_PATH . '/' . MODULE_NAME . 'library/' . $classfile . '.php'); } }