Forums

Using PHP code in CC view action

ArnKor 09 Nov, 2015
Hello,

i am stuck. How can i get my PHP code working? I am trying to extract image names from one of my fields to generate HTML:

<?php
$fotostring  = $form->data['file_upload_fotos'];
$fotos = explode(",", $fotostring);
echo $fotostring;

foreach ($fotos as &$value) {
    $HTMLString  = $HTMLString . "<p><img src='images/ambiente_creator/{article_model.user_name}/$value' alt='' />" ;
}
echo $HTMLString;
?> 


It seems that i am using the wrong code at the first line ($form->data['file_upload_fotos']). How to access the fields listed in >Columns list< to get the image names from the String?

Thanks & kindest regards,
AK
GreyHead 09 Nov, 2015
HI AK,

What is the variable you are passing to the View - usually that is a parameter gcb=record_id ?

If so then you can use a DB Read action to load that record, then your code should work.

Bob
ArnKor 09 Nov, 2015
Hello Bob,

thanks for your reply!

HI AK,

What is the variable you are passing to the View - usually that is a parameter gcb=record_id ?

If so then you can use a DB Read action to load that record, then your code should work.

Bob



I think i did not ask correctly:

I am in CC > Front List > Actions > view

There is a code box where i entered the php code shown. But i do not know how to get the list fieldarticle_model.file_upload_fotos ([model_ID].[COLUMN LIST FIELD]). So i am trying to get the content of the variable as follows:

<?php
$fotostring  = $form->data['file_upload_fotos'];
but this seems to be wrong.

I do not understand how to use a DB read action here nor the variable you are talking about.

Could you give me an example regarding my code. Please see screenshot for line of code where i am trying to get the field data.
GreyHead 09 Nov, 2015
Answer
Hi Ak,

Sorry, I misunderstood :-(

The data there isn't in the $form->data[''] array. You should be able to access it from $this->data though. So please try your code with
<?php
$fotostring  = $this->data['article_model']['file_upload_fotos']; // change this line
$fotos = explode(",", $fotostring);
echo $fotostring;

foreach ($fotos as $value) {
    $HTMLString  = $HTMLString . "<p><img src='images/ambiente_creator/{$this->data['article_model']['user_name']}/{$value}' alt='' />" ; // and this line
}
echo $HTMLString;
?> 
I may not have the model IDs correct here.
Bob
ArnKor 09 Nov, 2015
Hi Bob,

Hi Ak,

Sorry, I misunderstood :-(
Bob



it was my fault! Your shown solution works perfectly!

Many thanks & kindest regards,
AK
This topic is locked and no more replies can be posted.