how to add new datas and new data fields in an existing model

How to add new data fields to an existing CF model for export.

Overview

The issue occurs because calculated data is stored in a separate array instead of the existing model retrieved by a database read action.
Ensure the data is stored directly into the existing model array by using the correct index syntax to match the model structure.

I need to know something about models in cf V7 and V8.

I have a piece of code with some value calculated with datas which are stored in a model named Carac_d  model retrieved by a db read action. These calculated datas are not stored directly in the database because they have nothing to do in because they are calculated.

After the db read i use this code in a custom php action . but the datas are stored in another model and not in the same as the read db action.

Both models have the same name I need to use them and store them in the same model array to use the in a xlsx export action and in a email action .

When i use this code in an email action, i can use both of the field directly in the mail body.

But i need a xlsx export of these data as attachement. So i try to add these with a custom php action before the xlsx export to made them as columns.how to modify these lines to achieve this and store the datas in new fields in model Carac_d?

		$this->data("Carac_d[$i].dev", $dev, true);
		$this->set("Carac_d.dev", $dev, true);
		$this->data("Carac_d[$i].nbplis", $nbplis, true);
		$this->data("Carac_d.dev", $dev, true);

I try with these lines but the values are stored in a new Carac_d array, not in the existing one, and i can't access them as columns in my export.

The piece of code i use to créate the data .

$uniqueRows = [];
$i = 0;
foreach ($this->get("Carac_d") as $row) {
    $uniqueKey = $row['a'] . '_' . $row['b'] . '_' . $row['c'] . '_' . $row['d'] . '_' . $row['e'];
    if (!isset($uniqueRows[$uniqueKey])) {
        $uniqueRows[$uniqueKey] = $row;
		$dev = $row['a'] + $row['b'] + $row['c'] + $row['d'] + $row['e'];
		echo "dev = " . $dev;
		$this->data("Carac_d.dev", $dev, true);
		$this->set("Carac_d.dev", $dev, true);
$nbplis = 0;
if ($row['a'] != 0) {
	$nbplis = $nbplis + 1;
}
if ($row['b'] != 0) {
	$nbplis = $nbplis + 1;
}
if ($row['c'] != 0) {
	$nbplis = $nbplis + 1;
}
if ($row['d'] != 0) {
	$nbplis = $nbplis + 1;
}
if ($row['e'] != 0) {
	$nbplis = $nbplis + 1;
}
$nbplis = $nbplis - 1;
		echo "nbplis = " . $nbplis;
		$i++;
		}
		}

Max_admin Max_admin 28 Feb, 2025

I think this what you should use:

$this->data("Carac_d.$i.dev", $dev, true);

Please try that and let me know

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fa fabrice.witkowski758 28 Feb, 2025
Answer

This doesnt semms to work the data are stroed in a carac_d array but not in the model of the db read.

I make a workaround in my case with a db save action in the previous page and a db in the page where i need these datas. I use the two db read actions as data source for my xslx export and in my email actions.

 [Carac_d] => Array
        (
            [0] => Array
                (
                    [ddev] => 1000
                )
        )
)
This topic is locked and no more replies can be posted.