Jump to content

bwakad

Members
  • Posts

    450
  • Joined

  • Last visited

Everything posted by bwakad

  1. just a step closer. My link in displayed items is now: <a href="<?php echo $config->urls->root; ?>/uren/min/"><?php echo $child->uren->min;?></a> Where the page 'min' uses my browse template file. My browse template file holds this code: case '1192': // id of page min $selector = "template=child-template, uren.min>{$page->uren->min}"; break; $selects = $pages->find($selector); And includes my .inc file which then displays the foreach $selects etc. But somehow, I get back all items (below, equal, and above the value) from the selector...
  2. ok, I use range slider for min and max values. Then those are displayed on front-end. I would like those values to be as a link, so when I click on the 'min'-value, it will do a search for all pages that have this 'min'-value. example $pages->find("min-value >= $page->min-value")
  3. hmm... I really need to think about this. Normally, with any link in front-end I have: $page->fieldname->url. which actually is a page. From there in the template used for that page I have my function to select and output what I need. In this case "range slider", it's just a value. So my best bet is to make a parent page - range, and two child pages - min and max. Then use the template which will hold my function to do my things. At least that way, I could use the $page->fieldname->url as a link.
  4. Somehow, I don't think it is possible to make a link from the field rangeslider value and then get the list of pages back... don't know exactly how to do this: <a href=' $pages->find ( " range.min >= $page->range->min" ) ' > $page->range->min </a> The above code displays the array in the link (when hovering). I can click it, but it does nothing... So, lets say, on the current page the link (range.min is 30), then I want to click on that 30 and do a search for pages which have this value in that field to. Basically the link has to do this part: $pages->find ( " range.min >= $page->range->min" ) Now, in my search form I have this code, and is working fine. I just select the value and get to the search page: <select id='search_hours' name='hours'> <option value=''>Any</option><?php // generate a range of hours, checking our whitelist to see if any are already selected foreach(array('0-10', '10-20', '20-30', '30-40', '40') as $range) { $selected = $range == $input->whitelist->hours ? " selected='selected'" : ''; echo "<option$selected value='$range'>$range hrs</option>"; } ?> </select> Does anyone have tips to get me started how to do the same for a link?
  5. Yes that is true as well... As I said "unless I start deleting things". Since the function is used for my menu, it is less likely to delete one of those pages anyway. My template is used for parents AND child's. But my menu pages are parent of the root. I could refer to template id/name and use parent=1 (as the very root parent home), but I would end up with pages in them which need to be restricted for members only, and in that, need to be restricted by member roles. And what if I suddenly try to rename my template? Or use a different template? Page id would still hold, but I would need to change my code since I used template. I guess it all depends on the situation.
  6. I am sure there must be a quicker way for my function below, but I started with $id = array(01, 02, 03) while I might as well used it directly in the $selector, or even more compact, use it in $pages->find("id=01|02|03"). I am referencing pages considering the names of objects ... Page Names are the most likely to change; Page Paths can change when page name changes; Template Names can change. However, page id, and template id are still valid. But if you suddenly use another template for a page then only page id or page path is valid. So, unless I start deleting things, my best bet (if I know which id I need) is to use id's in a selector. That's why I use this function for my menu: function nav_browse() { // need this to use $page->id, or $page->name, etc... $page = wire("page"); // need this since I am using $pages->find() below... $pages = wire("pages"); // specify public pages for browse parents $selector = "id=1006|1008|1026|1077|1127|1138|1156|1183"; $selects = $pages->find($selector); foreach($selects as $page) { echo "<li><a href='{$page->url}'>{$page->title}</a></li>"; } } In my template i simply use: nav_browse();
  7. Never thought about this before, but now I am actually thinking, do I have to do something with my textarea on the form to make it only accept characters and spaces, rather then that someone can enter code? inside my form I have this, but this does not accept spaces.... pattern='[a-zA-Z]{30,250}' ... so maybe I only have to leave the number of characters in, and use one of the back-end things? the field I talk about is sanitized upon submission: $member_page->about = $sanitizer->textarea($input->post->about); I see in the back-end 'text formatters' but really have no idea what is best.
  8. Thanks Martijn (and others) Just to make it clear: The profile template (page) is just a holder for the form, and only visible to the current logged in user. 'profiel' is a text-area field on the form, and is now renamed to 'about'... (changed it today). the contactnaam is just a name as a contact person for a company, nothing more, nothing less, so no chance of messing things up there all fields have nothing to do with the core user template and content - I keep login / registration details seperate from normal content... But indeed, the example wanze gave is something I can try. Except for the if it exist part, since the page is created by default.
  9. The member (name) page already exist because as I said, it's created when they register. The profile page is accessible after they logged in and just to update or add something new to their member page. So, the current logged in user is posting to their own member page. I can't use: new Page() on the first line - maybe use something as $p = pages->get(/members/{$user});
  10. Okay, here goes... I have a profile page for users who are logged in. On that page I present a form which hold 3 fields: profiel, contactnaam and contactemail. I have added those fields to the member template. Each user get created a member page upon registration and the member page name is same as username. Now, underneath I have code from creating a new page but I actually need to use the existing member page so that form submission is storing the fields on that member (user) page. Do I have to make use of user id, or user name? $p = new Page(); // delete this? or how to change? $p->of(false); // sets output formatting to false in order to change field values. $p->parent = $pages->get("/members"); $p->template = "member"; $p->profiel = $sanitizer->text($input->post->profiel); $p->contactnaam = $sanitizer->text($input->post->contactnaam); $p->contactemail = $sanitizer->email($input->post->contactemail); $p->save(); // save the page $p->of(true);
  11. Thanks, I actually tried that before, but since I am moving all my selectors inside a function I tested the selector but eventually have to use the string: $selector= "string here". After that I use $selects = $pages->find($selector); If I use more common names for what I select I would end up with so much variables inside the function.
  12. I had trouble with this selector which Even if not logged in - the current page (which is a user name), should give me info about that user and a list of items (pages) created by that user. My selector was originally this for logged in users - works and handy on user profile template: $selects = $pages->find("template=child-template, created_users_id={$user}"); // find pages user created But I was concerned about this part, because I want it also to be independent on a member page: created_users_id={$user} And needed to make it look like: ={$page->name} I could not use : $page->createdUser={$page->name} - since I am looking for other then current page. createdUser={$page->name} - since the field does not excist. $createdUser->name; - I would have to use $page in front which does not work for me, and $pages twice does not make sence. $user or $users - will not work because I look for $pages Then I browsed the API again... and used: $member = $users->get($page->name) ; which simply returns the ID of the user with that name Now I can set the selector to: created_users_id={member}; And, as always - if there are some things wrong I appreciate it if you let me know!
  13. I have a browse.php template which includes certain layout. For my parent (field select) pages as well as their children I use the same layout. But for members browsing I use another layout. So 1 template, 2 includes. Using my first function (post on top) I did not really know how to implement the members code. But then I started follow a course and hence: Just to make my function selector look more nice I used switch() - learned in PHP course. Hope you guys like my efforts: function selects(){ // set required variables; $page = wire("page"); $pages = wire("pages"); $noresult = wire("config")->urls->root; $layout = "browse.inc"; switch ($page->id) { case '1006': case '1008': case '1026': case '1077': case '1127': case '1138': case '1156': // cases up until here have same selector, e.g. parent field select $selector = "template=child-template, limit=4, sort={$page->name}"; break; case '1171': // this case is for members, selector and include layout change $selector = "roles=member|employer|applicant"; $layout = "members.inc"; break; default: // this is the default if none of the cases match, e.g. children field select $selector = "template=child-template, {$page->parent->name}={$page->id}, limit=4, sort=-{created}"; break; } // construct what we are selecting. Now I do not have to use $selects = $users->find($selector); $selects = $pages->find($selector); // we output something else if nothing is there if (!count($selects)) { return "<div class='medium-12 columns'><h3>No items are found.</h3> <p>try searching through our indexes at <a href='{$noresult}'>ClientC</a> or use the search form on the right.</p></div>"; } else { // construct quantity found $message = "Showing {$selects->count} out of {$selects->getTotal()}"; // contruct pagination $pagination = $selects->renderPager(array( 'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>", 'currentItemClass' => 'current' )); // call layout for results: display quantity, paginator, foreach, and markup include($layout); } }
  14. this is also working: sort={$page->id}
  15. Or, as I did it, just use the menu to output only certain links if logged in: if (!$user->isLoggedIn()) { // menu link login here // menu link register here } else { // menu link profile here } for no direct access through url: on the profile page - if not logged in - session redirect to login, OR make it not appear in search/etc via admin settings. on the login page - after succesfull login - use session redirect to profile
  16. One thing i thought to be convenient (and as the course implies: during development) was the following code inside a function: var_dump(debug_backtrace()); It should be able to go through the steps inside the function one by one explaining what it did step by step. Unfortunately, it did not work for me and gave me a blank content page. Maybe my latest function was not good enough. lol
  17. Yes. I did apologized for not hearing the message itself. Did not grasp the underlying messages at first. Meanwhile I learn PHP as suggested by Martijn and others. And I hope, one day we can all drink a beer together (or some other flavor).
  18. Yeah... php.net is a good resource, although the community always have examples which look way to complicated for beginners. Anyways, I enjoy the course (lynda.com).
  19. Just as I always was thinking "you can find anything on the internet" - why need it? But a member of this community (don't know if I can say the name) was so kind to arrange for me to follow a php course. And I must say "1 day has given me so much more tips which I consider to be gold"! Array, loops, strings, operators, and more. Never knew there were so many things possible in the right context... I really like the way it is explained, for instance the =, == and ===. Or even the ' ' and " " differences.
  20. Those were good tips, saved me some lines of code/variables, is easier to read, and it is still working. It even saved me from a wrong ID in the array: function selects(){ // set required variables; $page = wire("page"); $pages = wire("pages"); $noresult = wire("config")->urls->root; // test array for parent page ID (on browse tpl) if(in_array($page->id, array(1006,1008,1026,1077,1127,1138,1156) )) { $selector = "template=child-template, limit=4, sort={$page->name}"; // example rootparent } else { $selector = "template=child-template, {$page->parent->name}={$page->id}, limit=4, sort=-created"; // example rootparent-child } $selects = $pages->find($selector); if(!count($selects)) { return "<div class='medium-12 columns'><h3>No items are found.</h3> <p>try searching through our indexes at <a href='{$noresult}'>ClientC</a> or use the search form on the right.</p></div>"; } else { // display quantity found $message = "Showing {$selects->count} out of {$selects->getTotal()}"; $pagination = $selects->renderPager(array( 'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>", 'currentItemClass' => 'current' )); include("browse.inc"); // holds paginator, foreach, and layout } }
  21. I am beginning to sound like britney "did it again". lol. Forgot that config also need wire in a function. Thanks for that. My function is now this (which definitely improved speed)! I just echo selects() in any page I want... function selects(){ // get required values; $current = wire("page")->id; $field = wire("page")->parent->name; $noresult = wire("config")->urls->root; // single and double comma was giving issues below so use variable // test array for parent page ID (on browse tpl) if(in_array($current, array(1006,1008,1026,1027,1077,1138,1156) )) { $selector = "template=child-template, limit=4, sort={$page->name}"; // example rootparent } else { $selector = "template=child-template, {$field}={$current}, limit=4, sort=-created"; // example rootparent-child } // need to define variable before count $selects = wire("pages")->find($selector); if(!count($selects)) { return "<div class='medium-12 columns'><h3>No items are found.</h3> <p>try searching through our indexes at <a href='{$noresult}'>ClientC</a> or use the search form on the right.</p> </div>"; } else { // display quantity found $message = "Showing {$selects->count} out of {$selects->getTotal()}"; $pagination = $selects->renderPager(array( 'listMarkup' => "<ul class='MarkupPagerNav pagination'>{out}</ul>", 'currentItemClass' => 'current' )); include("browse.inc"); // holds paginator, foreach, and layout. Include here so I can use this in function scope } }
  22. Just something I came across. Currently my home link (in header) is this and correctly send me to the home page: <a href="<?php echo $config->urls->root; ?>">Client</a> Now I am finishing my function which echoes the same line of code in a page. But apparently - used in a function (in function scope) I have to add a slash : / <a href="<?php echo $config->urls->root; ?>/">Client</a> Otherwise it will take url from the page you are on. On a side note: using a function for a selector has really speed up loading time on pages.
  23. Well, I guess you speak for the whole forum. It's true - we speak the same, but write different. btw: The assets loading was in response to your question. And the include still have to do with optimizing code. So in short they all fall within the same topic I guess and therefore would not be good to start yet another topic. But maybe we should have a guideline - what is allowed to ask; in what forum; when to ask; and by whom. I did not and never will ask anyone for an entire site to be rewritten for me. You already mentioned such thing before "letting others do the work for me" but I do not think this is fair to say. I never, not once, received code for a whole page which I could just copy and paste. I did however pick up on some of (your) tips regarding selector and template. From which I think is valuable information you gave me. If you could look at my code none of it would resemble any of yours or others. But all of this is really off-topic now. So, let me thank you for your answer. No hard feelings on my part.
  24. Yes Charles, I understand what you say, but agree with me what I mentioned earlier: "True I do not know all basics from memory. And I appreciate all answers, especially the one that can learn me something." My question was about this code: // it is less likely the ID will change while names can be changed and the code stay the same echo "<li><a href='{$pages->get(1026)->url}'>{$pages->get(1026)->name}</a></li>"; // more static, but when changing the page name, the code need to be rewritten echo "<li><a href='{$config->urls->root}members/'>Browse Members</a></li>; // automatic, although I'd probably need a IF for excluding menu items $menu = $pages->find("template=browse, parent=1, sort=title"); foreach ($menu as $item) { ?> <li><a href="<?php echo $item->url ;?>"><?php echo $item->title;?></a></li> Were Nik provided me with some changes that make sense to me as I also mentioned some were above. If after that there is a remark like this: "I don't want to be rude here @bwaked but the optimisation you need is studying some basic PHP." it does sound rude because it reads as if I myself need optimization. It would be different if it was: "for optimization you need to study (this or that) more on php". Probably my misconception of what was meant comes from my work which is law related. I used to read comma to comma, sentence to sentence, paragraph to paragraph. But as you read all my topics, most of them are friendly, useful for learning, and many times with a big thank you. What I usually do is try a search on google and hopefully come to a website other then PW so not to bother you guys. But in many cases any link points to PW back. I can't help it if PW is becoming google's favorite . As such I made the topic in here. All together I did had valuable feedback from Nik, the links to minify from someone else, and the mentioning about skyscraper's setup. But I think I better redraw myself from anymore questions.
  25. In general: I don't want to be rude as well, but many times it comes to that level (in answers) - it's always difficult to express yourself in written words. True I do not know all basics from memory. And I appreciate all answers, especially the one that can learn me something. But I have had the same answer (go study) on a question about functions, although functions in PHP are not very basic. How valid is such an answer? If we say 'studying some basic php' - and I add -> before we ask - it's basically telling me (and maybe others) 'not to ask any kind of questions'. But then again, who decides which question has to do with basic PHP? Questions are never without a reason. You learn from the answers and tips when people trying to help. It is never of use to only one person. It can be of use to many. And for the record: People study PHP, even basics for years, and still ask questions of any kind, including mine. Since this topic is marked as a HOT topic I do not think it is a wrong question! Among us (also in this topic) are developers with advanced skills in PHP whom debate about it. I did not see anyone tell them to study basics!? I hope this has nothing to do with the time being a member or not being a contributor. I merely ask questions when I do not understand or need some tips. The most easy thing to do is tell someone to study. The most difficult part is to put people on track.
×
×
  • Create New...