bernhard Posted July 11, 2017 Share Posted July 11, 2017 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 More sharing options...
Robin S Posted July 11, 2017 Share Posted July 11, 2017 Maybe this works...? return $page->getFormatted('title'); 1 Link to comment Share on other sites More sharing options...
bernhard Posted July 13, 2017 Author Share Posted July 13, 2017 thank you robin, it worked! still i would like to know what's going on and why it does not work as expected... 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now