Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)

[eluser]RagaDaga[/eluser]
I have 2 classes - Students and Groups with many-to-many relationship. On a student page, I want to show all his details and list all groups he belongs to, delimited by comma. This is my Students controller:
Code:
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 get student's details like this in student_view:
Code:
Name: <?php echo $student->name; ?>
E-mail: <?php echo $student->email; ?>
Groups:
<?php foreach ($student->groups as $group) : ?>
  <?php echo anchor("/groups/$group->id", $group->name) ?>
<?php endforeach; ?>

So, how can I list groups delimited by comma? I tried adding group names to an array in the controller and then just
Code:
<?php echo implode(', ', $groups); ?>
in the view. But this way I cannot make a link using group IDs.

[eluser]theprodigy[/eluser]
[quote author="WanWizard" date="1289913574"]Which version of CI? I've read somewhere that 2.0 has an issue with the encryption library.

If you replace the encrypt/decrypt with something simple, like strtolower() and strtoupper(), does that work? If so, it's not a Datamapper issue, but a CI issue. I don't see anything obviously wrong with your code.[/quote]

It may be that. I am using CI 2.0. It's just weird that it has no problem with the login, which is comparing what they type in, with the decrypted version of what is in the database, but when going to output it once logged in, it does this. I guess I could revert back to 1.7.2 for this project, or just keep going an eye out and see if there is any update to CI before rolling out live.

I'll run a few simple checks when I get home tonight (doing the strtolower and/or another simple function). I'll let you know what I come up with.

[eluser]WanWizard[/eluser]
@RagaDaga,

You want the links separated by a comma? Why not simply do
Code:
<?php $first = TRUE;
foreach ($student->groups as $group)
{
    if ( ! $first ) echo ", ";
    echo anchor("/groups/$group->id", $group->name);
    $first = FALSE;
endforeach; ?>

[eluser]RagaDaga[/eluser]
oh, thanks!
any ideas why there is one space added after group name and thus before the comma? I checked, there is no spaces in database.

[eluser]Unknown[/eluser]
[quote author="WanWizard" date="1289624212"]A new version of Datamapper ORM has just been committed to Bitbucket.
Just click on "get source" to download the lastest version.

This version introduces a new extension to work with nested sets (used to store tree structures in a database). Not all planned functionality is present yet, but it's very usable. You can find the manual page for this extension here.

You'll find the complete changelog here.

Note that this version has been tested with today's version of CI 2.0. Although still no guarantees, we haven't found any problem.[/quote]

This definitely piqued my interest. I have a custom nested set implementation at the moment that is part of a larger DB schema that I was going to roll over to DMZ. With a little luck I might be able to do the entire thing in DMZ now...

[eluser]WanWizard[/eluser]
[quote author="RagaDaga" date="1289965079"]oh, thanks!
any ideas why there is one space added after group name and thus before the comma? I checked, there is no spaces in database.[/quote]
Probably because of a newline somewhere, all consecutive whitespace is reduced by the browser to a single space.

[eluser]WanWizard[/eluser]
[quote author="Chuck Liddell" date="1289966078"]This definitely piqued my interest. I have a custom nested set implementation at the moment that is part of a larger DB schema that I was going to roll over to DMZ. With a little luck I might be able to do the entire thing in DMZ now...[/quote]
Let me know what you think. The extension is still fairly untested, so if you find any issues, post them here.

I'll currently working on symlinks, so you can have a treenode point to another node (in another tree if needed). It's a feature I use in ExiteCMS, which support multiple sites, and every site is a tree in the database. It allows you to link section of a website into another website.

[eluser]mikelexp[/eluser]
Is it possible to force an id when saving a new object? I'm building an app that caches Facebook objects and I'd like to build all the relationships using Facebook's own IDs.

[eluser]OverZealous[/eluser]
@mikelexp
It's in the manual ;-)

[eluser]mikelexp[/eluser]
[quote author="OverZealous" date="1290116186"]@mikelexp
It's in the manual ;-)[/quote]

Thank you! I've read the entire manual but this line led me to believe that it wasn't possible:

Code:
Every table must have a primary numeric key named id that is automatically generated.




Theme © iAndrew 2016 - Forum software by © MyBB