微擎开发--基础讲解

应用目录

应用存放在/addons目录下
应用下的模板存放在/template目录下,其中前端存放于/template/mobile目录,后端直接放在/template/ 下;

URL:

前台:http://www.aa.com/app/index.php?i=1&c=entry&eid=2
后台:http://www.aa.com/web/index.php?c=site&a=entry&eid=3&version_id=0

MVC形式的URL:
前台:http://www.aa.com/app/index.php?i=1&c=entry&do=index&m=edu_2018
后台:http://www.aa.com/web/index.php?c=site&a=entry&do=company&m=edu_2018

/app/:表示为前台页面
/web/:表示为后台页面
i=1:表示平台中公众号位置,第一个公众号
c=entry:前端c表示入口,默认entry
c=site:后端c表示site.php入口文件
a=entry:后端a表示入口,默认entry
eid=2:应用安装到数据库后多个菜单的id标识
do:类方法名称
m:表示应用模块名称

创建URL

$this->createMobileUrl('index');
$this->createWebUrl('company');

类:

前端名称必须以doMobile开头:function doMobileIndex() {…}
后端名称必须以doWeb开头:function doWebHt() {…}

全局变量

$_W是系统中最为重要的全局变量
用法: $_W[‘siteroot’]
$_GPC全局请求变量, 获取 $_GET, $_POST, $_COOKIES 中的变量
用法:$_GPC[‘eid’]

数据库

增加: pdo_insert($tablename, $data = array(), $replace = false);  int | boolean
删除: pdo_delete($tablename, $condition = array(), $glue = 'AND')  int | boolean
更新: pdo_update($tablename, $data = array(), $condition, $glue = 'AND')  array | boolean
查询: pdo_get($tablename, $condition = array(), $fields = array());  array | boolean
查询所有:pdo_getall($tablename, $condition = array(), $fields = array(), $keyfield = '');  array | boolean

模板:

类方法中的变量、数组等不需要引入或赋予前端模板,可以直接调用

public function doWebOrder() {
        global $_GPC,$_W;   
        $name='1-8课';
        $array=['哥','姐','弟','妹']; 
        include $this->template('index');
}
输出变量:{$name}<br/>
循环数组:
    <ul>
        <!-- 循环数组$index指针不是必须 -->
        {loop $array $index $item}
        {php $num=$index+1}  <!-- PHP语句 -->
            <li>
                {$index}-{$num}-
                <!-- if else判断 -->
                {if $item=='哥' || $item=='弟'}
                    {$item}-男
                {else}
                    {$item}-女
                {/if}
            </li>
        {/loop}
    </ul> 
跳转:<a href="{php echo $this->createMobileUrl('index')}">点击</a><br/>
引入模板:   
{template 'footer'}



posted @ 2019-07-18 10:02  心晗  阅读(1731)  评论(0编辑  收藏  举报