Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 09/09/2016 in all areas

  1. This week's blog post is written by Jonathan Lahijani where he writes about the works he's done with CMS Critic: Read the blog post at: http://processwire.com/blog/posts/cms-critic-powered-by-processwire-again-case-study/
    7 points
  2. Hi, Have you followed this: http://processwire.com/docs/security/file-permissions/ ?
    4 points
  3. Simple Contact Form Using Google Recaptcha & Valitron validation library I just finished creating a simple Contact-Form for a client's website so i thought it would be really helpfull to share it with the community. The contact form uses: Google recaptcha for validating the user is not a robot (https://github.com/google/recaptcha) Valitron validation library for validating the form fields (https://github.com/vlucas/valitron) Twitter Bootstrap 3.0.0 for form HTML The contact-form is located inside a contact-page, so the bare minimum you need in order to setup your own is: contact.php (template file used by your contact-page) _contact-controller.php (file used as a controller for your contact-form functionality like send email, validate fields etc) 2 extra lines inside your composer.json file So, let's start: First you need to update your composer.json file adding 2 lines inside the require object: "vlucas/valitron": "^1.2", "google/recaptcha": "~1.1" Here is a sample composer.json file: { "name": "processwire/processwire", "type": "library", "description": "ProcessWire CMS/CMF", "keywords": [ "cms","cmf", "content management system" ], "homepage": "https://processwire.com", "authors": [ { "name": "Ryan Cramer", "email": "ryan@processwire.com", "homepage": "https://processwire.com", "role": "Developer" } ], "require": { "php": ">=5.3.8", "ext-gd": "*", "vlucas/valitron": "^1.2", "google/recaptcha": "~1.1" }, "autoload": { "files": [ "wire/core/ProcessWire.php" ] }, "minimum-stability": "dev" } open console and navigate to processwire root folder (where composer.json file is) on this step i assume you have already setup composer for your project, otherwise google it run the following command: composer update this will create a vendor folder (if it does not already exist) and download valitron and google recaptcha libraries. Then open your contact-page template file(usually named contact.php inside your templates directory) and add the following: * Note: The form below uses bootstrap 3.0.0 css, so if you are using something else you need to make the appropriate changes. <?php namespace ProcessWire; include('_contact-controller.php') ?> <div class="container"> <div class="row"> <div class=" col-md-4"> <h2>Contact Form</h2> <?php if($session->flashMessage):?> <div class="alert <?=!$session->sent && (!$v->validate() || !$resp->isSuccess()) ? 'alert-danger' : 'alert-success'?>" role="alert"> <?php echo $session->flashMessage;?> </div> <?php endif;?> <form id="contact-form" method="post"> <div class="form-group <?=$v->errors('name') ? 'has-error' : ''?>"> <label for="name">Name</label> <input class="form-control" name="name" id="name" type="text" value="<?=$sanitizer->text($input->post->name)?>"> </div> <div class="form-group <?=$v->errors('email') ? 'has-error' : ''?>"> <label for="email">Email</label> <input class="form-control" name="email" id="email" type="text" value="<?=$sanitizer->text($input->post->email)?>"> </div> <div class="form-group <?=$v->errors('message') ? 'has-error' : ''?>"> <label for="message">Message</label> <textarea class="form-control" name="message" id="message"><?=$sanitizer->text($input->post->message)?></textarea> </div> <div class="form-group"> <!-- Google Recaptcha code START --> <div class="g-recaptcha" data-sitekey="<?=$googleSiteKey?>"></div> <script type="text/javascript" src="https://www.google.com/recaptcha/api.js"> </script> <!-- Google Recaptcha code END --> </div> <button type="submit" class="btn btn-primary">SEND</button> </form> </div> </div> </div> <?php //here we remove the flash-message because it is already shown above the form. $session->remove('flashMessage'); //reset 'sent' variable for future submit $session->sent = false; ?> Next create a file inside you templates directory with name: _contact-controller.php: and set the required variables($googleSiteKey, $contactFormRecipient, $contactPageID) <?php namespace ProcessWire; /** * here we include Valitron & Google recaptcha libraries * make sure the path is correct in your template */ include(dirname(__FILE__) . "/../../vendor/vlucas/valitron/src/Valitron/Validator.php"); include(dirname(__FILE__) . '/../../vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php'); /** * here we add the form field values to Valitron */ $v = new \Valitron\Validator(array( 'name' => $sanitizer->text($input->post->name), 'email' => $sanitizer->email($input->post->email), 'message' => $sanitizer->text($input->post->message), ) ); /** * validation rules set for each form field * For more details on Valitron/Validator usage visit: * https://github.com/vlucas/valitron */ $v->rule('required', ['name', 'email', 'message']); $v->rule('lengthMin', 'name', 5); $v->rule('email', 'email'); /** * set Google recaptcha site-key & secret-key * create a new key from: https://www.google.com/recaptcha/admin */ $googleSiteKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; $googleSecretKey = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'; /** * set the email of the contact form recipient(usually the website owner) */ $contactFormRecipient = 'your@company.com'; /** * set the id of contact-page in order to redirect there when the form is sent */ $contactPageID = '1045'; //here we check whether the 'name' field exists inside post variables (which means the form is posted) if ($input->post->name) { //if fields validation passes if ($v->validate()) { $reCaptcha = new \ReCaptcha\ReCaptcha($googleSecretKey); $resp = $reCaptcha->verify($input->post->{'g-recaptcha-response'}, $_SERVER["REMOTE_ADDR"]); //if google-recaptcha validation passes if ($resp->isSuccess()) { //This is the HTML message $message = ' <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Contact Form | ' . $input->post->name . '</title> </head> <body> <p>' . $input->post->message . '</p> </body> </html>'; //here we send the form to $contactFormRecipient wireMail($contactFormRecipient, $input->post->email, "Contact Form | " . $input->post->name, $message); //here we set a flash-message to notify the user that the form was successfully sent $session->flashMessage = 'Thank you for your message! We will get in touch with you shortly.'; //save in session that the form is sent $session->sent = true; //finally redirect user to contact-page $session->redirect($pages->get($contactPageID)->url); } else { //self explain $session->flashMessage = 'Error while validating you are not a robot!'; } } } ?> Thats all! You now have a simple contact-form working with captcha and field validation! I would be more than happy to help anyone having problems on the setup.
    3 points
  4. Another approach, what works automatically everytime, and without additional support, (updating version numbers) can be: $timestamp = filemtime($config->paths->templates . 'scripts/myJsFile.js'); $myJsFile = $config->urls->templates . "scripts/myJsFile.js?ts={$timestamp}"; $config->scripts->add($myJsFile); I'm to lazy to add version numbers to all and everything. Also, last modified filetime is foolproof, not updated version number is not.
    3 points
  5. During the installation process ProcessWire needs write access, however, after you have installed PW, it is time to be more strict, and remove as much permission as you can on the server in question. http://processwire.com/docs/security/file-permissions/#securing-writable-directories-and-files "If the installer populates 777 and 666 permissions, this translates to directories and files that are readable and writable to everyone, which is not a good scenario in shared environments. But without knowing more about the hosting environment, they may be the only permissions that we know for certain will enable ProcessWire to run. In either case, please read on for more details. In most cases you can further lock down these permissions with a little more information."
    3 points
  6. Yeah, I don't worry about that. No different to Repeater items in that respect. If you're concerned about orphaned pages you can set PageTable pages to be trashed or deleted if their parent page is deleted.
    3 points
  7. You can use a hook to append a formatted created date to the end of the page list label. In /site/ready.php... $this->addHookAfter('ProcessPageListRender::getPageLabel', function($event) { $page = $event->arguments('page'); $created = date('d/m/y', $page->created); $event->return .= " $created"; });
    2 points
  8. Make sure the user has the necessary privileges on the database.
    2 points
  9. +1 @bernhard Who is this clever developer you are referring to?
    2 points
  10. And here is the ALL-IN-ONE-FILE-WITHOUT-COMMENTS version...just put this in your contact.php template file (don't forget about composer update though): <?php namespace ProcessWire; include(dirname(__FILE__) . "/../../vendor/vlucas/valitron/src/Valitron/Validator.php"); include(dirname(__FILE__) . '/../../vendor/google/recaptcha/src/ReCaptcha/ReCaptcha.php'); $v = new \Valitron\Validator(array( 'name' => $sanitizer->text($input->post->name), 'email' => $sanitizer->email($input->post->email), 'message' => $sanitizer->text($input->post->message), ) ); $v->rule('required', ['name', 'email', 'message']); $v->rule('lengthMin', 'name', 5); $v->rule('email', 'email'); $googleSiteKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; $googleSecretKey = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'; $contactFormRecipient = 'your@company.com'; $contactPageID = '1045'; if ($input->post->name) { if ($v->validate()) { $reCaptcha = new \ReCaptcha\ReCaptcha($googleSecretKey); $resp = $reCaptcha->verify($input->post->{'g-recaptcha-response'}, $_SERVER["REMOTE_ADDR"]); if ($resp->isSuccess()) { $message = ' <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Contact Form | ' . $input->post->name . '</title> </head> <body> <p>' . $input->post->message . '</p> </body> </html>'; wireMail($contactFormRecipient, $input->post->email, "Contact Form | " . $input->post->name, $message); $session->flashMessage = 'Thank you for your message! We will get in touch with you shortly.'; $session->sent = true; $session->redirect($pages->get($contactPageID)->url); } else { $session->flashMessage = 'Error while validating you are not a robot!'; } } } ?> <div class="container"> <div class="row"> <div class=" col-md-4"> <h2>Contact Form</h2> <?php if($session->flashMessage):?> <div class="alert <?=!$session->sent && (!$v->validate() || !$resp->isSuccess()) ? 'alert-danger' : 'alert-success'?>" role="alert"> <?php echo $session->flashMessage;?> </div> <?php endif;?> <form id="contact-form" method="post"> <div class="form-group <?=$v->errors('name') ? 'has-error' : ''?>"> <label for="name">Name</label> <input class="form-control" name="name" id="name" type="text" value="<?=$sanitizer->text($input->post->name)?>"> </div> <div class="form-group <?=$v->errors('email') ? 'has-error' : ''?>"> <label for="email">Email</label> <input class="form-control" name="email" id="email" type="text" value="<?=$sanitizer->text($input->post->email)?>"> </div> <div class="form-group <?=$v->errors('message') ? 'has-error' : ''?>"> <label for="message">Message</label> <textarea class="form-control" name="message" id="message"><?=$sanitizer->text($input->post->message)?></textarea> </div> <div class="form-group"> <!-- Google Recaptcha code START --> <div class="g-recaptcha" data-sitekey="<?=$googleSiteKey?>"></div> <script type="text/javascript" src="https://www.google.com/recaptcha/api.js"> </script> <!-- Google Recaptcha code END --> </div> <button type="submit" class="btn btn-primary">SEND</button> </form> </div> </div> </div> <?php $session->remove('flashMessage'); $session->sent = false; ?>
    2 points
  11. Ok, I still can't reproduce here - from reading about that object it should only be an object if output formatting is off. Anyway, I have committed a new version which should prevent the error - the PW Info panel might not display the contents of that object as an array how I'd like, but it should hopefully work for you for now until I can reproduce and format properly. Please let me know if it fixes the error for you.
    2 points
  12. The error in the logs could be a symptom rather than the cause of the problem. When it comes to out-of-the-blue errors like this the usual suspect for me is mod_security - it would be worth disabling this to see if it resolves the issue. You may be able to disable mod_security via cPanel or htaccess, but if you're not sure ask your host.
    2 points
  13. @Galo, I think the step you are missing is adding the plugin button to the CKEditor toolbar. The toolbar buttons are set in the field settings, on the Input tab. Edit: and you also need to activate the plugin for the field...
    2 points
  14. It's '/site/modules/InputfieldCKEditor/plugins', isn't it?
    2 points
  15. Yes I have reported it on Github: https://github.com/ryancramerdesign/ProcessWire/issues/2031 Best regards
    2 points
  16. @giannisok i've went ahead and split your post into a new topic over here: https://processwire.com/talk/topic/14206-contact-form-tutorial/ Because your form is not really a module/plugin i thought it best to move it to the tutorials section. Let me know if this is okay.
    2 points
  17. Oops, looks like I forgot to wrap the title in a span. It's fixed, get the latest from GitHub. There's also a fix for CKEaddons, config.js wasn't loaded the way it should. LightWire skin wasn't loaded at all, for example.
    2 points
  18. Hello tpr, I use the latest version of AOS and today I have discovered the same problem with long titles by templates (static header at the top, Reno Theme) As you can see the long headline of the template edit screen floats below the save button. It is the same problem as we have with headlines by articles in the past. You have solved this by limiting the characters of the headline. Best regards Jürgen
    2 points
  19. I'm not sure what you mean. It's just as @MadeMyDay explained - the order is stored as part of the field. You just need to get the "block" pages via the field rather than as children of a parent. Instead of... $blocks = $page->children('sort=sort'); ...do... $blocks = $page->my_pagetable_field;
    2 points
  20. The reason you are seeing pages from the trash is because you are using $pages->get() which returns a page regardless of access or status. Besides Adrian's suggestion you could use $pages->findOne() instead of $pages->get(). But I think the way you are adding a match to your $pages->find() result is going to cause a problem with your pagination - the additional match will appear on every page of results. The only way I can think of getting around this is to make the child page titles a property of the parent page so that parent page can be matched directly in your selector. Unfortunately there isn't a "has_child" feature similar to "has_parent". So perhaps make a page field in your event template and automatically add and remove child pages from it with hooks. Or use a PageTable or Repeater field for your event_date pages and only add event dates via this field.
    2 points
  21. I think the issue lies with the autoload condition: If this is changed to... 'autoload' => true, ...then it works for me. If you change this, do a refresh in Modules to clear the cache.
    2 points
  22. Hi guys! I'm really happy to finally showcase this website in the forum. It's the website of a Porto based Digital Animation Studio. A bunch of talented folks, really. This is a heavily animated/scripted/ajaxed website, that makes use of CSS animations, transitions, transforms, HTML5 audio API, and so on and so on. I spent actually more time debugging than constructing it. Unfortunately, we didn't manage to kill all the bugs before the launching, so you might experience some along the way. We even had to give up on Safari (Damn buggy piece of software !!), and advice the user to use another modern browser. But we think it's still well worth it This is also the first website we developed but didn't design. The design is from the excellent The Royal Studio, from Porto. You might know some of their illustration work for the Adobe online tutorials. --- Enough talk, here is the link http://www.aimcreativestudios.com/ (No safari, please, you'll regret it) Hope you guys like it!
    2 points
  23. Trekkerweb Supply & Demand https://markt.trekkerweb.nl/ Trekkerweb.nl brings agricultural mechanization news and supply & demand together in a single online platform for all the tractor and machine enthusiasts and others interested in the mechanization sector. The site is multi-language with English as default. None Dutch browsers will get the English version of the site, currently we are finetuning the German version which will be available somewhere in the near future. The search page in English and Dutch language - https://markt.trekkerweb.nl/search/ - https://markt.trekkerweb.nl/nl/zoeken/ Used modules Profields Table Profields Textareas MarkupLoadRSS (fetches brand related new from the main website) PageImageManipulator 2 (PIM2) (for placing watermark image) ProCache ProcessGetVideoThumbs TextformatterVideoEmbed WireMailSmtp LanguageSupport (Site is multi language: Dutch, German and Default English) Couple of custom made modules for user profiles and cross page linkage of the datamodel (Bower) components awesome-bootstrap-checkbox bootstrap-dropdowns-enhancement-sass bootstrap-sass bootstrap-select font-awesome formvalidation.io hashids jquery jquery-file-upload jquery-throttle-debounce jquery.mmenu js-cookie lifestampjs moment semantic-ui-sass verge Front-end user profiles (custom module) Account registration Customizable fields (in module settings) Per field privacy configurable (private, public, on a per user basis). Front-end login/ logout Reset password Email activation for account Request activation mail View profile Public profile Edit profile Set profile picture (cover image and avatar) Modify password Language choice Profile dashboard Front-end Ads management Create new ad Edit existing ad Manage media (images / video) Preview and approve ad Remove ad Data model Categories Subcategories Brands Input fields Options An intuitive data model drives the whole site. A couple custom made modules take care of the cross page assigning of categories to subcategories and brands. Per subcategory we are able to assign the related input fields and options which will be rendered on the 'Create new ad/ Edit ad' form page and combined with the given values rendered on the ad detail page. Database caching + Pro caching One of the challenges was to keep the whole project as low weight as possible. Since the data model with categories, subcategories, brands, inputfields and options is the backbone of the site we came up with the solution to have the names, titles, ids, and relations between them cached. Completely as json/javascript with pro cache and separated with database caching. With the Wire Fuel we made the $dm object available for accessing anywhere in PHP and globalJS.dm from within javascript. This means the whole data model is called only once per request, and while it exists in the database cache and pro-cache it is incredibly fast. Subcategory page The first image shown below represent one of the subcategories (Tractors) with assigned categories, brands, input fields and options. The image there after is a screenshot of the add ad page, where the input fields, options and brands are dynamicly rendered after being loaded via Ajax. Other features cookie based favourites cookie based last-viewed list advanced filter search related ads Thanks to the whole team (Ferdi, Bastiaan, Alex, John, Hessel) and last but not least Ryan for creating ProcessWire and all module developers out there
    1 point
  24. Hello everyone, I'm currently working on my first ProcessWire project and read a lot in the forums lately. I also came across the following thread and thought about a way this could be neatly solved. However as I am new to Processwire I don't know if my proposed solution a) makes sense at all b) is possible to implement c) is an improvement over what Processwire currently offers Therefore I would like to discuss the idea a bit and get some honest feedback. The Problem We have a group of input fields that belong to one part of a page. Those input fields should be visually connected so the user knows they are related to one another. Every page can (and probably will) have different values in those fields. Example: We have a couple of settings for a sidebar on a page. show a sidebar on this page (checkbox) sidebar title (text) sidebar subtitle (text) some other options (for example what content should be shown) (select or checkbox) The way to achieve that now The way I see it (again, I'm new to Processwire and so sorry if I missed another option) the way to do something like that is to use a fieldset_open fieldtype or fieldset_tab_open. However that feels a bit cumbersome, at least for me. You have to choose where the fieldset should start, where it ends, don't really see it when you're adding new fields, etc. It just didn't feel as elegant as the rest of Processwire. The proposed improvement [updated] Now what I was thinking is if there could be something like a FieldtypeTemplate FieldtypeGroup. For our sidebar problem our workflow would then become: we create the fields we want to use, but do not assign them to a template next we create a field "sidebar" of our new FieldtypeGroup, select the fields we created and add that field to our page template. That way we could later simply add more sidebar related fields to our sidebar field and automatically all templates using the sidebar field would have the new option. The workflow is really similar to what the repeater fields currently does, just without the actual repeating part. Now I'd like to know, does the idea make sense and would it be possible to achieve with Processwires architecture? Thank you for reading through Alex
    1 point
  25. @Jonathan Lahijani Really great post, thanks. Sounds like you put in quite a bit of work in this upgrade - is it okay to ask the approximate number of hours the project took?
    1 point
  26. Yes, it fixes. I will post an issue to new PW repo. Ohh. Thanks for the expanation. Line-trought style is generated by an Chrome extention. It mark all links with rel="nofollow" with line-trought style.
    1 point
  27. Hi. I don`t know is it bug or just my little knowledge of php, but I will post it here because it is relative to strict mode of Tracy. PW 3.0.33 Tracy 3.0.3 While Im trying to change field type from TextareaLanguage to Textarea i get notice Also it creates table in DB named like "field_name_pwtmp". If to turn off strict mode in Tracy settings and after removing of newly created temporary table, changing of field type could be done normally
    1 point
  28. Introducing the new "User Bar" If enabled (currently off by default), this bar is displayed for users that don't have Debug bar permissions (typically all non-superusers) Currently it has three features: Admin, Edit Page. Page Versions The first two are simply links from the front-end to the root of the admin panel, and a link to edit the current page in the admin panel. These are quite similar to horst's ALIF module, but I was thinking if you are using Tracy anyway, then why not have it provide these buttons for other users who have editing permissions. Now for the first of the unique features: Page Versions. This is a simplified version of the Template Path panel that is available from the Debug Bar. It is also similar to the User Dev Template option, but this one allows the user to try multiple options that you provide. Remember you can always have the alternate template files load different js/css etc files as well, so you can provide a very different version of a page for your users to test. To make it more friendly for your clients/editors, the labels in the list are formatted to look like page names, rather than filenames. The user simply selects an option and the page instantly refreshes showing the page using the alternate version. Even if you have the Page Versions option selected in the config settings, it won't appear on the User Bar unless you have alternately named template files matching this pattern: "home-tracy-alternate-one.php" etc. The key things are the name of the template, plus "-tracy-", plus whatever you want to appear in the list of options, like "alternate-one", plus .php Users must also have the "tracy-page-versions" permission assigned to their role. My next goal for the User Bar is the Feedback / Tickets / Review functionality that was discussed earlier. I know this is starting to take this module beyond just a debugging tool, but I think it's nice to have all this stuff accessible from the same place, so that when you as the developer look for a user submitted support ticket, it will be part of the Tracy Debug Bar. Of course I am also planning a central admin interface for managing all tickets in one place, but I still think it makes sense to be able to submit them from the page in question and also view them from the page as well. It certainly needs some styling improvements etc, but is functional already. I will probably make it possible to define custom styling/positioning in the config settings. Please test carefully before enabling this new User Bar on a live site! Maybe it's time this module gets renamed as the "Tracy Developer Toolbox"
    1 point
  29. I can't see this, but I see that inline cke mode doesn't use up AOS settings (cke plugins, skin). I'll have to check this later.
    1 point
  30. At the and of the video, you can see how to setup the database. This is what I found, but you might be able to find better tutorials. I've never used LAMP, but phpMyadmin comes with it, so you can just look for phpMyadmin tutorials.
    1 point
  31. I've always had them created before I get this stage, so I'm no real help here.
    1 point
  32. @szabesz haha actually the idea is not mine but it was easier to find the snippet in my github repo as there are only very few modules in it and other user's github would have taken me hours to search through @horst thats easier and better of course @tpr ah i see, thanks for clarifying and thanks for adding it in the future
    1 point
  33. Renobird is not 100% correct. ProcessWire does try to create a db for you, but it does need the access rights to do so. I'm not sure if that's the case for your setup.
    1 point
  34. The default theme has a maximum width about 1100 or 1200px, if I make the module layout 2 columns then columns will be too narrow. Reno is full-width so that's why I've set it 2cols if page width is above 1900px. Of course I could widen the max-width of the main container (default theme) let me know if you think that's a good idea. CSS/Js versioning is a good idea, that was on the todo list. Thanks for the snippet!
    1 point
  35. Did you set up a new database and user specifically for this ProcessWire installation? If so, you would have had to give it a database name, username, and a password. That is what's being asked for here. Usually the port is 3306 and host is localhost, so that should be good. This would be different from just a generic MySQL setup.
    1 point
  36. You should find the ip of db host in your hosting or db configuration, ie. when I create a new db on my hosting provider it shows me ip and port to access it.
    1 point
  37. Hi, make sure that db host and db port are valid, I often forget to change db host value if not localhost and receive such an error.
    1 point
  38. Yes!!! Problem is solved! Thank you so much.
    1 point
  39. Have a look at this one: https://github.com/EX3MP/generator-processwire
    1 point
  40. Message from Dumps Recorder: Doesnt return anything.
    1 point
  41. Please try enabling the Dumps Recorder panel - the dump is probably being lost due to a page redirect or something. If you still don't get anything returned, can you please try: bd($outValue); at line 311 - just before the if(is_array) line. Thanks for your help with this.
    1 point
  42. Nothing is returned. Fatal error: Cannot use object of type ProcessWire\LanguagesPageFieldValue as array in /home/.sites/24/site1275/web/site/assets/cache/FileCompiler/site/modules/TracyDebugger/ProcesswireInfoPanel.inc on line 316 Only the line number has changed from 315 to 316.
    1 point
  43. Hello Adrian, I use Tracy Debugger 3.0.0. Unfortunately there is nothing specific on that pages (the first is the homepage with a slider, and the second ist a page with a pricelist). They have nothing in common.
    1 point
  44. Hello Adrian, on some of my pages I get the following error message on the frontend: Fatal error: Cannot use object of type ProcessWire\LanguagesPageFieldValue as array in /home/.sites/24/site1275/web/site/assets/cache/FileCompiler/site/modules/TracyDebugger/ProcesswireInfoPanel.inc on line 315 The Tracy bar will not displayed on that pages. Best regards
    1 point
  45. Yeah, this is what we've been discussing for a while in different topics. And there have been various proposals to move forward in this area, like yours. eg:
    1 point
  46. @szabesz - Thanks for that tip. I have it installed just now and made a backup immediately. Because I know: A file that is not backupped is defined as unimportant. Günter
    1 point
  47. What have you done Adrian!?!? TBH I was surprised that those lived so long. They always made me smile
    1 point
  48. I have improved this code please, check the new repo https://github.com/NinjasCL/pw-rest
    1 point
  49. I wrote up a detailed tutorial on how to use this: https://processwire.com/talk/topic/11806-tutorial-building-a-simple-rest-api-in-processwire/
    1 point
  50. Yes, The verb is on the Http Request and different responses are given depending on the way you call an endpoint. If you got www.your-pw-site.com/products/ then you can have these methods GET -> list of products POST -> create a new product then if you got this particular product "computer-1" www.your-pw-site.com/products/computer-1 you can have these methods GET-> info of computer 1 PUT -> replace all the info of computer 1 PATCH -> replace specific info like name or sku of computer 1 DELETE -> removes computer 1 Now taking that as an example, you can have this way to program and endpoint in Processwire 1.- Create a template named "products" (with a file products.php in templates folder) 2.- Create a page that use that template, and creates the url www.your-pw-site.com/products/ (Enable UrlSegments) 3.- Now products.php will be coded like this Note that Product.php is just a helper class that just have some methods for easier output formatting <?php require_once './includes/Rest.php'; require_once './models/Product.php'; // Vars with the default output $code = 200; $output = null; $header = Rest\Header::mimeType('json'); // First check if you have Url segment1 // this segment you can have the product id if($input->urlSegment1) { $productId = $input->urlSegment1; $product = Product::find($productId); // Check if we found a product if(!($product instanceOf NullPage)) { // Convert the page object to our model $product = new Product($product); // Detects the Verb if(Rest\Request::is('get')) { // json encodeable array $output = $product->get(); } else (Rest\Request::is('put')) { $params = Rest\Request::params(); $output = $product->put($params); // Could be 202 if modification is made async // 200 if OK // $code = 202; } else (Rest\Request::is('patch')) { $params = Rest\Request::params(); $sku = $params['sku']; $output = $product->patch('sku', $sku); // Could be 202 if modification is made async // 200 if OK // $code = 202; } else (Rest\Request::is('delete')) { $output = $product->delete(); } // Product not found } else { $code = 404; $output = Product::notFound(); } } else { // Detects the Verb if(Rest\Request::is('get')) { $params = Rest\Request::params(); $page = $params['page']; $output = Product::fetch($page); } else (Rest\Request::is('post')) { $params = Rest\Request::params(); // You can get the params like // $params['name'], // $params['sku'] // and so on $newProduct = Product::create($params); // Returns and array that can be json encoded $output = $newProduct->get(); // 201 Created $code = 201; } } // End if // Show the response and body http_response_code($code); header($header); echo json_encode($output);
    1 point
×
×
  • Create New...