-
Posts
680 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Jan Romero
-
$pages->find(selector) always return true
Jan Romero replied to adrianmak's topic in General Support
Next and prev return a single Page, not a PageArray, so you can’t count them. See the docs for $page->next: https://processwire.com/api/variables/page/ »This page's next sibling page, or NullPage if it is the last sibling.« This is the same for all properties and methods that return only a single Page, like $pages->get(), $page->parent, $page->rootParent, etc. If nothing is found, they will give you a NullPage, which always has the id 0. So you can test for it using one of these conditions: if ($page->next->id === 0) { /*$page is the last of its siblings*/ } or if ($page->next instanceof NullPage) { /*same here*/ } Since 0 evaluates to false you can also go if (!$page->next->id) { /*see above*/ } if you’re into the whole brevity thing. Sorry, can’t format on mobile. -
I actually think “page” is a stroke of genius. It keeps the learning curve low for beginners by giving them a word they can immediately understand and work with. You can either keep working under the assumption that a page represents an HTML document, or dig deeper little by little. You’ll install a module like Language Support, and notice that – what do you know – languages are pages, until you arrive at “everything is a page”.
-
Check this out. It tells you exactly what you need to do and shows you what your page will look like on facebook.
-
Regarding page reference for page/product's categorization
Jan Romero replied to adrianmak's topic in General Support
In your page field settings go to Input, expand “Custom PHP code to find selectable pages” under “Selectable Pages”. You can fill your input field according to the template of the page being edited, by checking $page->template: if ($page->template->name === 'News') { return $pages->find('parent=/categories/news/'); } else if ($page->template->name === 'Product') { return $pages->find('parent=/categories/products-type/'); } else if ($page->template->name === 'Picture') { return $pages->find('parent=/categories/pictures-type/'); } Make sure to remove all the other options from “Selectable Pages”. Sometimes they don’t get overridden properly. -
In the database it’s going to look the same either way: a table with two columns, user id and picture id. But since you probably want to show “this image has been favorited by 43 users”, rather than “this user has favorited 29 pictures”, I’d put it in the picture template. That way you can simply go $page->favs->count(), rather than $users->count("favs={$page->id}"). It would also be easier to select and sort pictures by number of favs. Have you considered storing the time of the favorite? Maybe this module will be of interest: http://modules.processwire.com/modules/fieldtype-page-with-date/
-
Hi ngrmm, the value of a checkbox is 0 for unchecked and 1 for checked, so to have checked pages at the top, you have to sort in descending order. Simply prepend a - to the field: $articles = $pages->find('template=x|y, sort=-highlight, sort=creation');
-
You can build your selector string like any normal string before you pass it to the find function. If a field has been left empty, you can simply not include it in the selector. $selector = "template=user, roles={$role}, include=all"; //fixed part of the selector that is always used if ($input->post('country')) { //sanitize etc. $selector .= ", country={$inputcountry}"; } //repeat for other inputs
-
Might be faster to just do a simple for loop from 2010 (depending on how far back your archive goes) to 2100 (or, say, the current year) and just check the page count for each year. That way you’re not loading any pages at all, and you don’t have to do any date magic. It would also probably result in shorter code. for ($i = 2010; $i <= date('Y'); $i++) { $c = $pages->count("template=artikel, publish_from>={$i}, publish_from<" . ($i+1)); if ($c > 0) $out += "<a href='/{$i}'>{$i}</a>"; } Maybe even throw limit=1 into the selector, or display the count for free.
-
Since you already have $references_parent in a variable, why not use $references_parent->numChildren(true)? It’ll give you the total number of children including pages that are hidden/unpublished/etc. Set to false to get only visibles. Another idea would be to use $r->sort. Even with manual sorting that should always be the highest number immediately after adding the page. Be aware that both these methods will lead to duplicate numbers if you decide to delete one of the existing pages! You should probably keep a record of the highest number assigned somewhere central, if you need these reference numbers to be unique.
-
For anyone wanting to getUnformatted regardless, you can do this: $page->getUnformatted('dates_table.begin_date'); /* Returns: * array(8) { * [0]=> int(1430863200) * [1]=> int(1433282400) * [2]=> int(1434837600) * } */ Also: $page->getUnformatted('dates_table.first.begin_date'); // Returns int(1430863200) $page->getUnformatted('dates_table.last.begin_date'); // Returns int(1434837600) So you can have your cake and eat it too without having to parse date strings. E. g. you can directly use the inbuilt templating syntax with formatted values, but if, say, you also need a locale aware day name, you can feed the timestamp to strfrtime().
-
The method get() returns only one page. Your code is looking for a page with the path /case-references/. If this path doesn’t exist on your site, you will get a NullPage. You can check if you got a NullPage by testing for $references_parent->id === 0 or $references_parent instanceof NullPage. Because you only get a single page from get(), your variable $num will always be 0, as page objects don’t have a count. To find multiple pages, you should use wire('pages')->find(). Unfortunately it is unclear which pages you want exactly. I’m guessing you want all the children of /case-references/. In that case, try wire('pages')->find('parent=/case-references/'). You may also want to specify the template of the pages you’re looking for. Also in your first line you are testing whether $page->id is false AND $page is unpublished. That seems like an unlikely combination, because the NullPage is usually published.
-
While Praegnanz do use ProcessWire in some of their projects, I doubt Computerbase.de is among them. Here is a German blog post about the project, where they say they were only responsible for the frontend design: http://praegnanz.de/weblog/computerbase-workflow Gerrit van Aaken of Pragenanz is one of the best-known German web developers and he occasionally posts here in the PW forums.
-
Of course you can totally roll your own table and SQL, but the “ProcessWire way” would be to have a Review template and a separate page for each review. There are a couple of different ways to model the relation between reviews and their pages, the simplest being just making them children. So you’d have --Listing (?? or whatever) ----Review 1 ----Review 2 If you don’t want to pollute your page tree with this, and/or have the convenience of editing reviews directly from the page edit screen, you may use a page field, a page table field, or possibly a repeater field. PageTable would probably provide the nicest UI for editors, if that’s a concern. If you’re interested in accessing the database, these threads about the $db variable may also be of interest: Functions/methods to access the DB? Reading and displaying data from a custom table
-
Is PW a "better" fit for my needs in regard to sort query results?
Jan Romero replied to ZionBludd's topic in Getting Started
Hi mattcohen, since you specifically asked about “more control over the results other than using foreach”, I’d like to add to the responses above that you can absolutely sort, modify, filter the results you get from find()! What ProcessWire’s $pages->find() gives you is a special kind of array object called PageArray. PageArrays have a number of methods detailed in the ProcessWire Cheatsheet. If you need to sort the gyms from your example by location after finding them, you can do this: $gyms->sort('location'); //Sorts ascending. For descending prepend a "-" like so: sort('-location') This may be useful if, for example, you want to output the same list of gyms twice. Once sorted by rating and once by location, perhaps. You can also use find() on an existing PageArray. Maybe you want to show all gyms, but feature the three top rated ones above. You may do something like this: //Find all gyms sorted by location $gyms = $pages->find("parent=/gyms/, sort=location"); //Copy the 3 with the highest rating into $top_three (another PageArray) //No need to go to the database again, because we have $gyms already $top_three = $gyms->find("limit=3, sort=-rating"); foreach ($top_three as $top) { echo "$top->title: $top->rating Stars"; } foreach ($gyms as $gym) { echo "$gym->title in $gym->location"; } -
My occam’s razor guess would be that PW couldn’t have anything to do with this at all, since it’s all server side, while Chrome only gets to see the final product. So it would have to be some local caching that Chrome does on its own. This admittedly dated SO thread shows a couple of settings that may be of interest: http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development
- 12 replies
-
- 2
-
- Developer Tools
- Chrome
-
(and 1 more)
Tagged with:
-
Hide single input field for specific user/role
Jan Romero replied to cabrooney's topic in Getting Started
There is this module by Ryan. Sounds like that’s what you want. Using the visibility setting to hide a field is probably a bad idea, because that will only hide it client-side with JavaScript. -
Isn’t it just this? $out = array(); foreach(Page::getStatuses() as $status=>$value) { if ($page->status & $value) $out[] = $status; } return $out; That should return an array with all statuses set for $page, right?
-
404 Error behavior for index.php/foo (Soft 404)
Jan Romero replied to webaff's topic in General Support
Jumplinks can handle this. I’ve had the same problem recently. I do also think ProcessWire should 404 these kinds of URLs, though. -
I just ran into an issue with ProcessPageLister that has been addressed in this commit, but still persists for me. Non-Superusers can’t find unpublished pages in the Lister (nor via the search box in the menu), even if they themselves unpublished them in the first place. The user can view and edit the page because his role has all permissions on the root-page template, but Lister doesn’t seem to account for inherited access. TBH I don’t understand why Lister checks access at all, considering there’s nothing stopping anyone from seeing unpublished pages in the page tree anyway, whether they can edit them or not? Or am I doing something wrong? @Beluga: I can’t reproduce this here. Are you using any modules that manipulate field markup?
-
Are you aware of this? What do you need help with specifically? You should be able to feed Instagram’s API URLs into $wireHttp->getJSON($url) and get the requested data back as an array. See here for more info.
-
Make assets from different pages accessible from a single URL
Jan Romero replied to charger's topic in General Support
As long as you don’t need to physically store the files in one central directory, I’d create a page that accepts the file names as urlSegments, and serve them from there. The file names would have to be unique anyway for your proposal to work, so you should have no problem fetching them. The only problem would be that this solution does not guarantee unique upload file names, because the files would still be in separate directories. You could ignore this or hook into the file upload somewhere to make sure. E. g. you may do this: $filename = $sanitizer->selectorValue($input->urlSegment1); $p = $pages->get('images=' . $filename); if ($p->id > 0) header('Location: ' . $p->images->get($filename)->url); else throw new Wire404Exception(); die(); Bit crude but you get the idea. -
On the edit page of the user role, below the checkboxes, it says: To do this, go to Setup→Templates and edit one of your templates. To keep it simple, you may choose the template of your Frontpage, as all other pages will inherit the permissions you set here. In the Access tab, check page-edit for the roles of your choosing.
- 1 reply
-
- 4
-
The maximum function nesting thing reeks of recursion. Maybe one of your widgets tries to render itself or some other page that also has this widget? Perhaps inside a prepended/appended file? Is _main.inc auto-appended?
- 8 replies
-
- 3
-
- widgets
- page field type
-
(and 1 more)
Tagged with:
-
Integrating a member / visitor login form
Jan Romero replied to thetuningspoon's topic in General Support
$username = $sanitizer->username($input->post->username); $pass = $input->post->pass; $u = $users->get($username); if($u->id && $u->tmp_pass && $u->tmp_pass === $pass) { ... } $u = $session->login($username, $pass); This is where you try to find the user by the submitted name and then check if you got one by seeing whether $u->id is 0. So what you want to do is, if you didn’t find a user with that name, assume that an e-mail address was submitted instead, and check that: // Get user by the input name $username = $sanitizer->username($input->post->username); $pass = $input->post->pass; // (password is irrelevant for this, so we don't have to repeat it below) $u = $users->get($username); if ($u->id == 0) { // no user was found, so let's do the same thing, only // this time, treating the input as a mail address $usermail = $sanitizer->email($input->post->username); $u = $users->get("email={$usermail}"); // select by matching the mail field } // Now do the same checks as before and see if // the user was found after all if($u->id && $u->tmp_pass && $u->tmp_pass === $pass) { ... } // log in with $u->name, the name of the matched // account, instead of $username. If only the NullUser // was found, this will be an empty string. $u = $session->login($u->name, $pass); -
Hi Jonah, welcome to the PW community! Your issues mostly seem to pertain to PHP, not ProcessWire specifically. To answer #3, you are correct in that there is no special ProcessWire syntax. In the code you show, there is nothing really “PW-specific”. What ProcessWire does here is provide you with variables you can use in your template, namely $page to access data related to the requested page. The PW-specific knowledge you need is not of syntax, but of those variables, their classes and their methods. In the example, you need to know what kind of object the field image_details is, so you can know to access it with foreach. In #1, be aware of PHP’s assignment and equality operators! In your if condition, you want to compare values, so you must use == or ===, but never =! You should also wrap the conditional blocks in {curly brackets}. It is not necessary if you only need one statement, but good practice if you ever need to add some more. Since it is a PHP question, I’ll let StackOverflow explain the difference between 'single' and "double" quotes: http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php Basically, it doesn’t really matter, but double quotes give you more functionality. I assume #2 is related to #1 in that you have overwritten $page->title with the string "home", because you used the assignment operator = instead of comparing with ==.