By KhaledBlah on
Hello,
I am trying to figure out a way to render a certain view display in my module. Here is the code I am using but it doesn't work.
$view = views_get_view('view name');
print $view->render('display id');
This, however, executes for 30 seconds and then PHP stops saying that the execution limit has been reached. Anyone have a tip for me what I am doing wrong? FYI, I have views caching disabled.
Regards,
Khaled
Comments
I've managed to get my code
I've managed to get my code working by changing it the way described below. I hope this helps someone else with the same problem and I would still be interested in comments from other developers!
Question about Implementation
I am looking to do something similar, so what made this work for you? Do you need to have the pre_execute?
Your code works for me, but in addition to the results of the view, I am getting edit, export, and clone links.
hover links
After looking around I see that you can disable these buttons via:
Administer -> Site Building -> Views -> Tools (Tab) -> Do not show hover links over views.
But I don't want to get rid of these all together, they are useful.
Yes, the pre_execute() call
Yes, the pre_execute() call was needed indeed.
Not working from controller
Hi,
This is not working from my controller :(
Any suggestion?
Thanks
.
Why not use views_embed_view('view_name', 'display_id') ?
Good question, Raf. I haven't
Good question, Raf. I haven't been programming very long with Views so I may have overlooked this function. I'll have a look at it. Thx for letting me know.
Thanks
I am also using views_embed_view now. It works great, thanks for the tip.
Seeting exposed filters
Is there some way to also include exposed filter values when rendering a view programmatically?
Something like but working? This does not work..is does render the view but the filters is not applied to the result...?!
Same problem
I am having the same problem, I have tried rendering the view using views_embed_view and $view->preview function. But in both cases, the exposed filter did not work. It gets rendered but wont work for the first time. One thing I noticed is the, though the filters are getting populated, but the exposed filter form is not. It only comes once I navigate to the 2nd page using my AJAX pagination. Then it starts coming for all pages. Actually besides this exposed filter form, I have another form in that page. I am not sure if the problem is because of that.
Any help?
-- Pratip Ghosh
Cleaner way
A cleaner way to do this can be found here:
http://drupal.stackexchange.com/questions/8369/how-do-i-programmatically...
-------------------------------------------------
take a look -> www.altrugon.com
called a block view on the custom page
<?php
/**
* @file
* Module file for student.
*/
/*
* Implement hook_help().
*/
function student_help($path, $arg){
switch($path) {
case 'admin/help#student':
return '
' . t('student') . '
';
}
}
/**
* Implement hook_menu().
*/
function student_menu() {
$items = array();
$items['student-details'] = array(
'title' => 'Student Details',
'page callback' => 'student_view',
'access callback' => TRUE,
);
return $items;
}
/**
* Menu callback function.
*/
function student_view() {
$blockObject = block_load('views', 'student-block');
$block_render_blocks = _block_render_blocks(array($blockObject));
$block_get_renderable_array = _block_get_renderable_array($block_render_blocks);
$output = drupal_render($block_get_renderable_array);
return $output;
}
$view = views_get_view(