many to many - List object properties delimited by comma in CodeIgniter with DataMapper OverZealous Edition -
i have 2 classes - students , groups many-to-many relationship. on student page, want show details , list groups belongs to, delimited comma. students controller:
class students extends controller {    function  __construct() {       parent::__construct();   }    function index() {       $this->get_all_students();   }    function get_all_students() {       $s = new student();       $data['students'] = $s->select('id, name, email')->get();        $this->load->view('students', $data);   }    function view($id) {       $s = new student();       $s->get_by_id($id);       $s->groups->get();        $data['student'] = $s;        $this->load->view('student_view', $data);   } }   i can student's details in student_view:
name: <?php echo $student->name; ?> e-mail: <?php echo $student->email; ?> groups:  <?php foreach ($student->groups $group) : ?>   <?php echo anchor("/groups/$group->id", $group->name) ?> <?php endforeach; ?>   so, how can list groups delimited comma? tried adding group names array in controller , <?php echo implode(', ', $groups); ?> in view. way cannot make link using group ids.
<?php echo anchor("/groups/$group->id", $group->name) ?>    should become ( see comma @ end of line )
<?php echo anchor("/groups/$group->id", $group->name) ?> ,   or display user groups list :
<?php foreach ($student->groups $group) : ?>   <?php echo anchor("/groups/$group->id", $group->name) ?> <?php endforeach; ?>   should become
<ul> <?php foreach ($student->groups $group) : ?>   <li><?php echo anchor("/groups/$group->id", $group->name) ?></li> <?php endforeach; ?> </ul>      
Comments
Post a Comment