Jump to content

pwFoo

Members
  • Posts

    708
  • Joined

  • Last visited

Everything posted by pwFoo

  1. I think I'll move the requests to a module with a own "/api" page working with urlSegments. Page template just perform a "normal" page load (PW template = controller, separated view). Module use urlSegments to route requests as needed.
  2. Yes, similar to that. PW template could bei used AS controller / return json, but requests for HTML / views should be redirected to another file (for example "./site/template/views/*"). But I don't know how to separate both. Easiest way should be urlSegments, but another way would be nice. Both requests could be ajax.
  3. I try to separate the requests for a template file (html) and the data / json and searching for a way to do it without enable url segments for each template (or enable by hook / api runtime). I'll build a autoload module and the request routing should be done there to send a template / view / html file OR execute the "controller" (page / PW template file) without the need of a switch case / if else inside of the page template file... Any idea how to do it? UrlSegments would work with for example first segment "template" or "view" to request the html file, but would be nice to do it without the use of segments (maybe needed for other things and default disabled). Any PW API way to do it by request content type, urlSegment / QueryString or anything else hook? Or a special "api" page which use urlSegments, load the page given by urlSegment and verify request type (html or json) by compare page path with (loaded page path)?
  4. Thank's, I'll test and compare the three hooks
  5. I know how to hook in page render, but what is the earliest hook into the ProcessWire page load? Should I hook (before) Page::render or is there a hookable method which executed earlier (for example if I check to skip current page load parts)? Also found Page::loaded?
  6. Hi, I play with something similar to service-pages and need to transport a selector and optional a field filter (for example to only get id, name, title instead of all the page fields). I set the selector as query string, /api/path?template=basic-page,field1=val1,limit=10 but how to set the field filter or split selector string from the field filter in parameters? /api/path?fields=id,name,title Can't combine the query string with selector and fields filter because of multiple "=" signs... How should it be done a clean / easy way? EDIT: Optional I use predefined selectors (more secure way too) only selected by path / urlSegments instead of selector in query, but would be nice to know how to handle it most flexible...
  7. Hi @Stikki, I'll take a closer look into you module code to see how filter feature could be added. Would it possible to add the JSON tab to user template too? I can't define the fields should be added to users if converted to JSON by your module?
  8. Is it possible to filter / extend page fields with function param like // only selected fields $myPages->toJSON(array('title', 'image'); // use "default" fields and add / remove fields $myPages->toJSON(array('title' => false, 'created' => true, 'addCustomField'); I know it could be done by a hook, set / modify fields by function param would be nice.
  9. Have to take a look, but messaging sounds great! encrypted would be nice! What's with group messages oder push notifications (web push)?
  10. Looks like I should use a custom not Selectors object / class to build that. No working solution found / known.
  11. Is there a way to redirect properties / fields to make them searchable by find($selector)? For example redirect a call to "$obj->prop<X>" to a function and return the needed value? Would that help to get find('prop1=myValue') work? I tried addHookProperty, but isn't usable for find(). $wa = new WireArray(); $obj1 = new Selectors('seg1=val1,seg2=val2'); $obj1->addhookProperty('seg1', function($event){ $event->return = $event->object->getSelectorByField('seg1'); }); echo $obj1->seg1; // "seg1=val1" $wa->add($obj1); $output = $wa->find('seg1=val1'); // object with items "count 0"
  12. To clearify. It is a PW Selectors object (not a custom class!) with dummy data. Because I need a selector (object) and some custom additional properties. Would be nice to just use the Selectors object with added properties searchable with find. And a missing part here. I tried to add custom properties to Selectors object, but get an error message: $this->property = 'value'; // ignored $this->set('property', 'value'); // error see below $this->addHookProperty(...); // error see below Error: Exception: Item 'selector' set to ProcessWire\ApiRoute is not an allowed type (in C:\xampp\htdocs\pw\wire\core\WireArray.php line 450)
  13. I played with the Selectors object and would like to use it for a special use case... That is a custom Selectors object with dummy data converted to an php array to see the structure (Selectors object is a WireArray with "fields" added) Array ( [0] => Array ( [0] => Array ( [field] => seg1 [value] => val1 [not] => [group] => [quote] => [forceMatch] => ) [1] => Array ( [field] => seg2 [value] => val2 [not] => [group] => [quote] => [forceMatch] => ) ) ) But instead of "seg1" the field name is "field" with value "seg1" (= my field name). So I can't search the Selectors WireArray (= custom WireArray with added Selectors objects) with PW "find('seg1=val1')", Is there a way to search with "find()" or build a simple wrapper to make the elements searchable / filterable with find()?
  14. Looks like it works fine... Don't know what I done yesterday before I opened the topic...
  15. With JS fetch() it is a bit tricky to get for example $_POST populated (params need to be FormData / forms), but would it possible to get PW $input (get, post, urlSegments, queryString) working for fetch requests? Is there a fix / hook / workaround to solve it PW side?
  16. Get it done with property lists for Page, PageImage and PageFile. Tested with PageArray, Page and Pageimage content.
  17. Hi @horst, thanks, but that doesn't work, because the needed properties are private ☹️ You can get the value by "$obj->url". print_r works fine and show all the private keys / values, but if you convert to array / json the private properties not there. I haven't found a way to automate the list of keys or any way to loop through with all the private key => value pairs (image property url and some more are private!).
  18. I tried to automate without the need of a switch / case for different PW objects... If not possible I need some lists of properties of different ProcessWire objects... I don't understand why some default properties like url, path, ... are private. Would be easier if accessable (as it is with a simple "$url = $obj->url").
  19. So it's possible to get the value like that $url = $obj->url; but no way to get all the values with key / prop by loop or something else ☹️
  20. First print_r with the full object and needed data (items) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) Second print_r is empty. No attributes like url, description, ... Array ( [0] => )
  21. Again the code / post isn't shown correct... I split it up again... Forum bug?? print_r($value); $wa =newWireArray(); $wa->add($value); print_r($wa->explode()); First print_r ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) Ok, nice. All attributes are there... Also the needed attributes (url, ...) in "items" sub array. Second print_r miss all the expected data? Array ( [0] => ) Code with pagination in the forum ist strange... ??
  22. Some more tests without success... Object is fine: ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) ) Try to convert it with WireArray (first print_r shows the output above! With all fields and items array) print_r($value); $wa =newWireArray(); $wa->add($value); print_r($wa->explode()); Result Array ( [0] => ) It's easy to output all the needed data, but not to get it to an array or object...?? ?
  23. If I try to get all attributes (explode without param) it doesn't work. The result should be a array with all attributes, but it's just [image] => Array ( [0] => stdClass Object ( [0] => ProcessWire\ProcessWire Object ( [hooks] => Array ( [after ProcessWire::finished] => Template->hookFinished() in Template.php ) ) ) ) Testing some more ways (getKeys() + foreach for example...) to get all the attributes to a plain array...
  24. I know this thread, but isn't what I'm searching for. Can't use explode() with single Page, just PageArray and if I try to get the image field JSON is looking like that. [null,null,null] // all fields of a PageArray [null,{},{}] // image field only Tried explode(), getArray() and getIterator() before without success.
×
×
  • Create New...