-
Posts
212 -
Joined
-
Last visited
Everything posted by Roope
-
So basicly we have product pages and this advanced search filters result from them. Product page has many fields in it (like color, material, socket). Most of fileds are Page field type so dealing with this kind of data is no problem. Then there are couple on text fields in product page (like socket) and we need to use data from these text fields also as filter in our advanced search form. Some example data from product pages 'socket' text field: E27 E27+PowerLED GU10 2G11 Then we create checkboxes from this data: <label><input type="checkbox" value="E27" name="socket[]"> E27</label> <label><input type="checkbox" value="E27 PowerLED" name="socket[]"> E27+PowerLED</label> <label><input type="checkbox" value="GU10" name="socket[]"> GU10</label> <label><input type="checkbox" value="2G11" name="socket[]"> 2G11</label> If user would have then selected all these as filter in advanced search form, our selector string would look like this: socket=E27|E27 PowerLED|GU10|2G11 And now you can see that our second socket data fails to match since + sign is removed by sanitizer.
-
If + sign has no use in PW operators maybe it should be left untouched? There are many cases where input value could have plus sign in it, like phone numbers for example. In my case advanced search form has select options and checkboxes and values come from PW pages. When user changes options, we create selector string from post data and display result count (and finally output results when form submit is clicked). With this text field we basicly get every page that has value in it and strore values to temp array and remove duplicates by array_unique(). Then we create options/checkboxes from this unique data. I don't know any better solution for this.
-
Is there a reason why plus sing is removed by $sanitizer->selectorValue - I can't see it been used anywhere in the docs? I'm just thinking cause those sanitized text fields actually had + sings and now values don't match.
-
Ahh.. I didn't know that value can be quoted like that. Works nicely. Thank you very much Wanze - again!
-
Hello all! I have a little problem with getting find selector to work with site data. My customer needs advanced search form for products where one of desired filter option is getting data from page text field. Problem is that some pages have commas in field value that breaks my selector string. Striping of comma and rest of the string and then use ^= as operator would be one choise but then there are lots of not exaclty matching results that my customer want's to avoid. Another solution would be of course to create pages for actual data and then use Page fields to attach it to product pages. This is how it's done with many other fields on product page but we selected text field for this one because there is actually so many variations and many variations belong only to one product. So is there any handy workaround for this or do we just have to deal with not so precise search results?
-
Cool! Image field (or any other file field type) is array if it's allowed to hold more than one file. You can set this from field setup under Details tab: Maximum files allowed. So your first attempt would also work if you set your header_img Maximum files allowed to 1.
-
Those two output exactly the same - what better suits your need. So if $header_imgs is a repeater I asume that $header_img field is defined for multiple images (like it is by default). Then you just have to remember that image field is also array and you can loop trough or get items using WireArray methods. So not much to add to your first attempt: <?php // get first image from last repeater object $img = $pages->get(1)->header_imgs->pop()->header_img->first(); // output relative url echo $img->url; // output absolute url echo $img->httpUrl;
-
Thank you Ryan! This solves error message, but now 404 doesn't get localizated - text is always in default language when system throws it. Better than errors though! I can send you site package and db if there's any help?
-
Frankly I don't quite get this part of your code: <?php $img = $pages->get(1)->header_imgs->pop()->header_img ?> So is the image field name in you homepage template header_imgs or header_img? If it's the first one and as the name suggest, it's defined to hold multiple images, you can get url like so: <?php // get last image from array $img = $pages->get(1)->header_imgs->last(); // this should also work $img = $pages->get(1)->header_imgs->pop(); // get first image from array $img = $pages->get(1)->header_imgs->first(); // output image url echo $img->url; For single image fields it works like this: <?php // get image $img = $pages->get(1)->header_img; // output image url echo $img->url; PW API pages has good info about image field type: http://processwire.com/api/fieldtypes/images/
-
Thanks! I got sizing working really fine here.
-
PW uses different kind of hash generation (?) depending on server php version. So for example, when you develop your site on localhost using php 5.4 and then migrate site to live server using older php like 5.2.x, all user accounts created from 5.4 server are now unloggable. Just something to keep in mind. Passwords are quite easy to reset using API as Ryan describes here: http://processwire.com/talk/topic/490-how-to-reset-your-password-how-to-enable-the-forgot-password-function/
-
Yes Wance, your example works exactly right - good info! Can you guys help me how to implement removeAll() method in my module? Tried this but doesn't work - Fatal error: Exception: Method Page::removeAll does not exist or is not callable in this context: // set page values else if ($this->fieldTypes[$name] == 'page') { if ($reset) $page->$name->removeAll(); $fields = explode(',', $value); foreach ($fields as $field) { $page->set($name, trim($field)); } }
-
Just did. So removeAll() is basicly what I need when reseting all data, thanks! Working nicely. Also add method. Remove isn't saying anything though - should it?
-
I've used Ryans CSV Importer couple of times when migrating MODX sites to PW and more than once noticed that all reported rows are not actually imported. My module does this also. I have 4210 rows of data in my csv and receive no errors during import. Counter confirms 4210 rows. But when I look to the parent folder in admin I see there's only 4187 pages inside. Maybe I should raise this question in ImportPagesCSV thread instead or am I missing something here? Again, functions are almost identical, at leat the part where errors are set: if (!$page->name) { if (!empty($pageName)) { $this->error("Unable to import product '{$pageName}'. It has no required 'title' field or it is blank."); } else { $this->error("Unable to import product. It has no required 'product_number' field or it is blank."); } return false; } $page = $this->savePage($page, false); if (!$page->id) { if ($this->options['csvDuplicate'] == 'new') { $page->name = $this->getUniquePageName($pageName); $page = $this->savePage($page); } else if($this->options['csvDuplicate'] == 'modify') { $page = $this->modifyPage($page, $data, $fields); } else { $this->message("Skipping row with duplicate product number '{$pageName}'"); } } I also print out success messages as rows in ordered list and after import, the last number in list is 4210. Wtf! What happend to those 13 pages?
-
True that. Looks like peole can organize their csv files decently since this hasn't pop up before My importer is about ready and it has quite similar functions than in Ryans. There's one oddity though: when modifying existing page, my module complained about not setting $page->setOutputFormatting(false). Still it's not needed in Ryans module either. Functions are almost identical: /** * Modify an existing page with CSV data */ protected function modifyPage(Page $page, $data, $fields) { $p = $this->parent->child("name={$page->name}, include=all"); $id = $p->id; if(!$id) { $this->error("Unable to load {$this->parent->path}{$page->name}/ for modification."); return false; } if($p->template != $page->template) { $this->error("Unable to modify '{$p->name}' because it uses a different template '{$p->template}'"); return false; } $p->setOutputFormatting(false); foreach ($fields as $key => $field) { $value = $data[$key]; $this->setValue($p, $field, $value); } return $this->savePage($p); } Is there any problem like this - shoud I set output formatting back to false?
-
OK, I didn't noticed that $parent was set as variable there. Thanks for support Wance! Speaking about Ryans CSV Importer, there's also var $pageName that's used inside importPage() method but I don't see it defined anywhere? protected function importPage(array $data, InputfieldForm $form) { ... if(!$page->id) { if($this->session->csvDuplicate == self::csvDuplicateNew) { $page->name = $this->getUniquePageName($pageName); // here $page = $this->savePage($page); } else if($this->session->csvDuplicate == self::csvDuplicateModify) { $page = $this->modifyPage($page, $fieldNames); } else { $this->message("Skipping row with duplicate name '$pageName'"); // and here } } ... }
-
OK, got it figured... Seems that it's safer to set values one by one. This got all values set to every Page fields correctly: // set page values else if ($this->fieldTypes[$name] == 'page') { $fields = explode(',', $value); foreach ($fields as $field) { $page->set($name, $field); } }
-
There is something weird happening with Page type inputs when I import values. Code for setting is like this: // set page values else if ($this->fieldTypes[$name] == 'page') { $page->set($name, explode(',', $value)); } For some reason I can only set values for Page fields that has PageListSelectMultiple set on Input field type setting. Page fields with Select or AsmSelect are left blank.
-
There's just one I don't understand here: when $this refers always to module itself, how can this work in Ryans CSV Importer: protected function modifyPage(Page $page, array $fieldNames) { $p = $this->parent->child("name={$page->name}, include=all"); $id = $p->id; ... } How can you get that $p under module parent->child? So just out of curiosity I tried in my module: die(var_dump($this->parent->name)); And got: Notice: Trying to get property of non-object.
-
OK, thanks Wanze! I actually had error in my loop. I was passing numerical key as $type. I didn't even think about it since I got titles imported just fine. @kongondo Yes, thats true when working with functions, but this is method from importer module - just copy-pasted two pieces for example. We're using Ryans CSV Importer as base for this module but it's gonna be simpler cause we don't need any options and it should be simple enough fo everyday use for our customer.
-
Hello all! I have a little problem with my custom csv importer module. There is public array available for field names and types that I use for looping: public $fieldTypes = array( 'product_number' => 'string', 'product_group' => 'page', 'product_family' => 'page' ); Then later I have setter, that takes Page as first parameter. Here problem is that I would need to acces $fieldTypes array but when dealing with pages, $this seems to reference to Page and breaks my code: protected function setValue(Page $page, $name, $value) { // here I receive warning for Undefined offset // since $this is referencing to Page if ($this->fieldTypes[$name] == 'page') { $page->set($name, explode(',', $value)); } } How could I have acces to $fieldTypes array in setValue method?
-
Of course... thanks! It works with reqular setter and you can set multiple values by using array: $demo->set('product_group', 1038); // append single value $demo->set('product_group', array(1041,1042)); // append multiple Cool! How about when you have need to update whole input - like in the example? I need to set it to 1040 and input already has two values 1024|1040.
-
Hello enibas! I believe you can achieve this pretty easily by using url segments. First, make sure url segments are enabled in homepage template settings and then try something like this in your template file: <?php // first segment is set if ($input->urlSegment1) { // third segment is set if ($input->urlSegment3) { // get page from actual path $p = $pages->get("/stuff/donation/$input->urlSegment3/$input->urlSegment2/$input->urlSegment1/"); // if page exists, render it and exit - else throw 404 if ($p->id) { echo $p->render(); exit; } else throw new Wire404Exception(); } // first segment set but no mathes, throw 404 throw new Wire404Exception(); } // begin normal homepage
-
I tried to set value with all these three variations: $demo->set('product_group', array(1040)); $demo->product_group->add($pages->get(1040)); $demo->product_group->add(1040); No effect. I still get original value (1024|1040) with: die($demo->get('product_group')); I know that it's possible to set values (page IDs) to Page input type by Ryans CSV import module and I see no special treatment there for any other fields than FieldtypeFile. I just can't figure out why set doesn't do anything here.
-
Hello Wanze, thanks for reply! Yes, product_group is a Page field and 1040 ID for existing page. Actually $demo page has already value set: $demo->get('product_group') will output "1024|1040" so setting it to 1040 shouldn't be problem. Setting some other field values works like excepted: $demo->setOutputFormatting(false); $demo->set('title', 'Cool Title'); $demo->save();