Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

concatenate array


Reply


5 Posts   1438 Views

Avatar
bebabeba

Community Member, 193 Posts

6 March 2009 at 6:21am

Hi!
I have this problem. I print result of my query as cicle. I nedd to concatenate to $doSet array an other array $pag that I need to print only one.
If I insert $pag in my $record array every cicle of function I print $pag value. I want see it only one.

function Query()
$doSet = new DataObjectSet();
foreach($rec as $key)
{
          
$record = array(
'Id' => $key['id'],
'Nome' => $key['mm_tourist_name'],

);
$doSet->push(new ArrayData($record));

}
return $doSet;

<% if Query %>
<ul id="liste">
             <% control Query %>
            
             <li>
               <div class="..">$Nome</div>
               <div class="..">$Id</div>   
               </li>
               $pag
             <% end_control %>
            
             </ul>
                
             <% end_if %>

Avatar
Jardiamj

Community Member, 17 Posts

6 March 2009 at 7:57pm

Hello! I'm not sure if I understood well your problem. You want to print $pag which is a array only once in the template, so why are you placing it inside the control?. Can't you call it out of the control?.
I'm quite new to SS and PHP. But I'll try to help if I can.

Avatar
bebabeba

Community Member, 193 Posts

6 March 2009 at 8:36pm

Hi Jardiamj!
I try to put my $pag out of cicle ina this way but I can see $pag value..any idea?

<% if Query %>
<ul id="liste">
<% control Query %>

<li>
<div class="..">$Nome</div>
<div class="..">$Id</div>
</li>

<% end_control %>

</ul>
$pag
<% end_if %>

Avatar
bebabeba

Community Member, 193 Posts

6 March 2009 at 9:06pm

an other solution was this but don't work..

$doSet->push(new ArrayData(array($record, 'pagination' => $pag));

Avatar
Jardiamj

Community Member, 17 Posts

7 March 2009 at 6:23am

Hello bebabeba!
Where is you variable $pag? I can't see it in your first post.
is it related with your query results?, I think yes. Because you could create another function to get this data and then call it in your template.
Or as I can see you were trying to push it inside your array. And then you could call it in you template like $Query.pagination or use it inside a control block if it is an array like <% control Query.pagination %> <% end_control %>.

If you can send me the whole code I will take a look at it.
Bye.