Jump to content

kongondo

PW-Moderators
  • Posts

    7,529
  • Joined

  • Last visited

  • Days Won

    161

Everything posted by kongondo

  1. Not an answer to your question. Just pointing out a coincidence that an almost identical question was asked within the hour. Anyway, I am cross-referencing the two threads:
  2. If you went with RuntimeMarkup, you could ask @Macrura how he did it as per this example:
  3. Have you tried something like this? $out = ''; foreach($page->page_table_field as $p) { $out .= $p->render(); } echo $out; Of course, change $page as needed
  4. @Zeka, No is the answer This will first return the PageArray (i.e. load pages) and then do an in-memory count. More like counting items in an array. This will do the counting at the db-level, hence faster and more efficient if all you want to do is count.
  5. Just a bit of an explanation for the next guy....: This will retrieve the pages, return a PageArray (PHP Object), which might end up using a lot of memory. Instead what you want is just the count of pages... Which brings us to this. This is very efficient. It will only count these pages and return an integer, not only doing its job very quickly but using next-to-nothing memory.
  6. Something like the below in your module's init() method. You can of course change it to lookup a role or roles or some user IDs [if(!in_array()...]. public function init() { if ($this->permissions->get('duplicator')->id && !$this->user->hasPermission('duplicator')) throw new WirePermissionException($this->_('Duplicator: You have no permission to use this module.')); }
  7. You can use the 'selector' option. See examples here: And the MSN Docs here.
  8. @ethfun, You are missing some code. See a fuller example here (the original CMS Critic case study). What you need: Create your Hook. Have that run as early as possible, preferably in a file that is prepended to templates, for instance _init.php Enable URL segments in home.php. Note that this depends on how you want the URL to be rewritten. If you want to rewrite directly off root, then 'home' is where to go. For instance, if you want /blog/post/ to be rewritten to /post/, you will need to enable URL segments for the template file home.php since that is where ProcessWire will be looking. If you want /blog/posts/post-a/ to be rewritten to /blog/post-a/ you will have to enable URL segments on the template used by blog. The reason you are hitting 404s is that you haven't instructed ProcessWire to accept a URL Segment for that template, in your case, 'home'. Tell ProcessWire what to do when it hits that URL Segment enabled in #2 Mapping the above to code: In these examples, we want to rewrite /posts/post-a/ to /post-a/ 1# Hook: We have this code in _init.php. Any prepended file will do. //wire()->addHookBefore('Page::path', function($event) { @note: this or below, both work. $pages->addHookBefore('Page::path', function($event) { $page = $event->object; if($page->template == 'post') {// template used by 'post-a' // ensure that pages with template 'post' live off the root rather than '/posts/' $event->replace = true; $event->return = "/$page->name/"; } }); 2#. Allow URL segments in the template: Do this in the URLs tab when editing the template. In our case, that is the template 'home'. 3#. Handling URL Segments: in home.php Note that here I haven't taken into account situations where we have more than 1 URL Segment. See CMS Critic case study link above for the full example, specifically under the sub-section /site/templates/home.php. // check if we have a URL Segment if(strlen($input->urlSegment1)) { // render the blog post named in urlSegment1 $name = $sanitizer->pageName($input->urlSegment1); $post = $pages->get("/posts/")->child("name=$name"); if($post->id) echo $post->render();// render the post using its template file else throw new Wire404Exception(); } Just in case you are not sure how to have ProcessWire automatically prepend a file like _init.php, you add this to your /site/config.php/ $config->prependTemplateFile = '_init.php'; It should work as expected, without 404s. ps: I haven't completely digested earlier posts but I am guessing this is what you were after.
  9. Cool. Did my code work though? Probably the titles won't be changing, but if they will, it is more reliable to check by $page.
  10. $Item will return an Object whether or not a user was found, hence case 1 will always be true. So, yes, you need to check differently. I like to check for both the object and an ID. Sometimes if you check only ID you might get a PHP error about a 'call to member function on a non-object' blah blah..: $item = $users->get("email=example@processwire.com"); if($item && $item->id) echo $item->name; else echo 'No user found';
  11. What @szabesz said. Best to PM Ryan to tell him you are interested in contributing.
  12. I think you are right @adrian. I quickly read this and for some reason thought they'd already seen the CMS Critic case study and that didn't suit their needs. I raise that since the same technique is used there. I think stuff like this could make nice short tuts, somewhere outside the forums. There's some nice gems buried deep in the forums.
  13. Untested. Try this: return $pages->find("template=hotel, country=$page"); Here I am assuming that the page field in the hotel template is named 'country'.
  14. If it's not grabbing it and the fact that we know there is a value sent, it means it is not the correct implementation. In other words, that is not how you grab it . The session is only temporary (it is deleted immediately after) since you need to be able to store the value of the first date somewhere in order to do the comparison. Below is a different approach. We directly check the values in the $input->post. Seems a bit hackish (?) but it works. Here, we make sure 'erroneous' values are not saved. We revert to older values in the database or blanks if there were no saved dates and show a field error on the first date input. Also note that if no first date is input, the field error will be displayed. You can play around with the if() logic to change the behaviour. public function init() { $this->pages->addHookAfter("InputfieldDatetime::processInput", $this, "hookAfter"); } public function hookAfter(HookEvent $event) { $post = $this->wire('input')->post; // change date string to timestamp $firstdate = strtotime($post->date); $lastdate = strtotime($post->date2); // if first date greater than or equal to last date if($firstdate >= $lastdate) { $field = $event->object; if($field->name == 'date' || $field->name == 'date2') { // get the page being edited $page = $this->wire('modules')->ProcessPageEdit->getPage(); // ensure we don't save 'erroneous' dates; we revert to older saved (db) dates or blank $oldDate = $page->get($field->name); $field->value = $oldDate; // only show error on first date field if($field->name == 'date') $field->error("Last date must be greater than the first date"); } } }
  15. @LMD. Thanks for reporting. I haven't been able to find a suitable solution for this. The issue is the quotes are tripping up the input value. Have a look at the markup in page source; you will see class="" is output but the HTML breaks since we have something like value="<i class="fa fa-home">". For now (and for any complex menus), I suggest you use the approach posted here, whereby you will have total control over your menu items' structure and styling.
  16. Repeater rows pages do not have a title field ....,hence you not getting anything back. If you did the below, you should see something like ' 1482226910-677-1 ' $test = $pages->get(1156); echo $test->name;
  17. get already assumes an include=all (that includes hidden). http://processwire.com/api/selectors/#access_control
  18. Cache....or staring at a screen for too long can do that to you sometimes .
  19. @adrian, page save might result in emails being sent every time that page is edited. I suggest 'Pages:added' instead.
  20. Are these users in the front or backend? If the backend, users already have email addresses. If you want to automate anything, the normal way is to either user cron or an autoload module (using Hooks). In your case, the latter is a good fit. You would want to Hook into 'Pages:added' (rather than sending emails every time the page is saved)
  21. OK. See @adrian post above you as well. Seems you posted at the same time.
  22. @xavier. Glad it worked. Since a couple of ProcessWire versions back (I can't remember how far back, but since 2.7 at least), pages have a property 'published'. So: echo $page->published;// outputs the date when this page was published. Oh, am not sure you've been properly welcomed. If not, welcome to the forums .
  23. That is weird. Hmm, maybe some caching issues. All the same, it is good to check if $product_pages actually exists.
  24. Actually I suspected that but forgot to mention it. Since you are in a foreach loop, it means that this code does not always get a page, i.e. some of the pages don't exist. $product_pages = wire("pages")->get("productid=$id_product"); //get the correct page so the images are placed in the correct product page Change that to: // get the correct page so the images are placed in the correct product page $product_pages = $this->wire("pages")->get("productid=$id_product"); if(!$product_pages) continue; I assume you've previously sanitised the values of $id_product. Are they integers or strings? What type of field is productid?
  25. So, my question still remains. Maybe confirm with some simple debugging of what this returns: $imgfield = $product_pages->images_product; echo gettype($imgfield); Since you are getting the 'non-object' error, I'm pretty sure that will echo NULL.
×
×
  • Create New...