Hi there :)

I tried to get the views result as array for use with smarty engine.

In template.php I did:

$view = views_get_view('portfolio_projects_all');
$view->render();
$dataArr = $view->result;

so I could assign the var with the function "smarty_preprocess (&$variables, $hook)"...

But the $dataArr does'nt contain data I need.

Is there another callable function that returns me an array within all fields?

thx for reply!
melchior

Comments

merlinofchaos’s picture

You should probably just call ->build() rather than ->render().

That said, I don't understand why $view->result would not contain the data you need. It's the raw data, of course, not the rendered data (in either case) but $view->result is the only thing that will provide what it sounds like you're looking for.

merlinofchaos’s picture

Status: Active » Postponed (maintainer needs more info)
domesticat’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Performing a mass closing of all issues over 180 days old. Please reopen if needed.

hassan.abudu’s picture

Status: Closed (fixed) » Active

Reopening, now with more detail.

I'm trying to output the views result as XML. I'd like to get an array of the results, manipulate them, and then theme the final results as XML at the end. I'm getting the result array of the view by doing this:

	views_include('view');
	$view = simple_link_view(); // this function returns my view
	$view->init_display();
	$view->pre_execute();
	$view->execute();
	$view_result = $view->result;

The result of this is:

Array
(
    [0] => stdClass Object
        (
            [nid] => 9187
            [node_title] => test new link
            [node_data_field_simpletitle_field_simpletitle_value] => test new link
            [node_type] => simplelink_promo
            [node_vid] => 40465
        )
    [1] => stdClass Object
        (
            [nid] => 9188
            [node_title] => test new link 2
            [node_data_field_simpletitle_field_simpletitle_value] => 
            [node_type] => simplelink_promo
            [node_vid] => 40470
        )
)

But if instead of $view->result I do:

        print ($view->render());

This is the result list:

	Nid: 9187
	Title: test new link
	Link Text: test new link
	Open in New Window: true
	URL:
	  www.abc.com
	  www.cnn.com
	flexifield_test:
	File: application/xml new__30.xml
	Open in New Window: false
	File: image/jpeg devishes.jpg
	Open in New Window: true
	
	Nid: 9188
	Title: test new link 2
	Link Text:
	Open in New Window: true
	URL:
	  www.abc.com
	  www.bbc.co.uk
	flexifield_test:
	File: image/jpeg devishes.jpg
	Open in New Window: false
	File: application/xml new__30.xml
	Open in New Window: false

In other words, if none of the multiple value fields are displayed, nor (bizarrely), the Open in New Window field. I think this is the issue the threadstarter saw.

I've been looking through the views code, but I can't for the life of me see how the display handler is fetching those extra results. If anyone knows more about this issue, keep us all posted.

Also, I'm thinking of theming the $view->render() results, and then parsing out the data I want. I don't want to create a separate views template, as simple_link_view() returns a view that is dynamically generated. Any assistance would be much appreciated.

Regards,
Hassan

merlinofchaos’s picture

Status: Active » Fixed

The display handler does not fetch those extra results, the field handlers do, and they use the pre_render() method to do it.

You might also look at $view->style_plugin->rendered_fields() after you call $view->render().

hassan.abudu’s picture

Status: Closed (fixed) » Fixed

Thanks very much! I couldn't call rendered_fields like a function, but as a variable, it worked like a charm. :-)

One last question as part of the array of results, I get:

[field_simpleurl_value] => <div class="field-item field-item-0">www.abc.com</div><div class="field-item field-item-1">www.cnn.com</div>

Is there a way to theme these rows using real-time functions instead of tpl.php files?

merlinofchaos’s picture

Unfortunately I'm afraid not. That markup, I think those are actually being themed by CCK anyway, so you'd have to intercept its theming.

hassan.abudu’s picture

Status: Fixed » Closed (fixed)

Thanks for all your help!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.