Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: 增加向js文件传递变量的方法 #143

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/admin/view/layout/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
VERSION: "{$version|default='1.0.0'}",
CSRF_TOKEN: "{:token()}",
};
window.$variables = {$jsVariables|raw|default='null'};
</script>
<script src="__STATIC__/plugs/layui-v2.5.6/layui.all.js?v={$version}" charset="utf-8"></script>
<script src="__STATIC__/plugs/require-2.3.6/require.js?v={$version}" charset="utf-8"></script>
Expand Down
10 changes: 10 additions & 0 deletions app/common/controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ protected function initialize()
$this->checkAuth();
}

/**
* 设置js变量
* @param array $data
* @return mixed
*/
public function setJsVariables(array $data = [])
{
return $this->assign('jsVariables', json_encode($data));
}

/**
* 模板变量赋值
* @param string|array $name 模板变量
Expand Down