Jump to content

thetuningspoon

Members
  • Posts

    691
  • Joined

  • Last visited

  • Days Won

    6

Posts posted by thetuningspoon

  1. Hi Webrocker,

    I have a site with more than 3,000 pages representing individuals which are displayed in a Lister, and it seems to handle it without issue. What is your limit set to in the Lister's settings? If you try to display all of those pages at once you will definitely have a problem. But if set to ~50 you should be good, and Lister will automatically paginate the results for you.

    I find that filtering the pages is still very quick even with all those potential results.

    • Like 1
  2. I am experiencing an issue with the System Notifications module in 2.6.3. I am using a hook before saveReady() which does a call to PayPal and receives a response. I am adding some notifications based on the response I get from PayPal in order to let the user know whether it was a success or a failure.

    For some reason it seems that the extra delay in processing that this introduces results in the notifications not displaying when the page finally reloads. I don't see either my custom notifications or the built in ones confirming the page save.

    I've narrowed this issue down to the System Notifications module, since uninstalling it results in the notifications being visible.

    I'm wondering if anyone has thoughts on why this would be happening.

    Thanks!

    Edit: Just to clarify, this is when using runtime Notice objects.

  3. I'm a little embarrassed to admit that after several years of working in PW I still don't "get" output formatting in the context of saving pages and fields. 

    I understand that when I get the value of a field it is automatically formatted when output formatting is on, and that I can switch this off to get the unformatted value. What I don't understand is why I need to turn off output formatting when I am saving a new value to a page. It's output formatting, not input formatting, right?

    Even more befuddling to me is the fact that this often results in a fatal error if I forget to do it, crashing my site. I also have to remember to turn it back on again afterwords, or else I can introduce security flaws into my code.

    I'm sure Ryan must have a reason for requiring switching output formatting off when doing a save, but if this is so important and is always required, why isn't it just baked right into the save() method? 

    I know the new setAndSave() method now does this for individual fields. It would be great to have a similar method when saving an entire Page.

    • Like 1
  4. Thanks LostKobrakai, that is a big help.

    I wasn't sure about the distinction between when the db is and isn't accessed, since the selector syntax nicely hides that distinction from us :)

    So what you're saying is that I could create a property, but that it would only work on existing PageArrays and not when calling $pages or when using a selector with $page? I'm a little confused as to why it wouldn't work with $page since $page->myMethod() works just fine, but I get why it wouldn't work with $pages.

    So does this mean that the run time selector would not be any more efficient than my php loop with an if statement?

    What would be the best way to "cache those values in real fields"? Does this mean creating a new field in ProcessWire and writing a hook to update it on save(), or are there other ways of doing that?

  5. I've recently grown fond of using hooks to add custom methods to the Page class to operate on pages of a certain template. On larger projects this helps keep logic out of my template files and tied nicely to the objects they operate on. For example, I have a travel site that has a "departures" template with a field called "group_size". On the front end of the site, I want to show the integer value for the group size as it is stored in the page. However, I have another field called "overflow" which is the additional number of travelers beyond the publicly visible group size who are allowed to book a given trip, to account for anticipated cancelations. I wanted an easy way to know when I should close a given tour, so I created a method called isFull() to house the logic that determines this. I also have getMaxRegistrations() (group_size + overflow), getOpenSlots(), and getPublicOpenSlots(), which all call each other as needed and return different values.

    The problem then is when I need to use a selector, I have no way (that I know of) of using these methods in the selector. So instead I need to use a simple selector like $pages->get('template=departure') and then loop through the results and use an if statement on each result (i.e. if($result->isFull())... ) to narrow down the selection to the page(s) I really want.

    I don't know enough about how selectors work under the hood to know whether this is the same thing as a selector with a field matching parameter within it, or whether this is much less efficient. 

    Is there a better/cleaner/more efficient approach to this?

  6. Clarification... the page didn't allow me to save the self-referential value, but it did appear in the ajax search and allow me to select it from the list. This is a big problem for a site I'm working on at the moment.

    To solve this I had to edit InputfieldPageAutocomplete.module and add the following to getAjaxUrl() after the first line of the function:

    // Prevent selecting the page this field is on
    $thisPageId = $this->input->get->id;
    $selector .= ",id!=$thisPageId";
    

    It seems like this is a bug.

  7. Hi valan,

    Have you tested the module yet to see if it will work for your needs? I'm not sure I fully understand your question, but it sounds like you want to be able to set the visibility property of a particular page field to "Open when populated and not editable (locked)" but still have the edit link show? Is that correct?

    The issue with this and with the other limitation you asked about is the fact that PW doesn't always provide the necessary CSS/JS hooks to be as granular as I would like (strangely, it does for some of the inputfields but not others). Ryan may have fixed this in 2.6, but I haven't had a chance to look at it again. I would like to fix this at some point, if possible!

    • Like 1
  8. I found a bug:

    
            if(!$ptf->has($child->id)) {
                $pp->{$ptf->name}->add($child);
                $pp->of(false);
                $pp->save($ptf->name);
            }
    

    Should be:

    
            if(!$pp->{$ptf->name}->has($child)) {
                $pp->{$ptf->name}->add($child);
                $pp->of(false);
                $pp->save($ptf->name);
            }
    
    

    It was re-writing the PageTable items every time, which made it impossible to reorder items.

    • Like 3
  9. Hey Macrura!

    Your post got me going in the right direction. I had to modify it a bit. $config->urls->root->httpUrl returns an error, so I had to use 'https://' . wire('config')->httpHost . '/'.

    I'm also looking for links without the http:// and adding that in so that they'll work either way.

    Instead of just targeting the assets folder, I'm replacing all instances of relative links ('href="/' or 'src="/') and adding in the site's base URL. It seems to be working.

    $base_url = 'https://' . wire('config')->httpHost . '/';
    		$placeholders = array('class="align_left"', 'src="/', 'href="/', 'href="www.', 'src="www.');
    		$replacements = array('style="float:left;margin-right:20px;"', 'src="' . $base_url, 'href="' . $base_url, 'href="http://www.', 'src="http://www.');  
    		$body = str_replace($placeholders, $replacements, $body);
    
    • Like 2
×
×
  • Create New...