# 后端新增代碼
* [ ] `介紹` 由于有些功能尚未開發,在原有基礎上新加的功能,用法詳見模板使用。
*****
## 路徑:\application\common.php;功能:判斷是否是在首頁
```
//判斷是否是在首頁
function isIndex(){
$request = \think\Request::instance();
if( strtolower($request->controller()) == 'index' && strtolower($request->action()) == 'index'){
return true;
}else{
return false;
}
}
```
*****
## 路徑:\application\common.php;功能:獲取欄目信息
```
/**
* 獲取欄目信息
* @param $outlink :所屬標簽的路徑
* eg:路徑通常用$__指定標簽__['url'];表單比較特殊,列表表單用$__表單標簽__['url'],提交表單用url($__表單標簽__['redirecturl'])
* @return 欄目信息
*/
function outlinkFindChannel($outlink)
{
$channel = \addons\cms\model\Channel::field('*')->where('outlink', $outlink)->find();
return $channel;
}
```
## 路徑:\application\common.php;功能:根據id獲取欄目信息
~~~
/**
* 根據id獲取欄目信息
* @param $id :欄目ID
*@return 欄目信息
*/
function getParentChannel($id){
$channel = \addons\cms\model\Channel::field('*')->where('id', $id)->find();
return $channel;
}
~~~
## 路徑:\addons\cms\controller\Base.php,\application\admin\controller\cms\Ajax.php,\addons\cms\config.php;功能:區分移動端跟PC端(Base.php跟config.php同時修改)。
## 替換包(可直接下載替換包修改Ajax.php跟Base.php,config文件還是得按照下面內容修改。提取碼: tbjr):[下載](https://pan.baidu.com/s/1se8Pm436xk7JMTrGwiZUNA)
~~~
Base.php(記得引入use think\Request;):
將以下代碼:
// 設定主題模板目錄
$this->view->engine->config('view_path', $this->view->engine->config('view_path') . $config['theme'] . DS);
修改成如下:
//判斷是否是移動端
if (Request::instance()->isMobile()) {
$theme = $config['thememobile'];
} else {
$theme = $config['themepc'];
}
// 設定主題模板目錄
$this->view->engine->config('view_path', $this->view->engine->config('view_path') . $theme . DS);
----------------------------------------------------------------------------------------------
Ajax.php(記得引入use think\Request;):
將一下代碼:
$themeDir = ADDON_PATH . 'cms' . DS . 'view' . DS . $config['theme'] . DS;
修改成如下:
//判斷是否是移動端
if (Request::instance()->isMobile()) {
$theme = $config['thememobile'];
} else {
$theme = $config['themepc'];
}
$themeDir = ADDON_PATH . 'cms' . DS . 'view' . DS . $theme . DS;
----------------------------------------------------------------------------------------------
config.php
將以下代碼:
[
'name' => 'theme',
'title' => '皮膚',
'type' => 'string',
'content' => [],
'value' => 'default',
'rule' => 'required',
'msg' => '',
'tip' => '請確保addons/cms/view有相應的目錄',
'ok' => '',
'extend' => '',
],
修改成如下:
[
'name' => 'themepc',
'title' => 'PC皮膚',
'type' => 'string',
'content' => [],
'value' => 'default',
'rule' => 'required',
'msg' => '',
'tip' => '請確保addons/cms/view有相應的目錄',
'ok' => '',
'extend' => '',
],
[
'name' => 'thememobile',
'title' => '手機皮膚',
'type' => 'string',
'content' => [],
'value' => 'mobile',
'rule' => 'required',
'msg' => '',
'tip' => '請確保addons/cms/view有相應的目錄',
'ok' => '',
'extend' => '',
],
~~~
- 介紹
- 標簽手冊
- 全局標簽
- block標簽
- config標簽
- execute標簽
- query標簽
- breadcrumb標簽
- blocklist標簽
- 欄目標簽
- channellist標簽
- channel標簽
- nav標簽
- 文章標簽
- arclist標簽
- archives標簽
- prevnext標簽
- 專題
- speciallist標簽
- special標簽
- 公共參數
- common參數
- include引用
- 單頁
- spagelist標簽
- page標簽
- spageinfo標簽
- 特殊標簽
- tagslist標簽
- tags標簽
- commentlist標簽
- commentinfo標簽
- diyform標簽
- 模板特殊標簽
- 列表頁面
- pagelist標簽
- pageinfo標簽
- pagefilter標簽
- pageorder標簽
- pagelist的相關排序
- 新功能
- 后端新增代碼
- 模板使用
- 二級導航功能
- 共用banner功能
- 后臺站點配置添加編輯器