欢迎各位兄弟 发布技术文章
这里的技术是共享的
这个是 api https://api.drupal.org/api/views/docs!docs.php/function/hook_views_pre_view/6
function view_sorter_views_pre_view(&$view) {
if ($view->name == 'MOST_RECENT') {
$view->display['default']->handler->options['sorts']['title']['order'] = 'DESC';
}
}
Hi. Here I'll show you how to alter views filters dynamically with hook_views_pre_view().
This hook is called at the very beginning of views processing, before anything is done.
The best way to alter filters.
1234567891011121314151617 | <?php /** * Implementation of hook_views_pre_view(). */ function mymodule_views_pre_view(&$view, &$display_id, &$args) { if ($view->name == 'myview') { // get our filters $filters = $view->display_handler->get_option('filters'); // for example, unset one. unset($filters['myfilter']); // apply changes $view->display_handler->override_option('filters', $filters); } } |
来自 http://d.danylevskyi.com/node/9
//这里用 hook_views_pre_view 过进行过滤
function execself_views_pre_view(&$view, &$display_id, &$args)
{
if($view->name == 'event_list')
{
global $user;
////部门中文值
$departValue = db_result(db_query("select pro_val.value from profile_values as pro_val
where pro_val.uid='%d' and pro_val.fid=2 ", $user->uid));//fid为2就是表示所属部门
$departArrs = _getDevArr();
$departKey = array_keys($departArrs,$departValue); //得到部门的英文键 en|cn 英文是键,中文是值
$filters = $view->display_handler->get_option('filters');
//var_dump($filters['field_to_development_value']['value']);exit;
$filters['field_to_development_value']['value'] = $departKey;
$view->display_handler->override_option('filters', $filters);
}
}
function zipcode_filter_views_pre_view ( &$view, &$display_id, &$args) {
$view = views_get_view('baby_clothes_pages');
$view->set_display('default');
$view->set_exposed_input(array('postal_code' => $zipcode));
$view->display['default']->handler->options['title'] = $title;
}
function zipcode_filter_views_pre_view ( &$view, &$display_id, &$args) {
$view->display['default']->handler->options['title'] = "this is the new title";
$view->exposed_input['distance']['postal_code'] = $_SESSION['zipcode_filter']['zip'];
$view->exposed_input['distance']['search_distance'] = $_SESSION['zipcode_filter']['distance'];
}