Having a lot of difficulty trying to replicate a CC6 Repeater view In CF7. CF7 just seem like quite a downgrade in terms of functionality and programmability.
So we have a read_data (coded in PHP, but output in the same format as the read_data block), and the Repeater's Data Sources is set as {var:read_data}.
Within the loop, we can retrieve a row's variable by using {var:read_data.Model.#repeater.Field} in HTML. How can this be done in PHP? Tried the following with no success:
$field = $this->get("read_data.row.Model.Field");
$field = $this->get("read_data.#repeater.Model.Field");
$field = $this->get("read_data.[n].Model.Field");
$field = $this->get("repeater.row.Model.Field");
$field = $this->get("repeater.#repeater.Model.Field");
Why can't we use the old format {var:repeater.row.Model.Field}? That was so much simpler.
Yes, this makes CF7 unusable for me. In addition to the attempts you made I also tried the following:
$field = $this->get("read_data.1.Model.Field"); - Works as expected and returns value associated with row/key 1.
$field = $this->get("repeater.key"); - Works as expected and returns the current row/key in a loop.
$field = $this->get("read_data.repeater.key.Model.Field"); - Does not work.
The shortcode that accomplishes this works with a similar syntax and performs as expected.
{var:read_data.#repeater.Model.Field}
I suppose this is a bug or an oversight and hopefully it gets corrected.
what is the problem if the 1st and 2nd solutions work:
$field = $this->get("read_data.1.Model.Field"); - Works as expected and returns value associated with row/key 1.
$field = $this->get("repeater.key"); - Works as expected and returns the current row/key in a loop.
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Hi Max,
Thanks for the quick reply. Perhaps I am missing something very obvious.
This statement $this->get("read_data.1.Model.Field") is 'hard-coded' to return the value associated with key/index 1 in the loop that is being iterated. It works as expected but doesn't help because I want to access each value that is iterated in my loop - not just one. The statement $this->get("repeater.key") works and shows the appropriate key values as the loop is iterated but I cannot understand how to integrate with the other statement. What I need is the functional equivalent of the shortcode {var:read_data.#repeater.Model.Field} for PHP.
If I remember correctly the CFv4 PHP equivalent was $row["read_data"]["Model"]["Field"]. The CFv6 PHP equivalent was $this->get("read_data.row.Model.Field"). Both of these statements showed the value assigned to each key/index/row in the loop as it was iterated. How can I do this in CFv7?
Thanks Max,
John
The solution to making this work in PHP for CFv7 is not quite as straightforward as the way it worked in CFv6 but it can be set up to work pretty easily.
Simply assign the key/row number in the repeater to a variable and then use the variable in the function to process the appropriate record.
$row = $this->get("repeater.key","");
$field = $this->get("read_data.$row.Model.Field","");
John
Actually found a even more straightforward solution to this. The way to retrieve a row's field, is basically:
{var:Model.Field}
Eg.
Model name = "Article"
Field name = "published"
Then if {var:Article.published) is used within that specific row, it'll show that row's "published" field.