Jump to:

23471 Posts in 18937 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » String variable cannot stand on both sides of assignment

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: 861 Views
  • Pipelynx
    Avatar
    Community Member
    4 Posts

    String variable cannot stand on both sides of assignment Link to this post

    This is the code I'm using:

    public function getAuthorsString($authors) {
    $result = "";
    if ($authors->exists())
    foreach ($authors as $authorKey => $author) {
    $result = $result."{$author->ForeName} {$author->SurName}, ";
    }
    $result = rtrim(trim($result), ",");
    return $result;
    }


    The $authors variable is a DataObjectSet, and this line is the problem:

    $result = $result."{$author->ForeName} {$author->SurName}, ";


    I also tried:

    $result .= "{$author->ForeName} {$author->SurName}, ";


    And:

    $result = "{$result}{$author->ForeName} {$author->SurName}, ";


    None of them work. But if I only assign without maintaining the last value, therefore ultimately returning only the last author:

    $result = "{$author->ForeName} {$author->SurName}, ";


    It works perfectly fine.
    The error I'm getting is this:

    error on line 33 at column 266: Encoding error


    Please help me, I have no idea what to do.

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: String variable cannot stand on both sides of assignment Link to this post

    What are you trying to output? I assume you would want something like "John Smith, Joe Bloggs".

    I'm also assuming that author isn't a Member object (because then you could just use $member->Name).

    I would write that concatenation like

    ..
    $result .= $author->ForeName . ' ' . $author->SurName ', ';
    ..

  • Pipelynx
    Avatar
    Community Member
    4 Posts

    Re: String variable cannot stand on both sides of assignment Link to this post

    EDIT: I deleted this post because I realized I was/am stupid >_> The error should be exactly what it said it was: A problem with the encoding in the database. I'm gonna investigate and post again.

  • Pipelynx
    Avatar
    Community Member
    4 Posts

    Re: String variable cannot stand on both sides of assignment Link to this post

    I have now changed all of my database to use utf8_general_ci, but that didn't work.
    I use the assignment

    $result .= $author->Name() . ', ';

    and the Name() function looks like this:

    public function Name() {
    $result = $this->ForeName . ' ' . $this->SurName;
    return $result;
    }


    The error seems to occur when a string pulled from the database hits a string defined in my code, but I have no idea what to do about it.

  • Pipelynx
    Avatar
    Community Member
    4 Posts

    Re: String variable cannot stand on both sides of assignment Link to this post

    I have now changed servers and am working with a fresh mysql database and look what happened! I can't even use simple strings anymore without producing an Encoding Error. My template looks like this (this is inside a <table>):

    <% control CatalogueMedia %>
    <tr>
    <td>$Title</td>
    <td><% control Authors %>
    $ForeName $SurName,
    <% end_control %></td>
    </tr>
    <% end_control %>


    So i tried this, and the usual Encoding Error popped up. Then I replaced the inner <% control %> with static text, but $Title alone produced the error again! I then replaced $Title with static text and got exactly as many table rows as I have entries in my table. What is going on? I have no idea what to do at this point. Please help me!

    861 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.