Jump to content

Valery

Members
  • Posts

    121
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Valery

  1. Hey guys, I am confused: my repeater fields are not saved from the API. Here's the setup: 1. A repeater (named 'faqQA') which contains 2 fields: 'title' and 'body'. 2. A template containing the above repeater. 3. A page that uses that template and has one instance of the repeater. Everything was created in the admin back-end. Repeater values were filled with sample text. (The repeater is supposed to be a FAQ item collection). This is the code I have in my template: $cFaqPage = $page; $cFaqPage->of(false); $faq = $cFaqPage->faqQA; $cFaqPage->faqQA->get(0)->title = '1'; $cFaqPage->faqQA->get(0)->body = '1'; $cFaqPage->save(); echo $cFaqPage->faqQA->get(0)->title; // outputs "1" echo $cFaqPage->faqQA->get(0)->body; // outputs "1" die(); The script is supposed to update the values of the repeater fields with some new values, and to exit. However, when I run it and go the the admin back-end to check the page, I still see the old values in the repeater fields. This is quite sad, and I stripped my code down to basics and it's still not working. Any ideas where to look at? Thanks for your support in advance.
  2. Hello, I was experimenting with comments manipulation through the API and found that saving modified comments works when you specify the field name when saving your page. For example, the following does not work: $page->of(false); $page->comments->get(0)->status = -2; $page->save(); But the following does: $page->of(false); $page->comments->get(0)->status = -2; $page->save('comments'); Seems you need to specify the comments field name explicitly when saving the page.
  3. Geez! Thanks, man That's exactly what I was looking for! Also: turns out, the editor itself does the job of converting <'s and >'s into < and >
  4. Hello, everybody. I decided to give my users a rich text editor (CLEditor). How do I sanitize the input without ruining the HTML markup? $sanitizer->textarea(...) works just as expected--it strips out all the formatting. I would like to keep it but remove tags like <script> and other potentially dangerous items (?) It there a reliable approach to rich text sanitization? Thank you in advance for your ideas, help, hints and links.
  5. Thanks, Pete, Martijn. What I believe OPCache does is: 1. When a PHP script is invoked, it checks if it has one in the pre-compiled form already. 2. If it does not, it runs the script through the PHP parser, sends the output (if any) back, and caches the PHP script as a binary in the shared memory. 3. If the invoked script already exists as a pre-compiled binary, OPCache calls it from the shared memory saving a) the time to load the script file from disk; b) the time needed to parse the script. While ProCache (I misnamed it in my previous post) does the following (my understanding): 1. Keeps track of what PW pages have been previously called and caches them as static HTML files. 2. When a page is called, ProCache looks it up in the cache pile, and if the page is there, ProCache feeds it back to the user agent as static content. 3. If the cached page was modified, ProCache removes the static page for it. When the updated page is called again, ProCache repeats Step 1. Basically, if you have a PW+ProCache website that does not get updated often, you are likely to end up with all of its pages served statically in some certain time. When this happens, OPCache can still be useful because it will cache, well, ProCache itself.
  6. Hello everyone, I have a question to Ryan and the PW experts here: in the upcoming PHP release 5.5.0 we are going to see Zend OPCache, a caching mechanism similar to APC. How does it compare to Cache Pro? Will Cache Pro still be needed if OPCache is used? Just a side note: I am buying CP as soon as my web project goes into production simply because I love PW and want to contribute. But will it decrease the page loading time any more than it will be possible with OPCache? Thank you.
  7. Hello Ryan--and thank you for the tip!
  8. Sounds neat. And it's definitely easier to implement and more reliable too, since not all browsers send HTTP_REFERER.
  9. Thanks, Soma. I am developing a site where I use some self-made scripts to process forms from PW pages. PW displays a page with a file upload form. When submitted, this form is processed by a custom script which uploads the file and puts a link to it into the page. When done, the script outputs a header with the URL of the file upload page. This way the file does not get uploaded twice when the user presses F5 by mistake. So I need my script to know the ID of the page from which the form was submitted so that it could redirect the user back to it. I use the get("/url/to/page") method to get the referrer page ID, and it works. It's just that today I came upon the httpUrl thing and thought whether or not this might be useful for my task. Addition: here's how I find the referring page's ID: $pagePath = str_replace($_SERVER['HTTP_ORIGIN'], "", $_SERVER['HTTP_REFERER']); $refererPageId = $wire->pages->get("{$pagePath}");
  10. Hi guys, A quick question: I am trying to find a page by its URL. $wire->pages->find("httpUrl={$_SERVER['HTTP_REFERER']}"); This does not work and PW says Error Uncaught exception 'WireException' with message 'Field does not exist: httpUrl' Does anyone know of an elegant solution to find a page id by its httpUrl? Thanks.
  11. Thanks for the insight. Really appreciate your help with finding and counting vs just counting. Handy!
  12. Thanks, Soma. My bad, sorry. Everything's working now.
  13. Hello, everybody, I am trying to display the number of published articles per author. echo $wire->pages->find("author~=Sam Smith").getTotal(); PW says: Error Call to undefined function getTotal() However, the function is in the Cheatsheet. And second: why does echo $wire->pages->find("author~=Sam Smith").count(); give me "1001|1002" instead of the number of found pages? What's the correct way to count a PageArray size? Thanks for any help with that.
  14. Thanks a lot, mate! eq() was just the exact method I was after, Hope your expanation will help others like me who mix up arrays and objects
  15. apeisa, Wanze, Thanks a lot for your help. deleteAll() worked, of course. As did foreach( $wire->pages->get(1001)->nn_basic_page_file as $value ) { $wire->pages->get(1001)->nn_basic_page_file->delete($value); } However, I am still trying to understand how to delete files by ID, not by name. I know that $wire->pages->get(1001)->nn_basic_page_file is an array. Is there a way to access it by numeric keys? Like $wire->pages->get(1001)->nn_basic_page_file[0], for example?
  16. Thanks, Luis. What I am not getting is what kind of variable $files is. is it $page->files? just $files? @Apeisa, Thanks for the hint. I tried something like $wire->pages->get(1001)->nn_basic_page_file->pagefiles->delete(); The API cheatsheet says that pagefiles returns a $files array. But I keep getting the same error: Error Call to a member function delete() on a non-object Maybe somebody has a working code snippet that deletes a page file through the API?
  17. Nico, yes. I even renamed the field to something inconspicuous but it did not help. I try $wire->pages->get("$refererPageId")->nn_basic_page_file->delete(); ($refererPageId equals 1001 in this case) However, PW says: Error Uncaught exception 'WireException' with message 'Invalid type to Pagefiles::remove(item)' in /u/www/htdocs/wire/core/Pagefiles.php:189 Stack trace: #0 /u/www/htdocs/wire/core/Pagefiles.php(175): Pagefiles->remove(NULL) #1 [internal function]: Pagefiles->___delete() #2 /u/www/htdocs/wire/core/Wire.php(271): call_user_func_array(Array, Array) #3 /u/www/htdocs/wire/core/Wire.php(229): Wire->runHooks('delete', Array) #4 /u/www/htdocs/f.php(68): Wire->__call('delete', Array) #5 /u/www/htdocs/f.php(68): Pagefiles->delete() #6 {main} thrown (line 189 of /u/www/htdocs/wire/core/Pagefiles.php)
  18. Hello guys, I am setting up a page for news publishers to be able to upload PDFs. Some forum browsing helped a lot with gile uploads (thanks, Ryan!). However, I ran into a different kind of problem: I can add files to pages just fine but I do not know how to replace/delete them after! Let's say I have uploaded a file to a page. I can see it in the admin backend. Then I try to delete it using an API call ("file" is the name of a file field that I added to the basic-page template): $wire->pages->get("$refererPageId")->file->pagefiles->delete(); Doesn't work. Says, Error Call to a member function delete() on a non-object $wire->pages->get("$refererPageId")->file->delete(); does not work either. I've run out of ideas, and looking through the code did not help (I know php just enough to be able to use pre-defined functions). Could you please enlighten me on how to delete page files using the API Thanks a lot in advance.
  19. Hi onjegolders, You might try printing out all the fields of your page as well as their values. You will see if your page's headline field is there or not. foreach($page->fields as $field) echo "<p>{$field->name}: " . $page->get($field->name) . "</p>";
  20. Sorry, disregard this post. I really should read the (awesome) PW docs more attentively...
  21. Hello, everyone, I've been playing around with Processwire since late 2012, so I am pretty much a novice. Hope my question is not too dumb though. I seem to have a problem which I cannot solve on my own. I want to be able to have a PW page with some form which, when submitted, is processed by a separate script. I added a form to the basic-page.php template. The code of the form looks like this: <form id="f" action="/f.php" method="post"> <input type="text" name="char_name" id="ch_name" value=" "> <button type="submit" id="char_name_submit">Proceed</button> </form> f.php processes the submitted form. Here's what its code looks like: <?php // bootstrapping PW include("/u/www/htdocs/index.php"); if($input->post->char_name === null) echo "Form was not submitted"; else if(!$input->post->char_name) echo "Form was submitted but the value is blank"; //some debug echo $_POST["char_name"]; ?> The problem is, when I submit the form, I get "Form was not submitted" from the f.php script. echo $_POST["char_name"] works just fine. My PW installation runs on php5.3+nginx+OpenBSD. Could you, please, tell me what I am doing wrong? Why is bootstrapped PW not seeing my submitted form data? Thanks a lot for your help.
×
×
  • Create New...