Jump to content

thomas

Members
  • Posts

    189
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by thomas

  1. Hello, I'm trying to build a frontend form using on of my Page fields, but since I don't always want to offer every option of the page field, I tried rebuilding it. So instead of simply doing: $form->append($edit->getInputfields()->get('myPageField')); I used this: $field = $modules->get('InputfieldCheckboxes'); $field->attr('name', 'options'); $field->attr('id', 'Inputfield_options'); $field->set('optionColumns',4); foreach($options as $ci) { $checked = array(); if($edit->options->has($ci)) $checked['checked']='checked'; $field->addOption($ci->id,$ci->title,$checked); } $form->append($field); (Where $edit is the page that's being edited, 'options' is an actual field in $edit's template and $options is a page array with some or all of the options in 'options') Now this works fine, but when I save the form foreach($edit->fields as $f) { $edit->set($f->name, $form->get($f->name)->value); } 'options' are correctly added when checked, but never removed when unchecked. I compared the form and the post data to when I simply use the 'options' field and I can't find any differences. I can loop over the options field and remove them manually but I just don't understand why it works with the stock field but doesn't when I rebuild it. Can anyone shed some light? Thanks, thomas
  2. Oh, sorry for being confusing. I delete those pages to get the most up-to-date data from the old site and because I like my import script better than FTP Also I get rid of all the test posts and test comments that way. My initial question was, how to fix that "no parent assigned" problem. Before anyone answered I figured out it was because the repeaters didn't get deleted. So yeah, I guess to give this whole thread a meaning, my question is: Why don't the repeaters get deleted? I'm using 2.2.9 with few modules. The biggest ones being module manager and formbuilder. Thanks Ryan! t
  3. Hi Ryan, I'm working on a relaunch of an existing site which has well over 1000 entries already. For that I build a module which downloads a JSON list of existing articles and rebuilds them for the new site. So I deleted all the articles in the local copy of the new site, moved the templates to the production server and ran the module, so it fills up the site with the most up-to-date data. My problem is, that the repeater fields never get deleted. I need to delete those manually in the DB, otherwise I get that "no parent assigned" error. But I found those fields in the DB now. My script for deleting the pages is this: foreach(wire('pages')->find("template=video,include=all") as $p) { $p->delete();} Thanks, thomas
  4. Hello, I'm just moving a site to a production server and deleted all my pages via the API. Now I try to re-import the pages again via a script but I get the error 'Can't save page: It has no parent assigned' when trying to add the repeater fields. I don't know what went wrong and how and where a parent for a repeater is assigned. Can anyone help? Thanks, thomas
  5. Hi, I'm experiencing Cache issues here trying to make the whole thing work. I'm using a session variable in each template to figure out which code to serve and everything works fine as long as I'm logged into the admin panel. If not, the whole system switches to random. I'm not yet all that familiar with PWs caching mechanism so has anyone got tips for me? Thanks, thomas
  6. Ah, now I understand: m.bmxrider and bmxrider are two different sessions! No wonder this acts so weird! So the next question is: Is there a way to make sessions work across subdomains? In this case here, it's not that big of a problem, but I have another site that depends heavily on session variables and I'd like to use the same mobile detect mechanism there. Or can I pass session ids when going to another domain?
  7. Hello, maybe it's too late or I had too little coffee or something else is sitting on my brain but I can't figure this out. I want to build a hook that determines if the User Agent is a phone and set a session variable accordingly: $this->addHookBefore('Page::render', $this, 'checkMobile'); function checkMobile(HookEvent $event) { $page = $event->object; $session = wire('session'); $domain = preg_replace("/^(m\.)/",'',$_SERVER['HTTP_HOST']); # this is to force one version or the other: if(wire('input')->get->v == 'desktop') { $session->isMobile = 'no'; } if(wire('input')->get->v == 'mobile') { $session->isMobile = 'yes'; } # /force # here comes mobile detection via Mobile_Detect if(!$session->isMobile) { require(wire('config')->paths->root.'/Mobile_Detect.php'); $detect = new Mobile_Detect(); $session->isMobile = $detect->isMobile()?'yes':'no'; } # /mobile detection # now for the redirects. This is cosmetics but I would like it to work: if ($session->isMobile == "yes" && !preg_match("/\bm./", wire('config')->httpHost)) { wire("session")->redirect("//m.".$domain.$page->url); } if ($session->isMobile == "no" && preg_match("/\bm./", wire('config')->httpHost)) { $session->redirect("//".$domain.$page->url); } } The idea is, that if someone visits bmxrider.de on a mobile, he gets redirected to m.bmxrider.de and $session->isMobile is set to yes so I can change the templates later on. I also like to be able to force each version by setting $input->get->v Whenever I use the query string to "force" a state, my site ends up in endless redirects. I checked the logs and it looks like $session->isMobile toggles between yes and no and I have no idea, why this happens. Can someone help me out? Thanks, thomas Update: The eternal redirect happens, when the domain doesn't match the query string. Like m.bmxrider/?v=desktop or bmxrider/?v=mobile
  8. Thanks Wanze, unfortunately I needed wildcards so I had to build my own method. I used your tip in another class ten minutes later though
  9. Thanks for the tip Ryan! I just tried it but the problem is I need the original sort order from the "views" table.
  10. thomas

    Koding

    Thanks to Diogo, I'm up next. PM me if you need/want an invite!
  11. Hello, is there a method to delete (expire) only selected cache files other than manually unlinking them? Thanks, thomas
  12. Cheers Ryan, I was trying to build an Ajax Form including image upload using the PW tools and the problem was which inputs to pass to the function. It turned out not woth the hassle though and now I use a regular form. Works great!
  13. Hello, I'm trying to build a form for registered users to upload images in the frontend and basically rebuilt an admin page. It all works great, upload, sort, all fields etc except for the "delete image" option. In the inputfield there's a checkbox to delete with value "1". This never gets checked or is anything but "1". I would like to know, how I can check if "delete" image was clicked? Can anyone help me? Thanks, thomas
  14. Hi Ryan, it's the latest stable and I deleted the pages using the api. I didn't know I could find the repeaters in the admin so I'll check that. The "pages" table in my DB now holds over 2000 pages and I only have a handful of pages in the admin ... Thanks, thomas
  15. Thanks for the info Ryan, I now changed the code to this: while($row = $result->fetch_array()) { if($video = $pages->get("id=".$row['video'].",category.id=17|23|9")->id) $bw->add($video); } thus avoiding the problem. Not sure if this is better or worse in performance terms but at least it works ... - thomas
  16. Hello, when I delete a page with repeater fields, the fields data stays in the DB. Is there a way to delete these or a way to find out which data in the "pages" table is from repeaters? I added and deleted about 4000 pages via a script and now my "pages" table is a mess ... Thanks, thomas
  17. Thanks again, I can't get it to work. Leaving the "id" will work a little better, but only with one id, not several id's divided by a pipe.
  18. Hi Soma, "views"is a simple table which writes a page id whenever someone watches a video on my site. I expect this to get rather large so I didn't want it to be PW pages. The query returns an array of page id's and works fine. As I said, everything works fine until I add "category.id" to filter (or "find", I tried both) ... I'll try leaving out the .id ... Thanks, thomas
  19. Hello, I have a fieldtype Page named 'category' in my pages. I want to find pages from several categories like this: $teaser=$pages->find("template=video,category.id=17|19|23,sort=-created"); This works great. Now I try the same thing on "my own" pageArray: $sql = "select distinct video from views order by created desc"; $result = wire('db')->query($sql); $bw = new PageArray; while($row = $result->fetch_array()) { if($video = $pages->get($row['video'])->id) $bw->add($video); } $teaser=$bw->filter("template=video,category.id=17|19|23"); ... now $teaser contains nothing. It works well when I leave out "category.id=[...]" in the filter ... Can anyone help? Thanks, thomas
  20. Hello, I was wondering if it was possible to hook before PageImages url is given, so I can provide a default image if an image is missing? I have about a hundred cases where I need to check for count($page->image), so I thought maybe a module could do this? Thanks! thomas
  21. Thanks a lot for the answers! Soma, that is just what I was looking for. I have a bunch of modules already, and this will help me put them in context! - thomas
  22. Hello everyone, my oop knowledge is pretty limited so please don't stone me for the forthcoming question: I have a rather large project which I'm moving from symfony 1.4 to PW (finally). I'm rebuilding most of the functions in modules with Page hooks, which at one point (now) leads to a naming problem. LIke a countMedia() method can be neccessary for many different contextes. - Is there a way to give a module it's own class name? So I can use $channel->countMedia(), $tag->countMedia(), both referring to different modules? - how do YOU deal with a large set of user functions that are needed in many different templates? Thanks, thomas
  23. Cheers for the answer, Soma! I'm talking about a user profile on the frontend, no PW user, so yours is pretty much the way I did it know. The whole question was more of a thought experiment if I could use PW to handle the include() decision for me.
  24. Thanks for your answers, I achieved want I wanted with hooking before render, now I only need to figure out if this is actually a good idea. Instead of using a lot of if() or different include() I thought I could use a different template for the current page, depending on a condition. So I built a "profile" template and a "profile_edit". If someone accesses his profile ('/profile/my_fancy_user_name') the link to edit his own profile is ('/profile/my_fancy_user_name/edit') ... it works, but I already encountered the first drawback: the two templates need to have the same fields. So I might just go for the "include()" Sorry, I should stop typing while thinking ... t
×
×
  • Create New...