Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.9
Component:
Views Data
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
3 Dec 2008 at 00:31 UTC
Updated:
20 Mar 2014 at 13:28 UTC
Jump to comment: Most recent
Comments
Comment #1
Roi Danton commentedNevermind, I've got it with the render method (maybe there is another which needs less ressources?):
Comment #2
merlinofchaos commentedpreview() would probably be better.
Comment #3
merlinofchaos commented$view->preview() would probably be better than $view-render() rather.
Comment #4
Roi Danton commentedAh, okay, thx for the follow up! :)
Comment #5
Roi Danton commentedI have wrote a small tutorial so the module developer knows what to expect from the result array.
Comment #6
a_c_m commentedi just edited that tutorial to add some argument handeling code as well as changing ->preview() to ->execute() ... which i hope is correct still.
Comment #7
Roi Danton commentedWorks and it seems that the execute() method doesn't create HTML code like preview() (contains no information about rendertime). Though the Array size is only <1% smaller (e.g. 845496 vs 845510 Byte) its more correct that way. Thx!
EDIT:
However, the disadvantage is that execute() doesn't accept arguments as parameter. If one wants include arguments on-the-fly than preview() has to be used.EDIT #2: I've seen you added it already.Comment #9
dropchew commentedHi sorry I have to reopen the thread but I notice using the method mentioned here http://drupal.org/node/342132, I was able to get only the 1st 10 results. My settings for the view (flag actually) was set to 20 but its seems to ignore it? Thanks.
Comment #10
merlinofchaos commentedUse $view->pre_execute() to get the pager settings properly used.
Comment #11
dropchew commentedThanks for your reply.
Is there any document I can refer to with usage examples? I can't seem to find anywhere with search...still new to views 2 api..tks : )
edit: I just found out the method on the api page
For example, set items to 20 instead of default 10
Comment #12
Roi Danton commentedSo $view->execute() doesn't heed the pager settings therefore you recommended $view->preview() in #3? Does the following code heed the pager settings properly?
If yes maybe it's better to use the preview() method though?
Comment #13
merlinofchaos commentedYes, calling pre_execute() prior to execute() works. The advnatage to using pre_execute() and then execute() is that you won't spend time rendering a view you won't display, so I would encourage using whichever method works best for you.
Comment #14
mmilo commentedBased on http://drupal.org/node/342132, after looking through the Views2 code, I've found that this will only work for me if I use
Without
$view->init_display(), the handlers for the displays seem not to have been initialized, but the Views2 code is calling the pre_execute() on those (non-existent) handlers.Is using
$view->init_display()a bad idea?Comment #15
merlinofchaos commentedinit_display() is safe to use. It is a good idea.
Comment #17
Roi Danton commentedIt seems that the creation of the result array in view::execute() doesn't heed overridden display settings or displays at all. E.g. we use a display with id my_display which has different filter settings than the default display of the view. When loading the result array with
this array still contains the items of the default display. I'm continuing looking for a solution but maybe someone can give a helpful hint.
Comment #18
dawehneryou could at least try out
Comment #19
Roi Danton commentedI'm sorry, it was my fault. The version posted in #17 works! (#18 works too, but it is enough to use init_display instead of set_display then)
I just had problems to retrieve the correct display id. Is there another way than that described here with the default views GUI (?):
I've updated the tutorial accordingly. Instead of set_display and set_arguments it'd also be possible to use
Comment #20
Roi Danton commentedThe keys for CCK fields are assigned with a bad behavior. Always the name of the CCK field with the lowest weight (first appearance) is appended to node_data_ followed by the name of the current field.
Example with two fields field_text and field_numberfloat.
field_text has lowest weight:
field_numberfloat has lowest weight:
This behavior is annoying when processing the view result. Is this by design?
Comment #21
dawehnerdid you looked once at the views query, it's something incredible powerful but dynamic! so the tables have to have names like this.
so at the end i think this is by design
Comment #22
karens commentedThis is by design. Views automatically checks to see if any of the fields share a table, and if so, the table only gets added in once. That means the table has the first name assigned to it. The previous behavior joined in a new table in for every field, which gave you the names you are expecting to see, but made for a much less efficient query.
Comment #23
Roi Danton commentedThanks for the explanation. Has been added to the tutorial.
Comment #24
indiralanza commentedHi
I need to recover the related nodes involved in a relationship, I dont know how to do it. Maybe I can make a db query to get the nodes references of other node, or working with views and accesing to the data of the view programally? I really need to solve it, I dont know how?? Please write back soon.
Comment #25
czeky commentedHi, thanx for a way from my problem, now just how to print this..
doesn't work..
thank You, would be big helper for me
Comment #26
Chad_Dupuis commentedI use something like the following in the php footer:
Comment #27
dawehnerHe asked the some question in another issue, and there the answer was given.
Comment #28
alisamar commentedHi i'm developing themes and views result is sometimes very complicated and unnecessary...
i need only
but problem is ; Fields -> Node: Title is link to node and i'm trim this field to a maximum length (34)
how can i render that options ?
Comment #29
OnkelTem commentedHi all.
I have 2 CCK image fields in a View on 1 Default display with "Fields" output.
Now.
When I run either:
$result = views_get_view_result($name, NULL, $args)
or:
$view = views_get_view($name);
$view->pre_execute($args);
$view->execute();
$result => $view->result;
then $result array contains only ONE, first field from my fields and I have no any mention in the result about my second image field.
When I see Live Preview in Views UI or I run $view->preview(), HTML output contains BOTH the fields.
Debugging View execution showed that view query doesn't even contain second field in SELECT list. Its added somehow later.
So the question is - how can I get result array with ALL my fields?
Comment #30
dawehnerNULL, cannot be your display.
Comment #31
OnkelTem commentedThis makes no difference. Problem didn't go. Please reread more carefully what I'm asking.
Comment #32
dawehnerOK. Then you have a multiple cck imagefield. This values are stored in the handler.
If you execute your view you can find it in $view->fields['name']->items[$nid]
Comment #33
dawehner.
Comment #34
esmerel commentedComment #35
Gabriel R. commentedThis is actually a very interesting question and I am also interested in the answer.
While the code snippets above work, they only provide a list of IDs. How to make them go the whole way and render each field's value in an array elements?
Comment #36
dawehner#35:
http://drupal.org/project/views_php_array might do what you want.
Comment #37
esmerel commentedComment #38
Dood59 commentedDereine:
Thanks you that's what I looked for.
Comment #40
incaic commentedJust like OnkelTem from #29 above, I am seeing everything fine under views preview, but am not seeing any of my CCK fields (text, date, integer, etc) when I do the following:
$view = views_get_view($name);$view->init_display();
$view->pre_execute($args);
$view->execute();
$result => $view->result;
I get the following:
Even if I call preview() instead of execute() I still do not get any of my CCK fields returned.
I'm stuck on this and open to any/all ideas. Thanks!
(using views 6.x-2.12)
Comment #41
S.H.Wang commentedIn my individual view template ( I mean in my file: views-view--ViewName--page.tpl.php),
$view = views_get_current_view();
$vies->render(); //or $view->preview();
var_dump($v->result);
I got:
Fatal error: Maximum function nesting level of '100' reached
Only:
$view = views_get_current_view();
$vies->execute();
var_dump($v->result);
works correctly.