Jump to:

23370 Posts in 18160 Topics by 2864 members

General Questions

SilverStripe Forums » General Questions » concatenate array

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

Page: 1
Go to End
Author Topic: 1363 Views
  • bebabeba
    Avatar
    Community Member
    192 Posts

    concatenate array Link to this post

    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 %>

  • Jardiamj
    Avatar
    Community Member
    17 Posts

    Re: concatenate array Link to this post

    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.

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: concatenate array Link to this post

    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 %>

  • bebabeba
    Avatar
    Community Member
    192 Posts

    Re: concatenate array Link to this post

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

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

  • Jardiamj
    Avatar
    Community Member
    17 Posts

    Re: concatenate array Link to this post

    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.

    1363 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.