Jump to content

unable to set $page->of(true) inside __invoke($page)


bernhard
 Share

Recommended Posts

hi everybody,

I'm working on my new datatables module. i pass a pagearray (rows of the table) and for each column i call the column callback that returns the value of the cell:

    // check type
    if(!is_array($rows)
      AND !($rows instanceof PageArray)) throw new WireException("Data must be an Array or a PageArray");

    // create objects for each row (page)
    foreach($rows as $row) {
      $obj = new \stdClass();

      // create property for each column
      foreach($this->cols as $col) {
        if(is_callable($col->data)) {
          $obj->{$col->name} = $col->data->__invoke($row, $col);
        }
      }

      $json->data[] = $obj;
    }
    return json_encode($json);

$col->data->__invoke($row, $col) makes it possible to define the tables columns like this:

$col = new ProcessWire\dtCol();
$col->name = "id";
$col->title = "Page ID";
$col->data = function($page) {
    return $page->id;
};
$this->cols->add($col);

the problem is, that $page inside the $col->data function has of(false)! what i need to be able to do is this:

$page->of(true);
return $page->title; // return current's language title

doing a $this->wire->pages->of(false); works, but that's no possible solution.

does anybody know whats going on here?

thank you!

edit: maybe this could be related to that i'm including the code via eval() ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...