Jump to content

nik

PW-Moderators
  • Posts

    294
  • Joined

  • Last visited

  • Days Won

    4

Community Answers

  1. nik's post in inconsistent selector behaviour was marked as the answer   
    First I'd check and double check the code you're searching for is exactly right - but you must have done that already to be able to give such a detailed description. Still, could those codes for pages 99.. have for example a space in the beginning? To check if the issue is about getting an exact match you could try it out with $pages->find("code%=xyz"). If this gives you the right matches then it has to be something with the data.
    To check the data you could see the database directly. Something like "SELECT LENGTH(data), data FROM field_code" will expose codes that have a length different from what you're expecting. Be it a 6 or 9 letter string, don't know which as the length changed in you post .
  2. nik's post in possible bug in selector using `limit` was marked as the answer   
    I tried those out and they all seem to work as expected for me (using the latest dev, 2.3.8). What's the page tree like? In what context are you running that code, in a template file or a module? Are you able to reproduce this behavior on a clean install? Or with some certain steps taken from a clean install?
  3. nik's post in Create new page, if it doesn´t exist was marked as the answer   
    Hi Alejandro!
    That else-block is never executed, that's why the page does not get created and rendered. This is because $pages->get() "Returns a Page, or a NullPage if not found.". So $fwd is always an object (either a Page or a NullPage) and "if($fwd)" is always true.
    Test for the page id to see if you got a real page, like this:
    if($fwd->id) { ... } else { ... } (And remember to sanitize $transaction_id if it's part of user input.)
  4. nik's post in Limit selector in foreach not working properly was marked as the answer   
    First of all, my examples were not right - not at all, sorry. Now they're fixed.
    The problem is that you're limiting pages under each "subchild" separately, not all grandchildren at once. Here's one way to get there:
    $limit = 4; $cats = $pages->get("/mypage/")->children; foreach ($cats as $cat) { $menu .= "<div>"; $menu .= "<h2 class='titlebg'>$cat->title</h2>"; $grandchildren = $pages->find("parent={$cat->children}, limit=$limit, sort=-date, sort=title"); if($grandchildren) { // if they have GRANDchildren $menu .= "<ul>"; foreach($grandchildren as $child) { $menu .= "<li><a href='{$child->url}'>$child->title</a></li>"; } $menu .= "</ul>"; if($grandchildren->getTotal() > $limit) $menu .= "<span><a href='{$cat->url}'>See More</a></span>"; } $menu .= "</div>"; } This would give (with the example structure again):
    cat1 cat2 child2.1.1 child2.1.2 child2.1.3 child2.2.1 See More cat3 child3.1.1 This trick to get grandchildren ("parent={$cat->children}") would not be the way to go if there were a lot of "subchild" pages under any "cat" page. This is because the selector expands to something like "parent=1234|1235|1236|1237|...|1507|1508" giving a too long selector string at one point. But assuming there aren't more than a couple of dozen of them, this would work just fine.
    I also added a little condition to show "See more" only if there are more grandchildren to see - just as an example.
  5. nik's post in Searching pages with date like someday was marked as the answer   
    Yes, $pages is not defined and thus the error. Replace this:
    $day_shows = $pages->find("show_datetime={$this_date}"); with this:
    $day_shows = wire('pages')->find("show_datetime={$this_date}"); And the same goes for other PW variables listed in http://processwire.com/api/variables/. So $page --> wire('page'), $templates --> wire('templates') and so on.
  6. nik's post in Problem with the $page->find(); function was marked as the answer   
    Hi Gespinha,
    ProcessWire is trying to tell you that "projects" is not a valid selector. See http://processwire.com/api/selectors/ on how to write selectors, this being the key here: "An individual selector consists of three parts: the field you are looking for, an operator (like an equals '=' sign), and the value you want to match. For example, a basic selector might be: title=products".
    So you could use for example "name=products". But just fixing the selector is not enough here; you're using find() which returns a PageArray (even if there's just one match), not a single Page. If you're trying to get a specific page, you could use get() instead. It works like find() but returns only the first match (a Page object). Or you could say find()->first()->url to access the first found Page inside the returned PageArray.
  7. nik's post in SQL error 1170 importing PW database was marked as the answer   
    What you did earlier for table "field_body" was correct - I was trying to say don't apply the same fix blindly to all keys named "data" as they're not all the same.
    So, for table "field_body" change "KEY `data` ( `data` )" to "FULLTEXT KEY `data` ( `data` )" (as column "data" is of type MEDIUMTEXT in that table). But for table "field_display_specialty_footer" leave the key to what it was ("KEY `data` ( `data` , `pages_id` , `sort` )") as column "data" is not of type TEXT/BLOB there.
  8. nik's post in function with passing reference was marked as the answer   
    ..and there's no need to pass an object explicitly by reference in the first place. Just pass by value and it works as expected (for that part, that is).
    See PHP: Objects and references for more information. And in case it was for performance benefits, read "Do not use PHP references" as well.
  9. nik's post in How to check if a module is installed? was marked as the answer   
    You're very close actually . This is how it works:
    if($modules->isInstalled("MarkupBox")) {     // do something }
  10. nik's post in If statement inside recursive function was marked as the answer   
    If I've understood right you only need to get rid of the <ul>...</ul> wrapping the initial function call and modify the if-statement inside the function just a little bit to let it proceed on the first round even if there are no records found. Like this:
    <?php function listProducts($productCat,$level=0) {     $result = wire('db')->query("SELECT id, product, productcat FROM products WHERE productcat='$productCat' ORDER BY subcat");     if($level > 0 && $result->num_rows == 0) return;          echo "<ul class='sortable'>\n";     while (list ($id, $product) = $result->fetch_row()) {                     echo "<li id='item_{$id}'>\n";         echo "<div class='dd-handle'>{$product}</div>\n";                  listProducts($id,$level+1);                  echo "</li>\n";     }     echo "</ul>\n"; } ?> <div>      <h5>Products</h5>     <?php echo listProducts(0);//call the function ?> </div> As a side note, I usually build a simple safety net when using recursive functions just to be on the safe side if (when) there's suddenly broken data in the database. Here that would mean adding one line at the beginning of the function:
    // ~25 levels of product categories could be considered an error, I think. // Use something big enough to allow any legitimate data but small enough to allow the server stay alive. if($limit > 25) throw new WireException("Recursion gone wild"); While it's not necessary, it's a small price to pay for peace of mind .
×
×
  • Create New...