21309 Posts in 5738 Topics by 2603 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 705 Views |
-
String variable cannot stand on both sides of assignment

29 October 2009 at 1:56am Last edited: 29 October 2009 1:59am
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. -
Re: String variable cannot stand on both sides of assignment

29 October 2009 at 6:12pm
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 ', ';
.. -
Re: String variable cannot stand on both sides of assignment

4 November 2009 at 10:44pm Last edited: 4 November 2009 10:49pm
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.
-
Re: String variable cannot stand on both sides of assignment

4 November 2009 at 11:08pm
I have now changed all of my database to use utf8_general_ci, but that didn't work.
I use the assignmentand the Name() function looks like this:$result .= $author->Name() . ', ';
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. -
Re: String variable cannot stand on both sides of assignment

25 November 2009 at 11:40pm
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!
| 705 Views | ||
|
Page:
1
|
Go to Top |


