Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by bwakad

  1. I even created the _init.php as per your example but no results if there should be one: // _init.php $sort = ""; // browse.php include "_init.php"; // some code to determine what $sort will be $sort = "sort by date …"; include "head.php"; // here is were my $sort get outputted ... include "grid.php"; include "foot.php"; // grid.php […] echo $content; […]
  2. Horst method is working fine to NOT display undefined variable. problem is this: on content (after head.inc) I define the variable value: $sorted = "sort by date joined (new first)"; So this method does not give undefined variable, but also does not display if there is a value! If I DON'T use the $sorted = ""; it gives undefined variable is there is no value, and does display value if there is one.
  3. Just for imformation: I have debug ON.... I tried Horst approach, but did not work: head.inc <?php include("./inc/functions.php"); // after this follows <html> <head> etc <body> opening functions.php : <?php $sorted = ""; // very first line //rest of code content.php : <?php include("./inc/head.inc"); // include something else - were variable is used ...
  4. Does anyone have a 'best practise' for defining variables? A PW function / practise? I was reading the _main.inc / _init.inc tutorial. In that, variables are defined as $fields, and used as : $variable append $field. Where as my $sorted is not a $field, so I use : $field append $variable. In head.inc I output: <h1><?php echo $page->title;?></h1> <h6><?php echo $page->get("extrainfo")." ".$sorted; ?></h6> The $sorted is a variable used only on certain pages. Obviously I get a undefined variable if I am not on a page were this is used. Using: if($sorted) echo $sorted; I still receive undefined variable because head.inc is loaded before content. I know php can do this with: <?php if (isset($sorted)) echo $sorted;?>
  5. sforsman and horst are right. fixed this. But I have taken this to another level - meaning re wrote the template code... hope I don't talk Hebrew to some of you. lol My tree looks like this: (All pages use the same template to display members, except the home and about). Home - browse - all members - - household - all members sorted on household value - - - partner - all members with partner sorted on name - - - roomies - etc - - etc - etc - About So my page path as example is /browse/household/partner/. No segments! All pages are actually accessible. The switch on my template determined on which page I was, but I used switch($page->parent->name) which lead to problems: Using page->parent I can only use as much of those as there are... and the third level "roomies" could never be a page->parent. It had to be the default case, which led to yet another problem: browse (first level) could be a page->parent but NOT when I am on this page... Just to make things simpler I use page->id for the switch. Next problem was my "filter". On the first level /browse/ and second level /household/ I wanted to filter and get their children pages. I was using a select dropdown (post) for this. It was working fine. Until I want to sort on those results. When I filter at /browse/ level for household children, I got the results. But using sort will only sort at page level. It will actually "stick" the ?sort=asc after the current page url (without considering the posted results). I will explain: If my current page would be /browse/ and I post to this page, the children from /household/ I would still be on /browse/. Using sort on browse would then give me /browse?sort=asc (on children of /browse/), not on /household/. So for the dropdown I converted this to normal url links. It now will lead to /browse/household/ which already give me the children, and then stick the "?sort=asc" after it (and will show all children of household sorted). This way, I can sort ID, name, created, page->name, and some more at any given results. It's now working as expected! I do want to thank you all for thinking with me on this.
  6. Should be correct like this, but sort is not working ... if($input->post->filter) { // post the criteria and sanitize them $filter = $pages->get("/{$page->parent->name}/{$page->name}/" . $sanitizer->pageName($input->post->filter)) ; if($filter->id) { $input->whitelist('filter', $filter); $filtering = "{$page->name}={$filter}"; } } if ($input->get->sort) { $sort = $sanitizer->pageName($input->post->sort) ; switch($sort){ case 'asc': $sort = "name";break; case 'desc': $sort = "-name"; break; // we don't set a default here when we did not click link default: ; break; } $input->whitelist('sort', $sort); $sorting = $sort; } else { // if not - then here we set a default sort } Array which return results was: $selects = $pages->find($selector); now is: $selects = $pages->find($selector)->filter($filtering)->sort($sorting); sort not working ...
  7. Well, can be I am not clear. The normal find() just give back all pages under the member-profile (member pages) The filter find() just give back pages under the member-profile (member pages) whith that particular field The sort - is sorting the normal find(), but NOT the filter find() @soma do you talk about this one? : $a->filter("selector") do I use it like : $selector->filter("{$filter}")
  8. btw, this is NOT in a function! Think it has something to do with this... First, the $filter GET page, and at the end of the file, find pages, but $sort should GET $filter value if excist. if($input->post->filter) { // post the criteria and sanitize them $filter = $pages->get("/{$page->parent->name}/{$page->name}/" . $sanitizer->pageName($input->post->filter)) ; if($filter->id) { $selector .= ", {$page->name}={$filter}"; $input->whitelist('filter', $filter); } } if ($input->get->sort) { // Sanitize the sort value $sort = wire('sanitizer')->name(wire('input')->get->sort); switch($sort){ case 'asc': $sort = "name";break; case 'desc': $sort = "-name"; break; default: ; break; } // Add sort to the whitelist... with the same name as the get var! $input->whitelist('sort', $sort); // expand selector with sort $selector .= ", sort={$sort}"; } else { // if not - then here we set a default sort //$selector .= ", sort={$page->name}"; }
  9. I already had that, just left it out (because of offtopic) thanks anyway!
  10. did not understand the message from diogo... but in the docs I see: get one, find the rest ... NOT find a couple, find the rest ... 1. normally: pages->find (" template=this ") 2. filter used: pages->find (" template=this , field=that ") 3. sort used : pages->find (1 or 2 , sort=likethis) it would feel strange hiding results through JS or CSS, and I do not think it's the way to do it.
  11. find find should not be good I think
  12. - EDIT - Question : when used a filter, results are less ... (obvious) ...duh. But IF used a filter, how can I sort THOSE results (collect the already obtained results and use sort on that ? So, here is the complete code - everything works, but not together ... // by switch I determine current page ... // if switch true, we know the path is " / browse / page->parent->name / page->name / ": $selector .= "template=member-profile, {$page->parent->name}={$page->name}"; // if switch false, we know the path is " / browse / page->name / " $selector .= "template=member-profile"; //I then have a select at the front-end: gives me a value (named $filter) if ($input->get->filter) { $filter = $pages->get("/{$page->parent->name}/{$page->name}/" . $sanitizer->pageName($input->post->filter)) ; // since it will be an ID if($filter->id) { $selector .= ", {$page->name}={$filter}"; $input->whitelist('filter', $filter); } } // I have links at the front-end ?sort=asc gives me a value (named $sort) if ($input->get->sort) { // Sanitize the sort value $sort = $sanitizer->pageName($input->post->sort) ; switch($sort){ case 'asc': $sort = "name";break; case 'desc': $sort = "-name"; break; // we don't set a default here when we did not click link default: ; break; } // Add sort to the whitelist... with the same name as the get var! $input->whitelist('sort', $sort); // expand selector with sort $selector .= ", sort={$sort}"; } else { // if not - then here we set a default sort } // at the end I use $selects = $pages->find($selector);
  13. That was funny, I took quite some time to debug this, but finally I knew what was wrong... On two pages I got an error like the text below. Specifically telling me the sort order... Error: Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pages.children' in 'order clause' (in C:\xampp\htdocs\mysite\wire\core\DatabaseQuery.php line 91) First I thought, must be because because I did not have pages containing this value. But it was never like that with PW. It would simply not let me see it if not found - it's the ease of PW! So then I deleted those pages, added new ones, no solution. Looked in the DB - nothing strange there... Looked at my selectors - nothing is wrong... What was the trouble??? Answer: reserved words! I had a parent page named "household", with you can guess it: a child named "children" and "parents". stupid stupid stupid. lol I guess I have to check my page names carefully: because a pages->find "parents" or "children" works as string, just not on the sort... in a DB action... - edit - so this was the problem : 1. goal: I want to sort on field value 2. goal: looking for template = member-profile 3. goal: using browse template for this 4. I am actually on the pages (using browse) which are used as a field value for member-profile pages... 5. assuming I am on /browse/household/children/ THIS $pages->find = " template=member-profile, {$page->parent->name} = {$page->name} " READ $pages->find = " template=member-profile, household = children " sort = "{$page->name}" // gives error - apparantly translates to sort on children(). I can't sort on children() pages I did not request. but here's the thing .... 5b. assuming I am on /browse/household/roomies/ sort = "{$page->name}" // gives no error - it translates to sort on roomies. And will work ... ?????
  14. Of topic, or dev topic, anyway's ...To me, foundation is becoming the perfect framework, easy and understandable. And PW it is great to use it for! But to make a layout (that takes small, medium and large screens into consideration), gave me some trouble using it in combination with PW image display resizing functionality. Foundation just shrinks away the image when put into a specified column. So if the PW resizing is bigger then the calculated foundation column size, it will become verrry small. But Foundation is building from small to large. And I took it the wrong way. On large screens I would have div's for columns to get a list layout. For example: 3 - 6 - 3. And I started adding the columns for small in those div's as well. Thinking, on small they will adapt... Wrong! Because they will float left until 12 columns are reached... So my fist attempt was: <div class='medium-3 small-12 columns'>content</div> <div class='medium-3 small-12 columns'>content</div> <div class='medium-3 small-12 columns'>content</div> But here's how I do it now (for the first "3" out of 12 columns): <div class='medium-3 columns'> <div class='small-12 columns'>content</div> <div class='small-12 columns'>content</div> <div class='small-12 columns'>content</div> </div> In this last code the medium basically get's ignored on small screens (as if it isn't there). And it will only list the small-12. Going back to medium screens, the medium get sized to 3 columns as we asked, and the small-12 get sized to full width of the medium-3. So, now I am just thinking 'containers', and work from inside to outside. Meaning I will always place an image in the smallest container.
  15. Well, you certainly made effort in trying to explain! Just to clearify this: find all pages - from this directory - but show only - if they have certain roles (page-view) They would be the current user... I can add a role, and I can add a user.... A user is a page; I can add permissions to a role, and I can add a user (page) to a role; At this point my page has a role, but you say it doesn't !? Sorry if this is a bit confusing... Now, this is clear (it's definitly not in the docs!) : $user = $users->get("johndoe"); if ($user->hasPermission("read-the-docs")) { echo "Sure thing, go ahead: http://processwire.com/api/"; } From this I understand, that whatever permission we set, has nothing to do with API and It's more like a text-placeholder to allow or disallow through template by just calling this string... while all this time I thought it was to set things in back-end that would not anymore needed to be restricted by if/then/else inside templates... Is page edit something to allow a user to edit the page by back-end?
  16. Would be nice to have a thorough explenation how to setup access. It might be me, but I never succeeded in setting this up the right way (at least, what I would like). Going to Access does not explain a lot. Docs neither. Example : permissions - I can add a new one. But what to do with it? it just has a title and name field... users - I can add users, and asign roles... roles - I can check what permissions they have, but how do you handle this in frontend, especially with new permissions. I find under permissions the "page-view (required)" rather confusing. If it IS required, why put it there? I would like to see a PW native function or something that said: find all pages - from this directory - but show only - if they have certain roles (page-view) That way, page-view would make sence to me. But as I said, it could just be me...
  17. Is this dynamic roles purely based on admin site access ( editors / moderators )?
  18. Hey cool... as you see - am thinking difficult! Your solution is more nice, thanks.
  19. I need to echo the field value in page array. No problem so far. But since I use a filter and all, I need it to be dynamic. The field is actually the current $page->title/name. I am in a foreach $selects as $member ... Normally it is: $member->household->title So I have this and wonder if this is the shortest possible scenario... any suggestions are welcome. <?php $value = $member->get($page->name); echo $value->title ;?>
  20. Understood. I was actually being put on the wrong track because the red box on error's showed me as if it strip down qoutes anyway. But it's a nice example for people anyway!
  21. Dang, I did not know this was a reall issue! For no reason today I used the single qoutes under the impression "PW does not mind"... but no results and I was thinking, what am I doing wrong? wrong combination (variable inside single qoutes): foreach ($pages->find( ' parent=/browse/{$page->name}/ ' ) as $filter) { good combination (double quotes = use brackets): foreach ($pages->find( " parent=/browse/{$page->name}/ " ) as $filter) { good combination (single qoutes = use concatenate ): foreach ($pages->find( ' parent=/browse/ ' . $page->name ) as $filter) {
  22. Well here are my thoughts... A: 2 pages would mean I have them either in the beginning or end of the url... buth their title would not mean so much - if thinking about content. would also mean I probably somewere end up with same data on 2 pages. SEO problem here. B: 1 page would mean I have twice data and markup on 1 page, had to use CSS to hide a part (but cannot use media query for that) so I would have to load YET another jquery of something else it will also mean I have to load the whole bunch of data to only show half. Also this presents yet another SEO problem. Hiding in css does not prevent reading from a crawler. C: urlsegments I could use the url segments to work with, it does require GET which is less secure then POST. In the end, when you have langues, AND pagination AND segments for this part, it would look like /?lang=en&page=3&view=grid or something similar. Moving through pages, I would need to make a adjustment to keep it in the segmentnr they are in. 1=a&2=b&3=c... I prefer to use native PW segments when they are needed especially for the pagination and language. Unless you change htaccess or something. D: Jquery, Ajax etc There are solutions, but they require a reload of the page (in my case) to get the value in the php variable... and I would need to use CSS - show and hide parts. They are overload in my opinion... I now have 5 lines of code - with only an if statement - and could even be simplified to 2 lines. Far less then using any of the other solutions. E: framework I use foundation, but on any framework, I simply use native parts which work everywere. And of course I could use native visibility classes to show or hide... but php requests had to be made anyway, for nothing, get processed, and is double load for nothing. I set up my pages with what I want to show, not what I want to hide - if that makes sence. Of course, any case is different I guess - but in the end PW get the job done. That's why I will never return to Joomla, WP, Drupal or any other
  23. I had been using RubberDucky, only available in US - used to bypass security and passwords on phone!
  24. SOLVED session part with layout... Ryan had a good example in this topic: https://processwire.com/talk/topic/1568-sessions-and-styles/?hl=%2Bsession+%2Blink#entry14252 Still open: how to set this for only few pages?
  25. The Jquery / javascript / ajax was not working as I already expected in my first post. In both files, the layout is different and some of the data. So changing only CSS does not help. Basically I just need to store this value in a session upon clicking something, then something like: if this is page xxx or yyy, layout is session value. But do not know how. Been browing the internet the whole day. Making it static I end up with 2 url's fetching (almost the same data) and if someone could say if that's good SEO speaking then okay : /path/to/page/list/page=2 /path/to/page/grid/page=2 If using other methods I guess I end up with a # in url, as long as session is in place i would not mind.
  • Create New...