Jump to content

gebeer

Members
  • Posts

    1,554
  • Joined

  • Last visited

  • Days Won

    48

Everything posted by gebeer

  1. @rastographics you're welcome. I didn't know much about docker either, before I put this together. Took me 2 days to get to know basic concepts and find existing images that I could base mine on. Read about docker-compose, too. But I decided to first learn proper use of docker with native docker utilities before using some wrapper around it. Makes me feel more confident when it comes to solving issues. Also, when you have setup your containers once with docker run ..., they are very easy to handle. Example: you have set up 3 containers following the README.md with names nginx, mariadb, example_com To stop them, just run: docker stop nginx mariadb example_com Next time you want to work on example_com: docker start nginx mariadb example_com Then you setup a fourth container with a new dev project with docker run --name example2_com ... To work on that project. you do: docker start nginx mariadb example2_com Its that easy. So I have no need for docker-compose. Just had a very quick look at wocker and it looks interesting. With my system I can start up a new project within less than 5 minutes. And thats quick enough for me
  2. @microcipcip WireHttp is meant as a replacement for external PHP http client libraries like guzzle etc. You would want to use these when you 'talk' to the REST API that you set up with PW. Don't confuse this with clsource's Rest Helper class that I am using in my tutorial. You would still use that to build your REST API on the PW side. Today, If I wanted to develop a PW application that exposes JSON data through an API I would go with the brandnew GraphQL module by Nurguly. Seems like a much cleaner approach compared to REST.
  3. As for organising your forms in the page tree, you could also save all form pages under one parent. When you save a form page via API, you can set the user who has created the form (which is the logged in $user). Some dummy code to achieve this $form = new Page; $form->template = 'form'; $form->parent = $pages->get('template=formparent'); /* set user who created this form */ $form->set("createdUser", $user); Then in the user's dashboard you get all the forms for that user with something like $forms = $pages->find("template=form, created_users_id={$user->id}"); I'm using this approach in some projects with frontend user dashboards and it works really well. Users can only see the content they created. All user content (here forms) lives under one parent page which makes it easy to create and query. Important note: in the backend you need to edit the form template and enable "Allow the 'created user' to be changed on pages?" under the "Advanced" tab. For the admin dashboard where forms for all users should be listed, you might want to spend a few bucks on Lister Pro. This saves you from developing a custom admin page. Lister Pro is very powerful and you can create a Lister that shows all pages with template form. You can list all forms sorted by created date, filter for forms of specific users etc. Also inline editing for the status field is possible. So admins can change the status very quickly. For the multi-step form: I also think that using Angular here would be overkill. I have a multi-step form that I render with PHP and use some very simple JS to step through the form. The form is divided into fieldgroups that reflect the steps. In the JS you can use AJAX to save the steps of the form that have been completed. Since you want to store the form data as JSON, you might want to look into a JS form framework that renders forms from JSON, something like Alpaca Forms. This would save you from creating the form rendering logic on the PHP side. They also support multi step form wizards. And, finally, what @adrian suggested above for creating users under different parents makes a lot of sense. I use this approach quite often.
  4. @microcipcip At the time of writing this tutorial and coding a real world application that uses this approach, I wasn't aware of the fact that PW brings it's own http client Class WireHttp. So today I wouldn't bother using an external library like guzzle or phphttpclient. I would go with WireHttp. It has all the methods you need. @clsource thanks for answering microcipcip's questions so thoroughly.
  5. Update: Working with this setup I found that installing modules with the installer from the admin did not work because php-zip module was not installed. I fixed this and pushed the new image and Dockerfile to dockerhub and github.
  6. @kreativmonkey you can leave out the namespace if the site works. You would need them if you were using other PHP libraries inside ProcessWire that might have naming conflicts. Otherwise you don't need them to make PW work. But in general it is a good practice to use namespaces if you are know what the implications are.
  7. @arjen I updated the README at https://github.com/gebeer/alpine-php-processwire Hopefully this makes things more clear. And here is a great resource for some basic docker commands (listing/removing of images, containers and volumes). I needed them a lot when experimenting... Please let me know how it is going for you.
  8. @kreativmonkey The thing is when you upgrade to 3.x and declare the namespace only in one file, it will most likely not work. You'd have to put the namespace line on top of all of your template files. Since the namespace is not declared in home.php but in function.php the file compiler in PW 3.x runs into errors. So either declare the namespace in all template files or in none. @all Please correct me if my assumption is wrong. At least this is how I understand it. When upgrading to 3.x it is a good idea to read up on PHP namespaces and search the forum for related threads. The error message in your first post points towards a syntax problem. But I can't spot an error in your syntax. Maybe someone else?
  9. @kongondo Never mind. Need one anyways
  10. @kongondo Ok, I'm going and get a coffee EDIT: @OpenBayou Try this code <?php $deal_items = $pages->find("deals_show_on_endorse={$page->id}");?> <?php foreach($deal_items as $deal_item) : ?> <?php echo $deal_item->title;?> <?php endforeach; ?>
  11. Thats because of the s in <?php echo $deals_item->title;?> It needs to read <?php echo $deal_item->title;?>
  12. @kongondo guess you're right. I recently had problems upgrading to 3.x and found that putting the namespace in every file in my templates helped. But here it seems to be a syntax error. I couldn't spot it in the code provided so I wanted to make sure that it is not a compiling issue because of missing namespace.
  13. Do you have <?php namespace ProcessWire; in the top of your _function.inc?
  14. Hello everyone, I've been fiddling around a lot lately with docker containers for my local development on a linux machine. Tried many different options, also readily available processwire images and tutorials from the forum. But never got it right. Mainly because of permission issues with docker volumes. That is a tricky part on linux machines whereas on OSX it doesn't seem to be an issue. Then I discovered http://www.wordpressdocker.com/. And the setup with nginx as a proxy that routes requests to separate containers with the actual site install appealed to me. The whole thing sits on top of alpine linux containers which are really lightweight. So I decided to give it a try. And, first time since experimenting with docker, I got a running PW install. Rewriting was not working until I adjusted the nginx config. Now I have a fairly complex PW site running in a container. Everything is working, image upload/editing etc. So I'm really exited, especially since the dev site is now blazing fast compared to my old vagrant virtualbox vm setup. Honestly, I don't really understand everything that is happening behind the scene. But I managed to adjust the original files and build a new image that works with PW and doesn't have all the WP stuff. The nginx config I took from https://github.com/elasticweb/nginx-configs/blob/master/configs/processwire-2.conf Not sure if it covers everything for PW3 as well. I would very much appreciate if someone who is more in the know than me could take a look. All files for building the docker image are here https://github.com/gebeer/alpine-php-processwire A working image here: https://hub.docker.com/r/gebeer/alpine-php-processwire/ Documentation is kind of lacking. I took over quite a lot from the original project. But following the github README and the original documentation should get people started who have a little experience with docker already. If someone needs a more in depth step by step tutorial for setting things up, let me know and I'll put something together.
  15. @Mike Rockett Thanks for the pointer. Didn't think about it. I was looking at the default site profile template files and they all have it in the first line. My post was meant as an example on how you can approach the problem with search/replace and regex. People can adjust the regex to fit their needs. However, I put together a new regex, that searches for <?php in the first line of a document which is not followed by any number of spaces, tabs or newlines and 'namespace ProcessWire;'. You can see it in action here. remove the first line and then add any number of new lines between '<?php' and 'namespace ProcessWire' to see that it works. It only picks up <?php in the first line of the document. Here it is for convenience (^<\?php(?![ \t\n]*namespace ProcessWire;)[ \t]*)/g
  16. That is what I did. You can get every file in directory templates that ends in .php. Then look if the file starts on the first line with <?php. If <?php is not followed by namespace ProcessWire, it will be replaced. The regex expression for the find operation \A^<\?php(?!\ namespace\ ProcessWire;) My Sublime Find&Replace panel looks like this You can adjust file paths and endings to catch other files in other directories (e.g. modules) as well. Should work in other editors that support regex search/replace across files, too.
  17. gebeer

    Web based IDE

    When it comes to working in teams, web IDEs can be great. I have some experience in team work on cloud9. And I am quite impressed about what features even their free account has to offer. If you are travelling a lot, you'll have your web IDE workspace setup available anywhere which is also great. Apart from that I prefer working on a local setup.
  18. Happy New Year to everyone! For a project that I'm working on, I needed to have dependent checkboxes on page edit forms in the admin. Just like dependent selects but for checkboxes. I couln't find anything and decided to write my first Inputfield module. I have only tried it on PW > 3.0. But it should also work on the 2.x branch. Would be great if some of you could try it out and give some feedback. You can find the module InputfieldDependentCheckboxes at github Here's some screenshots of the module in action and instructions on how to use it. ##An Inputfield for ProcessWire admin interface that handles the display of dependent checkboxes in page fields Sometimes we need checkboxes to depend on other checkboxes in our page edit forms. This module adds this functionality to standard page field checkboxes for 2 or more checkbox fields. ## Installation 1. Copy all of the files for this module into /site/modules/InputfieldDependentCheckboxes/ 2. In your admin, go to the Modules screen and click "Refresh". Under the 'Inputfield' section, install the 'InputfieldDependentCheckboxes' module. 3. Open Modules->Configure->InputfieldPage. Under 'Inputfield modules available for page selection' add 'DependentCheckboxes' from the select dropdown and submit ##Field Setup This inputfield extends the standard checkboxes for page fields. Therefore you need to have page fields configured already that you can extend with this Inputfield type. ###Prerequisites You need to have at least 2 fields of type page that have 'Checkboxes' defined as Input field type and live on the same template. A real world example: There are different types of instructors. Each instructor type can have multiple different certifications. For this to happen, we need 2 page fields (multiple): A) instructor_types: lists pages with template 'instructor_type' B) certifications: lists pages with template 'certification' The certification template needs to have the instructor_types page field to assign one or more instructor_types to a certification. ###Setup (link checkbox fields) 1. Edit your page field A and go to the 'Input' Tab. Under 'Input field type' choose 'DependentCheckboxes'. Hit save. Now under 'Choose the target checkboxes field' choose the name of your field B. Hit save again. 2. In your page field b make sure to choose a template under 'Input' Tab under 'Selectable Pages'->'Template of selectable page(s)'. Your fields should be setup. If you now edit a page that contains the 2 fields, the dependent checkboxes should be working. EDIT: And yes, this is working for multiple dependent checkboxes, too. (I have tried it with 3 so far) Some notes on how the module works behind the scenes: - parent checkboxes (actors) that have dependent checkboxes (targets) get custom data attributes applied which contain arrays of the targets' IDs - some Javascript is initiated on acxtors and targets to handle the display based on the id arrays in the data attributes. EDIT: since this module's mention in ProcessWire Weekly it might get some more attention. I just wanted to point out that it is still in alpha state. I will continue development and more thorough testing while implementing it in an ongoing project within the next 3-5 months or so. I will eventually release a stable version then. If you use the module with only 2 dependent checkbox fields, it should work smoothly. There are still some quirks when using 3 or more and I need to figure out how to best resolve them. So please be patient (or jump in with ideas ).
  19. Kind of solved. I decided to refactor my module code and replace the original render() method instead of the addOptions() method of InputfieldCheckboxes module. This way I can access my settings values inside the render method and make use of them further down the road.
  20. @ryan thank you for the insight. Problem is, that I need my config setting values to be available to the public function addOption($value, $label = null, array $attributes = null) {...} which replaces the original method in wire/modules/InputfieldSelectMultiple.module. And that method is called before renderReady(). I'm adding custom data attributes to the checkboxes using /** * Adds an option with extended attributes * Replaces original method in wire/modules/InputfieldSelectMultiple.module * taken from https://processwire.com/talk/topic/419-extending-inputfields/?do=findComment&comment=76823 * */ public function addOption($value, $label = null, array $attributes = null) { if(is_null($value) || (is_string($value) && !strlen($value))) return $this; if (null === $attributes) { $attributes = array(); } $extra_atts = $this->extendAttributes($value, $label); $attributes = array_merge($attributes, $extra_atts); return parent::addOption($value, $label, $attributes); } /** * Hook this and return an array with whatever extended attributes you need. * */ public function ___extendAttributes($id, $value) { /** * Either hook this method to do what you want or implement things directly if this * is the only use of this Inputfield. * For your example you'd grab the fields you want from your page and put into data * attributes... */ $atts = array(); $targets = array(); $deps = wire('pages')->find("template=certification, instructor_types={$id}"); foreach ($deps as $d) { $targets[] = $d->id; } $atts['data-icbdtargets'] = json_encode($targets); return $atts; } And I want to build the hardcoded selector in $deps = wire('pages')->find("template=certification, instructor_types={$id}"); from values that I get from the settings fields in getConfigInputfields(). If it is not possible at all I would have to create an extra configurable module that provides the settings. I'd like to avoid that overhead. My Inputfield module provides configurable dependent checkboxes. It is working with the hardcoded selector. But I want to release this as a configurable module so that people don't need to alter code in the module. It makes sense to have the settings in the 'Input" Tab of the field settings. So I would like to avoid the need of an extra module for config settings. I'm pretty new to module development and haven't grasped all concepts yet.
  21. Hello, I'm struggling to access module config values inside init() or ready(). My module extends InputfieldCheckboxes and implements Module interface. I have a custom configuration field public function ___getConfigInputfields() { $inputfields = parent::___getConfigInputfields(); $modules = $this->wire('modules'); $options = $this->getInputfieldCheckboxes(); $f = $modules->get('InputfieldSelect'); $f->attr('name', 'targetField'); $f->set('label', $this->_('Choose the target checkboxes field')); $f->set('description', $this->_('The field that has checkboxes which depend on this field\'s checkboxes')); // $f->set('notes', $this->_('Types indicated with an asterisk are for multiple field selection.')); foreach ($options as $fieldName => $prop) $f->addOption($fieldName, $prop['label']); $f->attr('value', $this->targetField); $inputfields->add($f); return $inputfields; } This is working fine and saving values. Right after getModuleInfo() I have public function __construct() { parent::__construct(); $this->set('targetField', ''); } In my render() and getConfigInputfields() methods, I can access the value for the custom config setting with $this->targetField. But in other methods, it is not available. In the API Reference for init() it says: When I remove my __construct() method entirely, config values still get saved correctly. But when I access $this->targetField in init() or ready(), I get null. How can I access configuration data inside init() or ready() ? I read many posts and looked at how other modules do this. But couldn't find a solution. Thanks in advance for any pointers.
  22. @BitPoet thanks for clarification.
  23. Hello and Happy New Year to everyone, I'm trying to implement module configuration fields in an Inputfield Module following Ryan's blog post https://processwire.com/blog/posts/new-module-configuration-options/ Is this supposed to work for all modules? My module extends InputfieldCheckboxes. This is the structure of my module folder: The InputfieldCheckboxesDependenciesConfig.php is not being picked up at all. When I configure it the old way with ___getConfigInputfields(), it is working.
  24. @lena In the module docs you can find instructions on how to apply your custom markup/classes: https://github.com/justb3a/processwire-simplecontactform/blob/master/doc/overwrite-classes-and-markup.md EDIT: and welcome to the forum!
  25. @Can thanks a ton for this hint. Looks promising and I will definitely give it a try.
×
×
  • Create New...