Wanze
PW-Moderators-
Posts
1,116 -
Joined
-
Last visited
-
Days Won
10
Everything posted by Wanze
-
If you are calling $page->next the magic getter is routing you forward to the $page->next() method. If you call $page->next('selector') you're calling the method explicit, so this won't get through the magic getter. In the first case you or by calling ->next() without arguments you want the next page (sort+1). But you're right.. I'm sure ryan has good reasons for the current implementation Edit: But still it seems not optimal that if you want to load the next/prev sibling, the current implementation loads all children under the parent... to return then only one
-
Wouldn't something like this be insanly faster when having lot of pages for the next/prev calls? // in Page.php switch ($key) { case 'next': // I'm sure there's a more elegant way... no time to go trough mysqli docs $p = wire('db')->query("SELECT id FROM pages WHERE parent_id = {$this->parent} AND sort > {$this->sort} LIMIT1")->fetch_row(); if ($p) { $id = $p[0]; return wire('pages')->get($id); } return new NullPage(); break; } Just did a quick test: Calling next on a page with 87941 siblings: Current implementation: Loads forever... i stopped :-P With sample code above: in some milli seconds the next sibling was loaded
-
Of course, but I guess the translated titles are used in another place of the site, just not in the switcher.
-
@Soma As far as I understand, he has this setup already but wants to output always the same titles in every language. Meaning: Leaving the titles translated BUT not use the translated title in the language switcher ;-) Try this: foreach($languages as $language) { if(!$page->viewable($language)) continue; // check if page not published for this language $url = wire('page')->localUrl($language); $title = $language->title->getLanguageValue($language); echo "<li$class><a href='$url'>$title</a></li>"; }
-
@teppo Sorry you're right! I just looked at the method that is then returning the next child, PageTraversal::next() static public function next(Page $page, $selector = '', PageArray $siblings = null) { if(is_object($selector) && $selector instanceof PageArray) { // backwards compatible to when $siblings was first argument $siblings = $selector; $selector = ''; } if(is_null($siblings)) $siblings = $page->parent->children(); else if(!$siblings->has($page)) $siblings->prepend($page); $next = $page; do { $next = $siblings->getNext($next); if(!strlen($selector) || !$next || $next->matches($selector)) break; } while($next && $next->id); if(is_null($next)) $next = new NullPage(); return $next; } In our case $siblings is null. So the method above loads all the siblings to return only one!! Hmm... Thinking the next/prev/child calls could be optimized with a database query?
-
ProcessWire conference, Switzerland (central europe)
Wanze replied to Soma's topic in News & Announcements
How about a conference this summer? Ah wait.... no summer in Switzerland this year. Let's postpone it to next year Edit: The crying smiley isn't working :'( -
Hi guys I don't think that performance is a problem with this code. Teppo, with your solution you are only checking for the first child or next sibling. Pw does not load more pages than one. But as you mentioned, be careful when using next() / prev() / children() methods, as you can get lots of children loaded in memory. Note that next() != next Edit: Sorry, wrong thinking. See teppo's post below
-
Well, the method localTitle doesn't exist. So you have at least 2 easy solutions: 1) Like I said: Add the textfield to language template and insert the title you want to appear in every language. 2) Code something, e.g. // Keys are IDs of languages... you could also use name $localTitles = array( 1234 => 'Italiano', 1235 => 'English', 3147 => 'Francais', ); foreach($languages as $language) { if(!$page->viewable($language)) continue; // check if page not published for this language $url = wire('page')->localUrl($language); $title = $localTitles[$language->id]; echo "<li$class><a href='$url'>$title</a></li>"; }
-
Lots of images to resize -> timeout in frontend...
Wanze replied to titanium's topic in General Support
Hi titanium You should try the following steps: Make sure the images are getting resized after uploading. Doesn't need to be the exact size of the thumbnail, but a reasonable resolution for web eg. 1280x1024 max. depending on your needs. This option is in the images fields settings. Maybe increase PHP's memory_limit for faster image processing. @adrian Problem is that when the client uploads monster-images (high resolution, big filesize), it takes time to make the thumbnails. If this time passes the 30 seconds set with max_execution_time defined in php.ini, you'll get that error. -
@moreweb If you need another translation just for the switcher, add a new text field to the language template e.g. 'titleSwitcher': foreach($languages as $language) { if(!$page->viewable($language)) continue; // check if page not published for this language $url = wire('page')->localUrl($language); echo "<li$class><a href='$url'>$language->titleSwitcher</a></li>"; }
-
May I ask the question: Why this setup? Makes no sense for me if you are redirecting Home to Root, why do you need Home?
- 12 replies
-
- 1
-
- navigation
- redirect
-
(and 3 more)
Tagged with:
-
Bootstrapping Processwire to my Websocket server problem
Wanze replied to Harmster's topic in API & Templates
Yep, they are equivalent. Problem is PHP related: In a function, the variables outside are not recognized - out of scope. So in this case here, it's the $wire variable which is unkown IN the function. Outside the function, it should work I guess. There are quite a lot of topics dealing with this problem, but usually its the $pages or $page variable which does not work, but same story here with $wire. For further information: http://php.net/manual/en/language.variables.scope.php -
How to Access Same Website Locally and Non-locally?
Wanze replied to fastpurplemedia's topic in General Support
I don't understand your question so I guess this isn't the answer you're looking for: Open two tabs or two different browsers and switch for copy/paste. -
Bootstrapping Processwire to my Websocket server problem
Wanze replied to Harmster's topic in API & Templates
Always in functions: wire('pages')->get() // Not $wire->pages or $pages Seems like this problem comes up twice per day Does it work? -
No idea why the '+' sign is removed. It happens here: // disallow some characters in selector values // @todo technically we only need to disallow at begin/end of string $value = str_replace(array('*', '~', '`', '$', '^', '+', '|', '<', '>', '!', '='), ' ', $value);
-
Hi Roope Always use: $selectorString = $sanitizer->selectorValue($stringWithCommas); Pw sanitizes the selector string e.g. quotes it when there are commas present.
-
Hi Peter, That's because all the API variables like $users, $page, $pages... are not known to the function. PHP - scope problem. The solution is to use the global wire() function from Pw to get the API variables: $vista = wire('page')->vista; // ... if (wire('user')->language->title != 'no')) { // ...
-
Ability to define convention for image and file upload names
Wanze replied to adrian's topic in Wishlist & Roadmap
Pw is sanitizing the filename, meaning it replaces any problematic characters such as Umlauts (ä,ö,ü) and spaces with '_'. See Pagefiles::cleanBasename() // ... $basename = preg_replace('/[^-_.a-zA-Z0-9]/', '_', $basename); $ext = preg_replace('/[^a-z0-9.]/', '_', $ext); // ... -
Hi thijs, It's in the dev branch only. So you have two (there are more of course, it's Pw!) solutions: Use the dev version of Pw and get the page that rendered the template with $options['pageStack']. The method ryan mentioned in the post at the end. Before rendering the home template: $home->caller = $page; Then in your home template, you can access the caller page with $page->caller;
-
Unable to sort child pages within a top level parent.
Wanze replied to simonds's topic in General Support
This should be ok. Can you set $config->debug = true; in /site/config.inc.php? In order to get any error messages. I just looked at the Class that is handling the sorting: /wire/modules/ProcessPageSort.module. Maybe you could check in the method sortPages if the query is getting executed? -
Page exists but neither visible, nor accessible in admin
Wanze replied to valan's topic in General Support
You could go to phpMyAdmin, search for all Pages that have an empty title and give them a title. Or note the ID and then just enter this as ?id=xxx when editing another page. You find the titles in the table field_title under data. Edit: Soma's solution is simpler Cheers -
Unable to sort child pages within a top level parent.
Wanze replied to simonds's topic in General Support
Hi simonds, As a developer you'll love ProcessWire Hm sounds strange. Can you check if the template of the parent has a predefined setting for sorting the children? This setting can also exist on the parent page itself under the "Children" tab, at the bottom. Though Pw should give you a javascript message that the reordering isn't possible because the pages are sorted by field XY. Which version of Pw? Any 3thparty modules installed? Cheers -
According to the cheatsheet remove() takes either a key or an object. Maybe I'm wrong but when you write a page-id like 1040, this is considered as key which doesn't exist. So you could try this: // Remove 1st item $demo->product_group->remove(0); // Remove 2nd item $demo->product_group->remove(1); // Remove object $p = $this->pages->get(1040); $demo->product_group->remove($p);
-
"URL" Field type bug - doesn't allow dashes in domain
Wanze replied to jacknails's topic in General Support
WhoopWhoop! It's a php bug, see here: https://github.com/ryancramerdesign/ProcessWire/issues/187 -
Updating Repeaters via API - without removeAll()
Wanze replied to renobird's topic in General Support
Hi Reno, When you loop through your repeater, in each iteration you already get the page. So the additional find is not needed, but I guess it does not affect performance at all because the page is loaded already: foreach ($expenses as $rp){ // changed $expense to $rp // the following line got you the same page as $expense before // $rp = $pages->get("id=$expense->id"); // the repeater page we want to update $rp->of(false); // ...