Jump to content

microcipcip

Members
  • Posts

    78
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by microcipcip

  1. I wrote a class to get any ProcessWire field in the core. It is still incomplete but should work for what you need. First you need to set up an api/pages template as explained in this tutorial Then you can use this code for the pages template and this class for getting all fields. This will allow you to get the following: http://mysite.com/api/pages/1 to get all fields from the home page http://mysite.com/api/pages/1?children=1 to get all fields plus the children pages http://mysite.com/api/pages/1/template-name/ to get a list of children with the given template name There's much more but you can read the class comments to learn how to use it. Note that I am a noob PHP developers so there may be a lot of mistakes ;p
  2. Actually It seems that it is more challenging than what I initially thought as it seems difficult to predict all possible results, for example if I have a query like this !body*=sushi tobiko&body|sidebar*=carbonated it will return "!body*" => "sushi tobiko" "body|sidebar*" => "carbonated" Also I need to take into account the selector operators....what is a good practice and the correct query syntax to get the selectors and santizie them properly? For example if I don't wan't to allow fields not visible in the API or disable include=hidden, etc?
  3. Yes I know this, that's why I'll filter the results, I have an array of allowed selectors. I just wasn't sure about how to sanitize the query properly, it's for a REST API. It seems I only need to specify type cast, but I can also make use of an array as specified here, although I am not sure which one is more secure and how easy it is to convert from the query to that format.
  4. I need the function because I need to use it in several places and I want to allow only certain search queries (otherwise someone may be able to see hidden pages or hidden fields). The array approach seems interesting, I'll have a look, thanks a lot for your help
  5. Thanks a lot, that was it. I was actually looking at https://github.com/NinjasCL/pw-rest trying to understand why it didn't need to include the index.php file . BTW, do you know if this is the correct way of sanitizing a query? function getSelectors() { $selectors = []; foreach ($input->get->getArray() as $key => $query) { $query = wire('sanitizer')->selectorValue($query); array_push($selectors, $key.'='.$query); } return implode(',', $selectors); } // then below I'd use... $p->children(getSelectors()); I have a query of this kind (in a REST API) "http:/mysite.com/api/pages/1?template=home|about" but when I debug it I get 0 => "template=home about" so it seems that it is removing the pipe. It also removes selector operators like >, =, < etc...
  6. How do you access ProcessWire API from an external file? I wrote a class and I need to use the API from there...my php file is in templates/includes/file.php <?php namespace ProcessWire; include_once('../../../index.php'); class myClass { private function ($query){ return $sanitizer->selectorValue($query); } } I get this error: Call to a member function selectorValue() on a non-object
  7. Dunno if it may help, but after two weeks of ProcessWire usage, I feel sorry not to have found it before, I wasted a lot of time learning other CMS (even Laravel based, although I do think that Laravel is amazing)
  8. Okay, thanks all for your suggestions. I'll have a look at the migrations module when I have time, it certainly looks like a nice solution but I need to read it carefully to avoid losing content.
  9. All right now I understand . Thanks a lot for your help!
  10. Thanks a lot, this helps a lot as I can now see the fields from the Admin. Is there a reason why debugAll won't show those nicely formatted fields when I debug from the frontend, but the ProcessWire popup will?
  11. All right, I am starting to understand. The reason I only see the "title" field is that I am getting the page by ID, so that tab is showing the page I'm in. Sorry about the mistake of toArray instead of getArray, I didn't notice it! Is it possible to get a nicely formatted array like the one on "Field List & Values" in ProcessWire popup, if I am in another page? I am basically building a REST Api so I can't access the templates directly (it's a single page app that I access from http://mysite/api/pages/pageID, I am following this tutorial). I am using $p = $pages->get($pageId); and then with da($p->banners->getArray()); I basically see the third screenshot I've shared above.
  12. My setup is a little bit confusing, in the "Field List & Values" of ProcessWire popup, I see the following (only "title" field!): If I try to output da($p->banners->toArray()); I get this list, without the array: If I try foreach ($p->banners as $banner) {da($banner); } I get this (and here the strange thing is that the imgs have no width/height, url, httpurl etc). Do you have any idea of what I am doing wrong?
  13. Does anybody know why I am unable to debug images? I only see the field name, but not the array with the list of images, I tried xdebug and tracy debugger... This is my code: var_dumb($page->fields) or dumbAll($page->fields). This is what I see, note that I have several images (array) in this page: If I try foreach on the fieldgroup and output the fieldname I can get the image url... P.S. a little bit off topic...but is there a way to just get the data/values of the fields? I don't really care about all the other fields like hooks, wire, notices, etc etc...
  14. Thanks a lot for this amazing tutorial. May I ask you few questions? How do you get the json info for image field type, either single or array (possibly included responsive file sizes)? How would you exclude specific fields, is it better to include each one manually or exclude the one you don't want? Do you usually add query parameters as well, for example if you want to output children of a specific page ID in the same call? Do you know if there's any example showing a tipical nested structure like mysite/api/pages/categoryList/{catID}/articleList/{articleID}/galleryList/{galleryID} etc.. For example, in my single page app I need to output all pages of the website, both root and nested pages. Would you still use the classes used in this tutorial or this library that seems more up-to-date? https://github.com/NinjasCL/pw-rest
  15. Okay, ATM I have ignored the assets folder processwire core, all seems good :). Why do you think that committing the database would bloat the commit history?
  16. I use extension .twig, it is easier to highlight in the editor. Thanks a lot for looking into this
  17. Does anybody know why I have to add the following code to every twig template? {# FileCompiler=0 #} If I remove that line, I get Parse Error: syntax error, unexpected ',' I am also having a difficult time debugging in php. Echo or print_r from within my template.php files usually result in php errors. What is the best practice to debug from php when Twig is enabled?
  18. Thanks for the welcoming, nice to see so many MODx devs here :). I wish I had embraced ProcessWire sooner, as after leaving MODx 4 years ago I have forked MODx Evo with other devs, then tried several other CMSs...but only in ProcessWire I find the closest resemblance of MODx Evo functionality (I hate Revo ), obviously ProcessWire is way way way more powerful.
  19. Thanks a lot for your reply, now I understand how it works
  20. Hi, I have several questions about modules: Where are modules settings saved? In the database? If yes, in which table? Where are modules fields saved? Again, in the database? If I were to git control my website, should I ignore modules folder?
  21. What does it mean "any change of version" here? Any change of the files? Would it be ok to version control the files assets if I am also committing the database?
  22. @fbg13 ok, I'll have a look! @kongondo thanks :), I surely remember the invaluable Wayfinder snippet, I am eager to test the Menu Builder
  23. @arjen Thanks! Where do I add the hook, in the admin.php template it is not working....also, is it possible to apply it to every processWire admin page and not just in the edit page?
  24. @Wanze I am still confused about the snippet of code for enabling dump(), I guess this function needs a class to be attached to, where do I add it? Edit: I have enabled it with the following code (in init.php) wire()->addHookAfter("TemplateEngineTwig::initTwig", function($event) { $twig = $event->arguments('twig'); $twig->addGlobal('hsaApp', wire('config')->hsaApp); $twig->addGlobal('hsaDist', wire('config')->hsaDist); $twig->addExtension(new \Twig_Extension_Debug()); }); Do you happen to know why `{{ dump(page) }}` results in a empty white page but for example `{{ dump(page.title) }}` works? Edit2: you need to install xdebug on php.ini
×
×
  • Create New...