Jump to content

kongondo

PW-Moderators
  • Posts

    7,529
  • Joined

  • Last visited

  • Days Won

    160

Everything posted by kongondo

  1. @Francesco Bortolussi This is not an answer to your question. I am not fully certain that what you have reported is a security issue. For now, I have moved the thread to the 'General Support' area. It would be good if you could file a bug report and provide other details as well (PW version, environment, etc). Thanks.
  2. It will soon click and it is code you can reuse . Btw, I added a note on concatenation in my code above.
  3. I am assuming by post you are referring to the $child? What is not clear is whether you want the title of the parent of the current page or the title of the parent of $child. Anyway, here's some code. // will give you the title of the parent of the current page // @note: if on 'home' page, will return nothing since 'home' does not have a parent $page->parent->title; // will give you title of the parent of $child // @note: since you are in loop, this will be repeated for each $child // but you already know the parent. It is 'recommendations'...so, @see alternative code below $child->parent->title; /** alternative code **/ // get the parent page $r = $pages->get('/path/to/recommendations/'); $out = '';// empty variable that we will populate with final output if($r && $r->id && $r->numChildren) {// checks if we found a valid page and it has children $out .= $r->title;// @note: about the .= read up on PHP concatenation (we are adding to the previous value we found here, rather than using multiple echos) foreach ($r->children as $child) { $out .= $child->title; $out .= '<img src="' . $child->Image->first()->size(200,0)->url '">'; } } // output echo $out; Also note, ideally, you want to name your fields all lowercase, i.e. 'image' rather than 'Image'.
  4. Welcome to the forums and ProcessWire @Emile. You probably know this already, but since you are new, I just want to confirm that you edited /site/config.php and NOT /wire/config.php ? .
  5. You could also shorten this... $config->urls->admin."page/edit/?id=".$page->id ...to this (available since PW 2.5 I think) $page->editURL, Welcome to the forums
  6. Thanks for sharing this @ryan. It throws up some very interesting statistics. They seem to be very up to date, assuming of course that their research methodology was sound. I have no reason to doubt them though . Some interesting stuff on this page as well.
  7. The code in your first post, is that in a template file or elsewhere? Not necessarily the cause of the error, but am wondering whether you are in a function context or not. Edit: These may be of relevance to you... https://processwire.com/talk/topic/12272-308-call-to-undefined-function-because-of-compiled-files/ https://processwire.com/talk/topic/12214-templates-namespace-and-modules-problem/ https://processwire.com/talk/topic/11815-undefined-variable-pw-3-wirerenderfile-use-compiled-file/ https://processwire.com/talk/topic/13500-variables-scope-in-included-files/ https://processwire.com/blog/posts/processwire-3.0-alpha-2-and-2.6.22-rc1/#compiled-template-files
  8. Works fine for me in an auto-load module in ProcessWire 3.0.42 using the code below. All fields are saved correctly, both page and non-page fields. public function init() { $this->pages->addHookBefore("FieldtypeMulti::savePageField", $this, "hookBefore"); } public function hookBefore(HookEvent $event) { $page = $event->arguments[0]; $this->newPage($page);// calls method to create new page $this->message("we hooked into page with id: {$page->id}"); } public function newPage($parent) { $p = new Page(); $p->template = 'basic-page'; $p->parent = $parent; $p->title = 'Test Child Page'; $p->save(); }
  9. Welcome to PW and the forums @webhoes, I didn't go through your whole code but noticed this: if (waves = 0)//....... That's not a comparison but an assignment. Should be if (waves == 0)//.... // or....depending on your needs if (waves === 0) //... Other than that, you might want to separate the PHP from JavaScript. E.g. for the checked input..., in a foreach loop, assign a CSS class, e.g. 'checked-input' and use that to find elements that are checked.
  10. Unless you are in a PHP Class, you should not be using $this at all, as pointed out earlier. You don't need this line at all: //$wire = $this->wire();// this is not needed in your context It is a good idea, to get a few basic PHP tutorials under your belt before starting to use ProcessWire . Given that you are setting up something as important as a user registration feature, I highly recommend you have a look at such tutorials.
  11. Those variables are always available to you. You don't need to do anything special. The one care you should take is not to overwrite them. # outside a function // will echo the integer value of an input called 'id' that was sent via $_GET echo (int) $input->get->id; // will echo the sanitized value of an input 'title' that was sent by $_POST echo $sanitizer->text($input->post->title); If in a function then: # inside a function // will echo the integer value of an input called 'id' that was sent via $_GET echo (int) wire('input')->get->id; // will echo the sanitized value of an input 'title' that was sent by $_POST echo wire('sanitizer')->text((wire('input')->post->title)); Of course, if inside a function or class, and you will be using lot's of wire('input'), then you can assign that to a variable at the start of the function/class method, i.e. $input = $this->wire('input')->post;// #1. if expecting only post variables // or $post = $this->wire('input')->post; $input = $this->wire('input');// if expecting either get or post or cookie // or $input = wire('input');// you get the idea // then, in relation to #1 above, you can do $id = (int) $post->id; If you have a specific issue, please address it. What is working? What is not? etc... http://processwire.com/api/variables/
  12. ProcessWire's WireMail base class https://processwire.com/api/ref/mail/ https://processwire.com/api/ref/wire-mail/ Example third-party module implementations http://modules.processwire.com/modules/wire-mail-swift-mailer/
  13. A couple of examples Outside function and class $page; $pages; $sanitizer; $input; $modules; $templates; $fields; $user; $users; $log; $session; $config; Inside function wire('page'); wire('pages'); wire('sanitizer'); wire('input'); wire('modules'); wire('templates'); wire('fields'); wire('user'); wire('users'); wire('log'); wire('session'); wire('config'); Inside class $this->wire('page');// also $this->page; $this->wire('pages');// -ditto- $this->wire('sanitizer');// -ditto- $this->wire('input');// -ditto- $this->wire('modules');// -ditto- $this->wire('templates');// -ditto- $this->wire('fields');// -ditto- $this->wire('user');// -ditto- $this->wire('users');// -ditto- $this->wire('log');// -ditto- $this->wire('session');// -ditto- $this->wire('config');// -ditto- Welcome to PW and the forums You may also want to use PW core email class + read up on the recent vulnerability regarding PHPMailer Class (if you haven't already)
  14. Brilliant! Your code could be optimised further like so: $childrenIDs = implode('|', $oldchildrenids); foreach ($pages->find("id=$childrenIDs") as $child) { $child->delete(); $this->message("{$child->id} wurde gefunden und gelöscht"); $childRepeaterPage = $repeaterPage->child("name=for-page-{$child->id}"); // will also delete the repeat item pages, e.g. the '1234567890' if ($childRepeaterPage->id) $pages->delete($childRepeaterPage, true); } In the find, we only fetch the children whose IDs we saved earlier, rather than all children first, then checking their IDs.
  15. // Array of template IDs that are allowed for children. Blank array indicates "any" $page->parent->template->childTemplates // Array of template IDs that are allowed for parents. Blank array indicates "any" $page->template->parentTemplates ...as per notes in core files...
  16. No...the older children. You will need to grab the first, e.g. into a variable, or their IDs then delete them.
  17. The duplicate entry went away for me only if I created the new children first, then deleted the older children. Repeater items would be copied over fine to the new child pages. The only issue then was that for some reason, I couldn't delete their leftover repeater pages...
  18. Excellent! Glad it worked and thanks for sharing the final solution. Similar to what Adrian was saying then (basically a new parent). @adrian, thanks for the ideas
  19. That would require a different repeater field for the child pages, no? In addition, from what I can tell, he wants to delete the older children.
  20. Found a working solution. If you move the code to delete the child pages to AFTER creation of the new child pages, it works. You can then delete the older children pages. After that though, I hit another snag. Haven't been able to delete the repeater pages of the older children
  21. Just seeing @adrian answer. That's definitely it. I've run out of time so can't test further. See if Adrian's solution works. If not, hopefully others chime in, meanwhile. Quick btw: In the code where you delete child pages, no need to delete their repeater pages there as well. They will be automatically deleted when you delete the child pages.
  22. Is this getting saved anywhere btw? $page->recurring = 0; Managed to duplicate the error you are getting. Working on it; will get back to you.
  23. Actually, it makes no difference. I have tested in PW 2.7 and 3.0.42, with each having the same title and it still works. Both adding to repeaters and deleting child pages and their respective repeaters work. Could you post your Hook code itself? i.e. how you are hooking.
  24. This is a strange line. $k->title = $page->title; You child pages will all have the same title; and that title is identical to the parent page. The child pages themselves will have different names; ProcessWire will ensure that. However, I don't know if the same applies to the repeater pages. My suspicion is that this is what is causing the 'integrity constraint' error. I haven't tested yet.
  25. Quick BTWs... In a module context, output formatting is always off (i.e. false), so no need to set it yourself. No need to 'get' the same parent over and over in the loop. Do it outside the loop What is $page in your case? What PW version are you working on? The following code works for me as advertised, in ProcessWire 2.7 and 3.0.42. All parent repeater fields contents are copied over to the children repeater fields $children = array('What We Do', 'Our Mission', 'Our History', 'Our Staff'); $parent = $pages->get('/about-us/'); foreach ($children as $title) { $k = new Page(); $k->template = 'basic-page'; $k->parent = $parent; $k->title = $title; $k->repeater_test->import($parent->repeater_test); $k->save(); } The code above results in this tree under Home And this tree under repeaters. The crossed out repeater items are the unpublished 'ready to edit repeater items' As you can see, names only have to be unique under the same parent (not just for repeaters but throughout ProcessWire)
×
×
  • Create New...