如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
http://note.youdao.com/noteshare?id=ce025646d5517556c3e190c0e3abe8d8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
数据库字典 https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=133 配置选项 https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=134 预定义常量 https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=14 系统 程序安装目录 IA_ROOT 微擎程序附件目录 ATTACHMENT_ROOT 当前模块目录 MODULE_ROOT 当前模块URL MODULE_URL 当前系统时间 TIMESTAMP 当前客户端IP CLIENT_IP 公众号 权限 卡券 附件 缓存 小程序 自定义菜单 用户状态 消息提醒 全局变量 $_GPC $_W 全局配置 https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=155 系统配置 公众号相关 web端可见 app端可见 网页授权 URL路由 c a do http://we7.cc/web/index.php?c=platform&a=menu& 当传入的 c 值为 “site”, a 值为 “entry”时则是一个模块路由,例如: http://we7.cc/web/index.php?c=site&a=entry&do=themeset&m=we7_demo 则会路由至 /addons/we7_demo/site.php 文件中的 doWebThemeset() 方法。 http://we7.cc/app/index.php?i=1&j=2&c=entry&do=list&m=ewei_shopping 则会路由至 /addons/we7_demo/site.php 文件中的 doMobileList() 方法。 url() 创建一个URL url($segment, $params = array(), $noredirect = false) 示例: echo url('site/entry/themeset', array('m' => 'we7_demo')); //http://we7.cc/web/index.php?c=site&a=entry&do=themeset&m=we7_demo echo url('mc/home'); //http://we7.cc/app/index.php?c=mc&a=home& createMobileUrl 示例 class We7_demoModuleSite extends WeModuleSite { public function doMobileIndex() { echo $this->createMobileUrl('home'); } public function doMobileHome() { //上面doMobileIndex()生成的链接会进入到这里 } } createWebUrl class We7_demoModuleSite extends WeModuleSite { public function doWebIndex() { echo $this->createWebUrl('home'); } public function doWebHome() { //上面doWebIndex()生成的链接会进入到这里 } } 文件加载器 func load()->func() - 加载系统公共函数 // framework/function/logging.func.php load()->func('logging'); class load()->class() - 加载系统公共类 // framework/class/account.class.php load()->classs('account'); model load()->model() - 加载系统model函数 // framework/model/attachment.mod.php load()->model('attachment'); web load()->web() - 加载web端公共函数 // web/common/tpl.func.php load()->web('tpl'); app load()->app() - 加载app端公共函数 // app/common/tpl.func.php load()->app('tpl'); library object singleton 缓存机制 cache_write('test', $data) - 按照指定的键名存储缓存数据 cache_load('test') - 读取指定键名的缓存数据 cache_delete('test') - 删除指定的缓存 cache_clean() - 清空所有缓存 cache_system_key() 统一系统缓存名称前缀,支持缓存名称中包含占位符,最多不得超过5个 数据库 https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=173 sql注入安全 函数列表 pdo_get() - 根据条件(AND连接)到指定的表中获取一条记录 $user = pdo_get('users', array('uid' => 1), array('username', 'uid')); pdo_getcolumn() - 根据条件(AND连接)到指定的表中获取一条记录的指定字段 $username = pdo_getcolumn('users', array('uid' => 1), 'username'); pdo_getall() - 根据条件(AND连接)到指定的表中获取全部记录 //生成的SQL等同于:SELECT * FROM ims_users WHERE status = '1' $user = pdo_getall('users', array('status' => 1)); pdo_getslice() - 根据条件(AND连接)到指定的表中获取某个区间的记录,此函数和 pdo_getall 的区别是可以指定limit 值 $user = pdo_getslice('users', array(), array(0, 10), $total); echo $total; pdo_fetch() - 根据SQL语句,查询一条记录 // :uid 是参数的一个占位符,没有使用引号,传入的第二个参数中要与SQL中的占位名称相同 $user = pdo_fetch("SELECT username, uid FROM ".tablename('users')." WHERE uid = :uid LIMIT 1", array(':uid' => 1)); // LIKE 占位的使用方法 $user = pdo_fetch("SELECT * FROM ".tablename('users')." WHERE username LIKE :username", array(':username' => '%mizhou%')); pdo_fetchcolumn() - 根据SQL语句,查询第一条记录的第N列的值,此语句与 pdo_fetch 使用相同,只是此函数返回的不是一个数组而是一个字符串 / 获取用户的总数,返回的值是一个数字 $user_total = pdo_fetchcolumn("SELECT COUNT(*) FROM ".tablename('users')); pdo_fetchall() - 根据SQL语句,查询全部记录,使用方法与pdo_fetch相同 // 需要注意的是,返回的数组的键值为用户的uid $user = pdo_fetchall("SELECT username, uid FROM ".tablename('users'), array(), 'uid'); pdo_insert() - 对指定数据表插入一条新记录 //添加一条用户记录,并判断是否成功 $user_data = array( 'username' => 'mizhou1', 'status' => '1', ); $result = pdo_insert('users', $user_data); if (!empty($result)) { $uid = pdo_insertid(); message('添加用户成功,UID为' . $uid); } pdo_update() - 更新指定的数据表的记录 //更uid等于2的用户的用户名 $user_data = array( 'username' => 'mizhou2', ); $result = pdo_update('users', $user_data, array('id' => 2)); if (!empty($result)) { message('更新成功'); } pdo_delete() - 删除指定条件的数据 //删除用户名为mizhou2的记录 $result = pdo_delete('users', array('username' => 'mizhou2')); if (!empty($result)) { message('删除成功'); } pdo_query() - 执行一条非查询语句 //更uid等于2的用户的用户名 $result = pdo_query("UPDATE ".tablename('users')." SET username = :username, age = :age WHERE uid = :uid", array(':username' => 'mizhou2', ':age' => 18, ':uid' => 2)); //删除用户名为mizhou2的记录 $result = pdo_query("DELETE FROM ".tablename('users')." WHERE uid = :uid", array(':uid' => 2)); if (!empty($result)) { message('删除成功'); } pdo_run() - 批量执行SQL语句 $sql = <<<EOF CREATE TABLE IF NOT EXISTS `ims_multisearch` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `weid` int(10) unsigned NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `ims_multisearch_fields` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `reid` int(10) unsigned NOT NULL, `type` tinyint(1) unsigned NOT NULL DEFAULT '1', `title` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `idx_reid` (`reid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; EOF; pdo_run($sql); pdo_fieldexists() - 检查表中是否存在某个字段 //如果shopping_goods表中不存在credit字段,则新增credit字段 if(!pdo_fieldexists('shopping_goods', 'credit')) { pdo_query("ALTER TABLE ".tablename('shopping_goods')." ADD `credit` int(11) NOT NULL DEFAULT '0';"); } pdo_indexexists() - 检查表中是否存在某个索引 //如果site_slide表中不存在multiid索引,则新增multiid索引 if (!pdo_indexexists('site_slide', 'multiid')) { pdo_query("ALTER TABLE ".tablename('site_slide')." ADD INDEX `multiid` (`multiid`);"); } pdo_tableexists() - 检查数据库中是否存在某个表 if (!pdo_tableexists('site_slide')) { echo '表不存在'; } pdo_fieldmatch() - 检查某个表中的字段类型是不是符合 pdo_fieldmatch('users', 'id', 'varchar'); // 类型不符合,返回 false pdo_fieldmatch('users', 'id', 'int'); // 类型符合,返回 true pdo_fieldmatch('users', 'id', 'int', 5); // 长度不符合,返回 -1 pdo_debug() - 调试运行SQL语句,显示执行过的SQL的栈情况 pdo_debug(); 链式操作 from/select/where/having/groupby/orderby/leftjoin/innerjoin/on/limit/page/get/getall/getcolumn/count/exists getLastQueryTotal/getLastQuery $query = load()->object('query'); $row = $query->from('users', 'u')->select('u.username')->get(); 错误处理 微擎系统中使用 error($errno, $message = '') 来定义一个错误结构,使用 is_error($data) 函数来判断是否发生错误。 日志处理 https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=186 模板引擎 //渲染 template('user/login'); //调用 include $this->template('index1'); 输出变量 {$foo} 判断语句 {if condition} {elseif condition} {else} {/if} 循环语句 {loop $result $key $value} {/loop} PHP语句 <span class="help-block">{ php echo date('Y-m-d H:i:s', $row['followtime'])}</span> 引用模板 {template ‘$templatename’} 创建URL {url ‘controller/action/do’, (array)querystring} 转义附件URL {media imageurl} 输出花括号 {##string##} 数据调用 {data func=”site_navs” index=”” item=”” assign=”” return=”true” limit=”10” module=”we7_demo”} //循环体 {/data} 调用微站导航 获取当前微站的导航 {data func="site_navs" item="row"} {$row['html']} {/data} 获取当前微站第二个位置的导航 {data func="site_navs" section="1" item="row"} 第$row['iteration']个:{$row['html']} {/data} 调用幻灯片 {data func="site_slide_search" item="row" limit="4"} <li>Name: {$row['thumb']}</li> {/data} 调用文章列表 {data func="site_article" cid=$cid return="true" assign="result"} {loop $result['list'] $row} <li> <div class="info"> <h3>{$row['title']}</h3> <p class="text">{$row['description']}</p> </div> <div class="pic"> <img src="{php echo tomedia($row['thumb'])}"> </div> </li> {/loop} 调用分类列表 <div class="category"> {data func="site_category" parentid="$cid"} <a href="{$row['linkurl']}">{$row['name']}</a> {/data} </div> 调用快捷菜单 {data func="site_quickmenu"}{/data} 微信消息 https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=542 函数列表 https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=204 系统公共函数 参数安全函数 业务公共函数 http请求参数 文件操作函数 数据库维护函数 web端公共函数 APP端公共函数 安全操作函数 模块组件列表 web端组件 APP端组件 系统公共组件 支付API https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=360 微信API https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=361 云服务API https://s.w7.cc/index.php?c=wiki&do=view&id=1&simple=&list=388 小程序开发 应用开发 云商城常见问题 |