Forums

Work with 3 model data, custom display

francosdad 16 Dec, 2015
Hello again,


after I successfully finished the db save / multi save, I now work on displaying data saved to the database.

As seen in the attached screenshot 'Frontend' I'm able to display the data in a table. Now I would like to work with the data befor I display it.

The data which eventually is displayed consists of three models
[list=]
[*]CampaignCore
[*]CampaignEntities
[*]CampaignTypes
[/list]

The relations are as follows:

CampaignEntities (belongsTo) -> CampaignCore and is referenced by foreign key id
The Join condition is
<?php
return array('CampaignEntities.campaign_id = CampaignCore.id');
?>

CampaignTypes (belongsTo) -> CampaignEntities and is referenced by foreign key id
The Join condition is
<?php
return array('CampaignTypes.id = CampaignEntities.type_set_id');
?>


What I would like to know is how I can access the data returned from the Database to work with it and afterwards display it with the custom list view.

I struggled to find a variable to put into var_dump or print_r? Would be $form->data in CF but this does not seem to work in CC (as it is database results we are dealing with).

I will prepare a mockup of how the data should look like at the end, maybe this helps to get what I try to do.
GreyHead 17 Dec, 2015
Answer
1 Likes
Hi JackPrince,

To see absolutely everything - you probably don't need this - add in the Header box:
<?php
echo '<div>$this: '.print_r($this, true).'</div>';
?>
then view the page source to see a structured version.

To see the basic list data including filters add in the Header box:
<?php
echo '<div>$this->view->controller->data: '.print_r($this->view->controller->data, true).'</div>';
?>


To see the returned data:
<?php
echo '<div>$this->view->vars[rows]: '.print_r($this->view->vars['rows'], true).'</div>';
?>


And the individual records are available in the Body box as:
<?php
echo '<div>$row: '.print_r($row, true).'</div>';
?>


All of these should only be used for debugging! Comment out or delete them before going live.

Bob
francosdad 17 Dec, 2015
Thanks Bob, your as awesome as always. I'll send you another coffee in the coming days. And will work on making a small tutorial to give something back. Maybe (after review) it will serve as a good example for a nice use case with CF & CC connected.
francosdad 31 Mar, 2016
Sorry to restart this/my old post. But I have a question

With the info given above on which place would I have to change configuration to group
all the CampaignEntities with a shared CampaignCore?

For example:
Campaigns:
[list]
[*] Campaign A
[*] Campaign B
[*] Campaign C
[/list]

Campaign A Entities:
[list]
[*] Entity 1 of Type X
[*] Entity 2 of Type Y
[*] Entity 3 of Type Z
[/list]

I attached a screenshot. I'd basically like to change the hole thing to be more grouped.

All Entities with a shared Core (and type) be grouped like this
$array[CampaignCore][CampaignTypes][{n}]

Somehow I seem to still have some kind of misconception of how the models in CC interact with each other.

Any help appreciated.
This topic is locked and no more replies can be posted.