Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.0-beta4
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Jun 2008 at 06:06 UTC
Updated:
12 May 2011 at 20:04 UTC
Hi,
I installed views 6.x-2.0-beta4 and I am able to create views. But when I tried to insert view into my page, I keep getting this error:
Fatal error: Call to undefined function views_build_view() in /home/viacitc/public_html/includes/common.inc(1537) : eval()'d code on line 14
Here is my code:
$view_name = 'comments_recent'; //name of view
$limit = 3; // number of returns
$view_args = array();
$view = views_get_view($view_name);
views_build_view('embed', $view, $view_args, false, 15);
Could somebody please help?
Comments
Comment #1
merlinofchaos commentedviews_build_view doesn't exist in Views 2.
Try
instead.
Comment #2
chenys_jason commentedit works. Thanks!
Comment #3
merlinofchaos commentedComment #4
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #5
doublejosh commentedHi. Doing my first view embeds in 6 and moving from views_build_view() which I used in 5.
When using views_embed_view() I'm curious about passing arguments and such things within a display_id
For now I'm using this (because it works)...
...but I have a sneaking suspicion it's not the best practices solution.
Thanks Mr. Chaos ;)
Comment #6
merlinofchaos commentedNo, it expects the arguments as a series of arguments, not an array of them.
If you need to do it that way, just break the function down and do what views_embed_view() does. views_embed_view is not a complex function.
Comment #7
tchouk commentedHi,
I am using the following code in my .module document under the form that displays my content but it doesn't give me the required view:
$view_name = 'Chanel'; //name of view
$limit = 3; // number of returns
$view_args = array();
$view = views_get_view($view_name);
views_embed_view($view_name,'default');
Should I add a permission or something like that? Or add 'print' before 'views_embed_view'?
Thanks for replying...
Comment #8
Ghostthinker commentedHi,
You can also do it this ways (more like d5):
Have a llok at the contrib api http://drupalcontrib.org/api/function/views_embed_view
Comment #9
doublejosh commentedThis is an ancient thread, but looks like this ability was potentially removed.
My use case is to take advantage of the views UI and configurations, etc. in order to create a list things, but actually call upon that view in PHP code to do the output via another means. I used to use views_build_view() to accomplish grabbing the content of a view and then doing other things with it. It's nice to leave the query building to views and just made use of the results.
Since $view->preview returns HTML rather than an array of item, is there a way to do this in D6 and/or D7?
Comment #10
dawehnerThere is views_get_result_view if you need the actualy output of a view.
Everything else can be done with the preview() function and more stuff.