javascript - 如何在 Perfex CRM 中隐藏用户角色的数据?
问题描述
我需要一个隐藏 Perfex CRM for User Roles 某些部分的功能。示例:折扣区。
我试过这段代码:
function hide_fields_nonusers()
{
if ($role != '4') {
<style type="text/css">
#sconto {
display: none !important;
}
#discount_area {display: none !important;}
</style>
}
但是没有任何效果,它为每个人隐藏了那部分,包括管理员。
编辑
这个正在工作,但只是为了通过 ID 获取员工角色。
/**
* Get employee role by id
* @param mixed $id Optional role id
* @return mixed array if not id passed else object
*/
public function get($id = '')
{
if (is_numeric($id)) {
$role = $this->app_object_cache->get('role-' . $id);
if ($role) {
return $role;
}
$this->db->where('roleid', $id);
$role = $this->db->get(db_prefix() . 'roles')->row();
$role->permissions = !empty($role->permissions) ? unserialize($role->permissions) : [];
$this->app_object_cache->add('role-' . $id, $role);
return $role;
}
return $this->db->get(db_prefix() . 'roles')->result_array();
}
解决方案
它可能hide_fields_nonusers()
会产生 PHP 错误,因为此函数不是完全有效的 PHP 代码。
要回答您的问题 - 根据您提供的内容 - 如果您在$role
不等于 4 时将样式标签作为 PHP 代码回显,这应该可以工作。
注意: 如果您没有收到任何错误消息,则表明该函数根本没有执行。正如 Marcel 评论的那样,如果您可以发布您调用此函数的位置,我们可以看得更近一些。
PHP
public function hide_fields_nonusers()
{
if ($role != '4') {
echo '<style type="text/css">
#sconto { display:none !important; }
#discount_area { display:none !important; }
</style>';
}
}
或者对于 JavaScript
if ($role != 4) {
var css = '#sconto { display:none !important; }
#discount_area { display:none !important; }',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
head.appendChild(style);
style.type = 'text/css';
if (style.styleSheet) {
// This is required for IE8 and below.
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
推荐阅读
- java - Android 上 Discord 和 Slack 中的新导航系统
- r - r - 使用反应对 Barts-ggplot2 进行排序
- c# - Blazor 页面中的 CancellationToken?
- javascript - 如何在 JavaScript 大集合中进行排序和搜索
- javascript - 如何在函数内使用防止默认和切换?
- python - Librosa 加载许多 MP3 内存使用情况
- python-3.x - 为什么我收到一条错误消息:“TabError:缩进中制表符和空格的使用不一致”?
- vue.js - 无法使用 Escape 键关闭 Vuetify 导航抽屉
- javascript - HTML + CSS | 主要内容不与导航栏重叠的问题
- c - C 如何使用 struct、union 或 enum 来构建菜单?