Example #1
0
 /**
  * 框架错误
  * @param  objcet $e 错误对象
  * @return viod
  */
 public function appError($e)
 {
     if (404 == $e->getCode()) {
         $action = 'error404';
     } else {
         $action = 'error';
     }
     obj('base/Error', 'controller')->{$action}($e);
 }
 function set_theme($key = 'AdminThemeTryChangeCSS', $value = 'admin_bootstrap_css')
 {
     $t = $_GET[$key];
     if (!$t) {
         return;
     }
     $e = self::config($value);
     $obj = obj('\\Model\\Config');
     if ($e) {
         $obj->update(['title' => $value], ['value' => $t]);
     } else {
         $obj->insert(['title' => $value, 'value' => $t]);
     }
 }
 /**
  * 
  * @param array $page
  */
 static function getByCate($page = [])
 {
     $c = obj('Model\\Category');
     $slug = $page['slug'];
     unset($page['slug']);
     if ($slug) {
         $cate = $c->findOne(['slug' => $slug]);
         if ($cate) {
             $id = $cate->id;
         }
     }
     $c = obj('\\Model\\Post');
     $condition = $page['condition'];
     if ($id) {
         $condition['category'] = $id;
     }
     $condition['status'] = 1;
     $page['condition'] = $condition;
     $all = $c->page($page);
     return $all;
 }
Example #4
0
function model($class)
{
    return obj('models\\' . $class);
}
Example #5
0
/**
 * Output an object in a readable format for comparison with similar output from javascript
 *
 */
function obj($mixed)
{
    static $objects = array();
    global $obj_buffer;
    if (empty($obj_buffer)) {
        $obj_buffer = "----make sure caching is turned off----\n";
    }
    static $level = 0;
    $output = '';
    $exclude_keys = array('originalRuleset', 'currentFileInfo', 'lookups', 'index', 'ruleset_id', 'type', '_rulesets', '_variables', 'allowImports', '_css', 'cache_string', 'elements_len', '_oelements', 'first_oelements', '_oelements_len', 'cacheable');
    //$exclude_keys = array();
    $type = gettype($mixed);
    switch ($type) {
        case 'object':
            if (in_array($mixed, $objects, true)) {
                return 'recursive';
            }
            $objects[] = $mixed;
            $type = 'object';
            if (property_exists($mixed, 'type')) {
                $type .= ' ' . $mixed->type;
            }
            //$type = get_class($mixed).' object';
            //$output = $type.'(...)'."\n"; //recursive object references creates an infinite loop
            $temp = array();
            foreach ($mixed as $key => $value) {
                //declutter
                if (in_array($key, $exclude_keys, true)) {
                    continue;
                }
                $temp[$key] = $value;
            }
            $mixed = $temp;
        case 'array':
            if (!count($mixed)) {
                $output = $type . '()';
                break;
            }
            $output = $type . '(' . "\n";
            ksort($mixed);
            foreach ($mixed as $key => $value) {
                $level++;
                $output .= str_repeat('    ', $level) . '[' . $key . '] => ' . obj($value) . "\n";
                $level--;
            }
            $output .= str_repeat('    ', $level) . ')';
            break;
        case 'string':
            $output = '(string:' . strlen($mixed) . ')' . htmlspecialchars($mixed, ENT_COMPAT, 'UTF-8', false) . '';
            break;
        case 'integer':
            $type = 'number';
            $output = '(number)' . $mixed;
            break;
        case 'boolean':
            if ($mixed) {
                $mixed = 'true';
            } else {
                $mixed = 'false';
            }
        default:
            $output = '(' . $type . ')' . htmlspecialchars($mixed, ENT_COMPAT, 'UTF-8', false) . '';
            break;
    }
    if ($level === 0) {
        $objects = array();
        $obj_buffer .= $output . "\n------------------------------------------------------------\n";
    }
    return $output;
}
Example #6
0
 function get_post($c = [])
 {
     $post = obj('Model\\Post');
     return $post->find($c);
 }
get('/', function () {
    return view('index');
});
get('about', function () {
    return view('about');
});
get('guid', function () {
    return view('guid');
});
get('posts|posts/<q:\\w+>', function () {
    $post = new Model\Post();
    $q = $_GET['q'];
    $c['status'] = 1;
    if ($q) {
        //$c['title'] =  new \MongoRegex("/$q/i");
        $obj = obj('Model\\Category');
        $rt = $obj->findOne(['slug' => $q]);
        $cid = $rt->id;
        if ($cid) {
            $c['category'] = $cid;
        }
    }
    if ($q) {
        $qurl = "/" . $q;
    }
    $data = $post->page(['url' => '/posts' . $qurl, 'size' => 1, 'sort' => ['created' => -1], 'condition' => $c]);
    return view('posts', $data);
});
get('post/<id:\\w+>', function ($id) {
    $post = new Model\Post();
    $data['data'] = $post->findOne(['slug' => $id]);
function theme_get_post($slug)
{
    $post = obj('Model\\Post');
    $c['slug'] = $slug;
    return $post->findOne($c);
}
Example #9
0
 /**
  * 首页
  */
 public function index()
 {
     $this->title = obj('Demo')->getTitle();
     $this->hello = obj('Demo')->getHello();
     $this->display();
 }