How do I display the values of an array and wrap in tags?

thread: 3 messages  |  last: a year ago  |  started: friday, february 26, 2010, 8:43 am pst


#1  |  kingwithin (San Francisco, CA) United States of America
Friday, February 26, 2010, 8:43 AM PST

In the controller I define the following:

$codes = $this->objUser->GetGroupCodeArray();

In the corresponding template (btw, I may want to move this functionality on the header which is included in every page, how do I get it to do that?), I have the following:


foreach($codes as $code)
  echo '<a href="whatever.php">'.$code.'</a>';

My desired result is that this array which has a bunch of code with a many-to-many association to the user (a user can have many codes, and each code can have many users), is output with the a-tag wrapped around each one individually with a dynamic href.

But I get an error:

Fatal error: Method GroupCode::__toString() must not throw an exception

Help?

#2  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Friday, February 26, 2010, 2:07 PM PST

$code is an object -- I'm guessing what you want to echo out is an individual property in your $code object.

If that's the case, you need to specify which property of the $code object you want to echo out.

#3  |  kentpachi (France, EU) France
Monday, March 1, 2010, 1:21 AM PST

also in a a debugging way you could use var_dump($cod);

or


echo "<pre>";
print_r($code);
echo "</pre>";

hth



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.