Forums

How to use data in php-code within ACTION

JohnVosDev 05 Feb, 2015
Hello,

I want to do some calculations in the ACTION from the Front List.
I saw on the forum:

<?php
pr($this->data);
etcetera....

If I use this the whole Arra is displayed correct.
But I want to use some fields.
I have tried to get the value of a field by using this statement: $int1 = $this->data['Veiligheid'];
Unfortunately the result is an empty field.

What am I doing wrong?

Please Help.
GreyHead 05 Feb, 2015
Hi JohnVosDev,

Using the pr() code will just dump the data - this is useful to see what is in the data object and what it is called. (it may help to click 'View page source' in your browser to see a better formatted version).

In my tests $this->data doesn't exist - I just get an error message.

If you need to know what is there then this code will show you the data in the current listing:
<?php
echo'<div>$this->view->vars[rows]: '.print_r($this->view->vars['rows'], true).'</div>';
?>
and the result looks like this (this is a very simple listing just showing the title from the contents table:
Array
(
    [0] => Array
        (
            [content] => Array
                (
                    [title] => Getting Started
                )

        )

    [1] => Array
        (
            [content] => Array
                (
                    [title] => My first article
                )

        )

    [2] => Array
        (
            [content] => Array
                (
                    [title] => Test article
                )

        )
So the title of the first row would be in $this->view->vars['rows'][0]['content']['title']

I hope this helps a bit.

Bob
JohnVosDev 05 Feb, 2015
Dear Bob,

In my case.
If I code:
echo'<div>$this->view->vars[rows]: '.print_r($this->view->vars['rows'], true).'</div>';
the result is only the text $this->view->vars[rows]:
and no content.

If I code:
pr($this->data);
the result is the dump as giving next.

My question is how can I use the content of the field VEILIGHEID.
In my case the value 10.

Array
(
    [M1] => Array
        (
            [Beoordeling_id] => 8
            [created] => 2015-02-05 10:09:07
            [modified] => 
            [Beoordelaar] => johnvos
            [IdeeNummer] => 1
            [Veiligheid] => 10
            [Duurzaamheid] => 10
            [Ecologie] => 10
            [LifecycleKosten] => 10
            [Bruikbaarheid] => 10
            [Toekomstgerichtheid] => 10
            [ToelichtingPark] => 
            [Inpassing] => 9
            [Service] => 9
            [DuurEffect] => 9
            [StijlVormgeving] => 9
            [ToelichtingVerfraaiing] => 
            [DraagvlakDoelgroep] => 10
            [Initiatieven] => 10
            [Doelgroepen] => 10
            [ToelichtingDraagvlak] => 
        )

    [cont] => lists
    [ccname] => ToonBeoordeling
    [act] => view
    [gcb] => 8
)
JohnVosDev 05 Feb, 2015
I have found the solution.
I have to use:

$int1 = $this->data['M1']['Veiligheid'];

Thanks for the TIP
GreyHead 05 Feb, 2015
Hi JohnVosDev,

Well done - I see I was testing using the Header box and not the Actions box :-(

From your output $this->data['M1']['Veiligheid'] should have the value you want.

Bob
MainsailSoftware 17 Feb, 2015
Bob,

Is there a short-hand notation similar to {Model.field} that I have seen in ChronoForms that can be used in the Header box instead of inserting PHP code in the HTML?

Jim
GreyHead 18 Feb, 2015
1 Likes
Hi MainsailSoftware,

Not that I know of - but there might be something I haven't found yet . . .

Bob
This topic is locked and no more replies can be posted.