比如我想在VIEW中只显示属于自己角色的页面,怎么设置,似乎只能选择角色为特定的角色比如注册用户,而不能选择比如我是注册用户,就显示注册用户发表过的东西,如果我是匿名用户,就只能显示匿名用户发表过的东西!这个应该不是太难的问题吧??有人知道吗??急
你可以試試我的views export 主要是用一個 role argumments, default value 給php code php 讀$user, $user->roles 有角色id 主要的一句php <?php $roles = implode("+",array_keys($user->roles));?>
<?php $roles = implode("+",array_keys($user->roles));?>
views import (你要自己加page/block)
<?php$view = new view;$view->name = 'role_arg_test';$view->description = '';$view->tag = '';$view->view_php = '';$view->base_table = 'node';$view->is_cacheable = FALSE;$view->api_version = 2;$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */$handler = $view->new_display('default', 'Defaults', 'default');$handler->override_option('fields', array( 'title' => array( 'label' => 'Title', 'alter' => array( 'alter_text' => 0, 'text' => '', 'make_link' => 0, 'path' => '', 'link_class' => '', 'alt' => '', 'prefix' => '', 'suffix' => '', 'target' => '', 'help' => '', 'trim' => 0, 'max_length' => '', 'word_boundary' => 1, 'ellipsis' => 1, 'strip_tags' => 0, 'html' => 0, ), 'empty' => '', 'hide_empty' => 0, 'empty_zero' => 0, 'link_to_node' => 1, 'exclude' => 0, 'id' => 'title', 'table' => 'node', 'field' => 'title', 'relationship' => 'none', ), 'name' => array( 'label' => 'Name', 'alter' => array( 'alter_text' => 0, 'text' => '', 'make_link' => 0, 'path' => '', 'link_class' => '', 'alt' => '', 'prefix' => '', 'suffix' => '', 'target' => '', 'help' => '', 'trim' => 0, 'max_length' => '', 'word_boundary' => 1, 'ellipsis' => 1, 'strip_tags' => 0, 'html' => 0, ), 'empty' => '', 'hide_empty' => 0, 'empty_zero' => 0, 'link_to_user' => 1, 'overwrite_anonymous' => 0, 'anonymous_text' => '', 'exclude' => 0, 'id' => 'name', 'table' => 'users', 'field' => 'name', 'relationship' => 'none', ), 'rid' => array( 'label' => 'Roles', 'alter' => array( 'alter_text' => 0, 'text' => '', 'make_link' => 0, 'path' => '', 'link_class' => '', 'alt' => '', 'prefix' => '', 'suffix' => '', 'target' => '', 'help' => '', 'trim' => 0, 'max_length' => '', 'word_boundary' => 1, 'ellipsis' => 1, 'strip_tags' => 0, 'html' => 0, ), 'empty' => '', 'hide_empty' => 0, 'empty_zero' => 0, 'type' => 'separator', 'separator' => ', ', 'exclude' => 0, 'id' => 'rid', 'table' => 'users_roles', 'field' => 'rid', 'relationship' => 'none', ),));$handler->override_option('arguments', array( 'rid' => array( 'default_action' => 'default', 'style_plugin' => 'default_summary', 'style_options' => array(), 'wildcard' => 'all', 'wildcard_substitution' => 'All', 'title' => '', 'breadcrumb' => '', 'default_argument_type' => 'php', 'default_argument' => '', 'validate_type' => 'none', 'validate_fail' => 'not found', 'break_phrase' => 1, 'add_table' => 0, 'require_value' => 0, 'reduce_duplicates' => 0, 'id' => 'rid', 'table' => 'users_roles', 'field' => 'rid', 'validate_user_argument_type' => 'uid', 'validate_user_roles' => array( '2' => 0, '7' => 0, '6' => 0, '5' => 0, '4' => 0, '3' => 0, ), 'relationship' => 'none', 'default_options_div_prefix' => '', 'default_argument_user' => 0, 'default_argument_fixed' => '', 'default_argument_php' => 'global $user;$roles = implode("+",array_keys($user->roles));return $roles;', 'validate_argument_node_type' => array( 'location' => 0, 'page' => 0, 'story' => 0, ), 'validate_argument_node_access' => 0, 'validate_argument_nid_type' => 'nid', 'validate_argument_vocabulary' => array( '1' => 0, ), 'validate_argument_type' => 'tid', 'validate_argument_transform' => 0, 'validate_user_restrict_roles' => 0, 'validate_argument_php' => '', ),));$handler->override_option('access', array( 'type' => 'none',));$handler->override_option('cache', array( 'type' => 'none',));$handler->override_option('style_plugin', 'list');$handler->override_option('style_options', array( 'type' => 'ul',));?>
-------------------------------- Joetsui's blog
非常感谢这位大哥,不过代码好长啊!!我PHP不是太懂,偶是VB出身滴人啊。就是想问下能不能自己在VIEW下设置呢?过滤功能+Arguments能否解决这件事?我的意思是尽量少些代码!再次感谢这位大哥
ozp
你import 了之後, 就沒有代碼了 我手寫的都只有三行code 一句一句教你如何設置的話, 不如你import 了, 自己看看便會明白
我是在VIEWS选择导入,在Paste view code here:*这里复制了你上面的代码,可是就显示导入不了,怎么回事??帮忙啊
Unable to interpret view code. 在views中,点import导入这段代码。显示无法导入。 要导入。是不是要先建一个这样的内容类型,或是开启哪些模块?
不过能否解释下关于global $user; $roles = implode("+",array_keys($user->roles)); return $roles; 这行代码呢?另外如果显示的是某标签的用户呢,比如发表一篇文章同一个类的用户都可以看,其他类的不行,这个怎么写??
$user->roles 是array, key 是 role_id
不明白你的問題, "某标签的用户"?
你可以試試我的views export 主要是用一個
你可以試試我的views export
主要是用一個 role argumments, default value 給php code
php 讀$user, $user->roles 有角色id
主要的一句php
<?php $roles = implode("+",array_keys($user->roles));?>views import (你要自己加page/block)
<?php$view = new view;
$view->name = 'role_arg_test';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'title' => array(
'label' => 'Title',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
'name' => array(
'label' => 'Name',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_user' => 1,
'overwrite_anonymous' => 0,
'anonymous_text' => '',
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
'rid' => array(
'label' => 'Roles',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'strip_tags' => 0,
'html' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'type' => 'separator',
'separator' => ', ',
'exclude' => 0,
'id' => 'rid',
'table' => 'users_roles',
'field' => 'rid',
'relationship' => 'none',
),
));
$handler->override_option('arguments', array(
'rid' => array(
'default_action' => 'default',
'style_plugin' => 'default_summary',
'style_options' => array(),
'wildcard' => 'all',
'wildcard_substitution' => 'All',
'title' => '',
'breadcrumb' => '',
'default_argument_type' => 'php',
'default_argument' => '',
'validate_type' => 'none',
'validate_fail' => 'not found',
'break_phrase' => 1,
'add_table' => 0,
'require_value' => 0,
'reduce_duplicates' => 0,
'id' => 'rid',
'table' => 'users_roles',
'field' => 'rid',
'validate_user_argument_type' => 'uid',
'validate_user_roles' => array(
'2' => 0,
'7' => 0,
'6' => 0,
'5' => 0,
'4' => 0,
'3' => 0,
),
'relationship' => 'none',
'default_options_div_prefix' => '',
'default_argument_user' => 0,
'default_argument_fixed' => '',
'default_argument_php' => 'global $user;
$roles = implode("+",array_keys($user->roles));
return $roles;',
'validate_argument_node_type' => array(
'location' => 0,
'page' => 0,
'story' => 0,
),
'validate_argument_node_access' => 0,
'validate_argument_nid_type' => 'nid',
'validate_argument_vocabulary' => array(
'1' => 0,
),
'validate_argument_type' => 'tid',
'validate_argument_transform' => 0,
'validate_user_restrict_roles' => 0,
'validate_argument_php' => '',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'type' => 'ul',
));
?>
--------------------------------
Joetsui's blog
非常感谢这位大哥
非常感谢这位大哥,不过代码好长啊!!我PHP不是太懂,偶是VB出身滴人啊。就是想问下能不能自己在VIEW下设置呢?过滤功能+Arguments能否解决这件事?我的意思是尽量少些代码!再次感谢这位大哥
ozp
你import 了之後,
你import 了之後, 就沒有代碼了
我手寫的都只有三行code
一句一句教你如何設置的話, 不如你import 了, 自己看看便會明白
--------------------------------
Joetsui's blog
我导入了,但是显示Unable to interpret view code.
我是在VIEWS选择导入,在Paste view code here:*这里复制了你上面的代码,可是就显示导入不了,怎么回事??帮忙啊
ozp
Unable to interpret view
Unable to interpret view code.
在views中,点import导入这段代码。显示无法导入。
要导入。是不是要先建一个这样的内容类型,或是开启哪些模块?
可以成功了,只要把开头结尾的PHP标志去掉就可以了。
不过能否解释下关于global $user;
$roles = implode("+",array_keys($user->roles));
return $roles;
这行代码呢?另外如果显示的是某标签的用户呢,比如发表一篇文章同一个类的用户都可以看,其他类的不行,这个怎么写??
ozp
$user->roles 是array, key 是
$user->roles 是array, key 是 role_id
不明白你的問題, "某标签的用户"?
--------------------------------
Joetsui's blog