public function read($id = false) { $data = array(); $q = ""; if (!empty($id)) { $q = "WHERE `id`={$id}"; } $start = isset($_GET['start']) ? $_GET['start'] : 0; $limit = isset($_GET['limit']) ? $_GET['limit'] : 10; $query = "SELECT * FROM `blog` {$q} ORDER BY `last_update` DESC LIMIT {$start},{$limit}"; $result = $this->db->query($query); $nbrows = $this->db->fetchRow($this->db->query("SELECT COUNT(*) FROM `blog`")); $nbrows = $nbrows[0]; while ($row = $this->db->fetchAssoc($result)) { $data[] = $row; } if (MyHelpers::isAjax()) { // prepare the metadata $ret['metaData'] = $this->makeMetaData($result); $ret['total'] = $nbrows; $ret['data'] = $this->Char2Utf8($data); $ret['success'] = true; $ret['message'] = true; return json_encode($ret); } return $data; }
/** * Display Template */ public function render() { // extract the variables for view pages extract($this->_variables); // the view path $path = MyHelpers::UrlContent('~/views/'); // start buffering ob_start(); // render page content if (empty($this->viewPath)) { include $path . $this->_controller . DS . $this->_action . '.php'; } else { include $this->viewPath; } // get the body contents $this->_bodyContent = ob_get_contents(); // clean the buffer ob_end_clean(); // check if we have any layout defined if (!empty($this->layout) && !MyHelpers::isAjax()) { // we need to check the path contains app prefix (~) $this->layout = MyHelpers::UrlContent($this->layout); // start buffer (minify pages) ob_start('MyHelpers::minify_content'); // include the template include $this->layout; } else { ob_start('MyHelpers::minify_content_js'); // just output the content echo $this->_bodyContent; } // end buffer ob_end_flush(); }
public function index() { $data = $this->_model->read(); if (MyHelpers::isAjax()) { header('Content-type: application/json'); echo $data; } else { $this->view->set('items', $data); return $this->view(); } }
<?php if (!MyHelpers::isAjax()) { $this->layout = '~/views/shared/_defaultLayout.php'; if (isset($_GET['extjs']) && $_GET['extjs'] == true) { $this->section['head'] = "\n\t\t<!-- Sencha ExtJs 4.2.2 perm link -->\n\t\t<script src='http://docs.sencha.com/extjs/4.2.2/extjs-build/examples/shared/include-ext.js'></script>\n\t\t<link href='http://docs.sencha.com/extjs/4.2.2/extjs-build/examples/feed-viewer/Feed-Viewer.css' rel='stylesheet' type='text/css'/>\n\t\t<script>\n Ext.Loader.setConfig({enabled: true});\n Ext.Loader.setPath('Ext.ux', 'http://docs.sencha.com/extjs/4.2.2/extjs-build/examples/ux');\n Ext.require([\n 'Ext.ux.PreviewPlugin'\n ]);\n\t\t// Start loading the page \n\t\tExt.onReady(function(){\n\t\t\tExt.create('Ext.data.JsonStore', {\n\t\t\t storeId:'blogStore',\n\t\t\t autoLoad:true,\n\t\t\t\tproxy: {\n\t\t\t\t type: 'ajax',\n\t\t\t\t url: '/mvc/blog', // our data link\n\t\t\t\t reader: {\n\t\t\t\t type: 'json'\n\t\t\t\t }\n\t\t\t\t }\n\t\t\t});\n\t\t\t\n\t\t\tExt.create('Ext.grid.Panel', {\n\t\t\t title: 'Blog Posts',\n\t\t\t store: Ext.data.StoreManager.lookup('blogStore'),\n\t viewConfig: {\n\t itemId: 'view',\n\t plugins: [{\n\t pluginId: 'preview',\n\t ptype: 'preview',\n\t bodyField: 'content',\n\t expanded: true\n\t }]\n\t },\n\t\t\t columns: [\n\t\t\t { text: 'ID', dataIndex: 'id' },\n\t\t\t { text: 'Title', dataIndex: 'title', flex: 1, renderer: this.formatTitle},\n\t\t\t { text: 'Author', dataIndex: 'author', hidden: true, width: 200},\n\t\t\t { text: 'Last Update', dataIndex: 'last_update', renderer: this.formatDate, width: 200}\n\t\t\t ],\n\t\t\t dockedItems: [{\n\t\t\t xtype: 'pagingtoolbar',\n\t\t\t store: Ext.data.StoreManager.lookup('blogStore'), // same store GridPanel is using\n\t\t\t dock: 'bottom',\n\t\t\t displayInfo: true\n\t\t\t }],\n\t\t\t formatTitle: function(value, p, record){\n\t\t\t return Ext.String.format('<div class=\"topic\"><b>{0}</b><span class=\"author\">{1}</span></div>', value, record.get('author') || \"Unknown\");\n\t\t\t },\n\t\t\t formatDate: function(date){\n\t\t\t if (!date) {\n\t\t\t return '';\n\t\t\t }\n\t\t\t\n\t\t\t var now = new Date(), d = Ext.Date.clearTime(now, true), notime = Ext.Date.clearTime(date, true).getTime();\n\t\t\t\n\t\t\t if (notime === d.getTime()) {\n\t\t\t return 'Today ' + Ext.Date.format(date, 'g:i a');\n\t\t\t }\n\t\t\t\n\t\t\t d = Ext.Date.add(d, 'd', -6);\n\t\t\t if (d.getTime() <= notime) {\n\t\t\t return Ext.Date.format(date, 'D g:i a');\n\t\t\t }\n\t\t\t return Ext.Date.format(date, 'Y/m/d g:i a');\n\t\t\t },\n\t\t\t renderTo: 'bloglist'\n\t\t\t});\t\n\t\t});\t\t\n\t\t</script>\n"; } if (isset($_GET['extjs']) && $_GET['extjs'] == true) { ?> <div class="block bgWhite"> <div class="content"><div id='bloglist'></div></div> </div> <?php } else { ?> <div class="block bgWhite"> <div class="content"> <img src="http://catalizt.com/wp-content/uploads/2013/07/blog-banner.jpg" width="990" alt="" /> </div> <div class="content"> <?php foreach ($items as $item) { ?> <a href="./blog/detail/<?php echo $item['id']; ?> "> <h1 style="font-size: 20px; font-weight: bold; margin-bottom:5px;"><?php echo $item['title']; ?> </h1>