Tom.

Members
  • Content Count

    404
  • Joined

  • Last visited

  • Days Won

    6

Tom. last won the day on September 5 2018

Tom. had the most liked content!

Community Reputation

533 Excellent

About Tom.

  • Rank
    Sr. Member
  • Birthday 11/01/1992

Profile Information

  • Gender
    Male
  • Location
    England
  • Interests
    ProcessWire

Recent Profile Visitors

3,049 profile views
  1. Tom.

    I am very aware of what the functions API is vs the variable API. I'm mostly talking from the perspective of a new user coming into ProcessWire.
  2. Tom.

    I think there is still a big issue for the Functions API and variable API. As my understanding we are pushing the Functions API, however, the blog posts are still using the variable API in it's examples. I'm getting really mixed messages, are we pushing the functions API or not? I can see this starting to get really confusing for new people coming in to ProcessWire. I can see them building websites with a mix of Functions API and variable API with little understanding of the difference. For example, they may believe that to get page data you do <?= page('title') ?> but to sanatize the data you use <?= $sanitizer->text( page('title') ) ?> Honestly, I think we should just push one or the other. Sometimes using one and sometimes using the other is causing a lot of confusion. We run the risk of moving into WordPress territory where there are multiple ways of achieving the same thing. We will have people asking the questions, which one or which way is best. I just believe a decision needs to be made and run with it. At the moment, I have no idea which approach to use for my next project. I was edging towards the Functions API but I just want to use what is seen as the standard.
  3. Tom.

    I'm also having this issue, which isn't letting me use the date() formatting due to this. Also when it does jump to that, the time selector GUI doesn't work.
  4. Tom.

    It would be good if the new Sanitize method was the default for FunctionsAPI so you can use sanitizer($value, 'text') Edit: Never mind, it is, just the opposite way around. Does it work in the same way in that you can chain them?
  5. Tom.

    I never knew it didn't do this already?! I haven't been optimising me images when I thought they were optimised haha! I noticed the module had been updated today, however it doesn't seem to be this version. I'm happy to help test it.
  6. I think that the new documentation is more confusing than previously. At the begging it only shows a handful of variables, so I use $files->render() to put the header and footer in each template. I don't use Regions or anything like that as we very rarely have absolute consistency between each page. For example sidebar etc. We often keep the design across each page but the layout is different depending on the content. $files is now hidden a long with a lot of other variables. As far as I can tell, we are pushing the Functions API unless there is a reason not to use it (multi-install etc.). That's great but the documentation isn't the same. For example $files has everything in there render() etc. Meanwhile the files() page just has $wireFileTools = files(); and nothing else. I feel like if we are going to favour the Functions API there needs to be an emphasis on this in the API Reference. At the moment it's a little... overwhelming? I feel like it should be a tabbed layout, where the variable API is under a different tab, then the functions API is first. I also think that it should be listed as it was previously. I don't know, it kind of feels like we are pushing the Functions API as it's beginner friendly, but the documentation for that part is definitely not beginner friendly. Another thing for me is if you look at a Functions API function in the documentation the left hand sidebar pushes you towards the Variable API, I can see that also get confusing. I think because the Functions API and variable API are essentially the same, I feel like having them all mashed together will get confusing with beginners using a mixture of both in their templates. EDIT: I just found out that you can't use the Functions API while using files()->render(), so in my _header.php page() returns Fatal Error: Uncaught Error: Call to undefined function page() in _header.php:5 I guess it's something to do with scoping. So it's looking for the template _header? I'm unsure exactly. Would this also be the case for rendering fields? Like repeaters etc. If this is the case, I really can not agree that using Functions API is more beginner friendly. I do like the way it looks but I'm unsure if it's better for beginners at all. I mean, I'm definitely not a beginner and it's confusing to me. EDIT 2: After some research, you have to use $this->page('title') or $this->page()->title which is longer than $page->title. I guess maybe I'll look at a markup region method. Maybe I should be updating my template rendering approach? It would be good if there was a guide of "Best Practice in ProcessWire 2019" or something. At the moment things are lost in blog posts etc. Would be good just to have a new "Starter guide" page that talks about preferred output methods especially when it can cause issues with the functions api. Having looked at markup regions in the past, I just don't know if they are more confusing as it requires a more advanced setup such as editing the config page, but also looking at site-default site profile, the site content is passed through as a variable, which to me just doesn't feel right with more advanced layout websites. EDIT 3: Okay, so after some playing around, you can use a traditional approach to the templates using Functional API. files()->render() does not work, however, wireRenderFile() does. I don't have the technical knowledge as to why. But if you use wireRenderFile() you don't have to use $this->page() but page() will work fine. It's definitely a different way at looking at ProcessWire. I'm just keen to keep myself up to date with the latest, lets say 'code style guide' as that's important to me. If we are favouring the Functional API in future, then I'd want to start using it straight away. EDIT 4: Sooo.... wireRenderFile() works on the homepage, but not any other page so it seems. Yeah, this is just really confusing for me. It's a shame because I do really like the more shorthand way of writing. I just think it's not as simple as $page as it seems to be causing confusion with rendering files. I've tried every method and here is what I've found. Homepage: Works with wireRenderFile() and use of page(), it also works with files()->render() and the use of $this->page() Any other page: Doesn't seem to work with anything, you can use wireRenderFile() or files()->render() with $page but any form of include or render on a non homepage doesn't work with Functions API. EDIT 5: Okay, I haven't gone back and updated the OP, because I would like to document the experience of someone new exploring the Functions API. It appears that any wireRenderFile or files()->render() will work if you define the ProcessWire namespace within the _header.php, I don't know if this is an issue with the TemplateFile compiler. But if you define the namespace at the top of an included file, everything works as intended. EDIT 6: Having played with the Functions API for a while, I think it's definitely cleaner. I think one thing could be improved. So: // This is what it looked like echo $page->featured_post->title; // Which then becomes echo page('featured_post')->title; /* This feels strange to me because I like $page->featured_post->title as it feels like you're drilling down the array. However page('featured_post')->title feels slightly different. I can't say exactly why, but I feel like the following would be good: */ echo page('featured_post.title'); // I also think the same for pages if it's used in GET context, however this may cause confusion as this wouldn't work as a selector. But I guess they will have to know the different anyway. echo pages(1, 'title');
  7. Tom.

    Firstly, Great work on launching the new website! Looks great! The only feedback I have is a concern about the example code that is provided on the homepage. Which I believe may confuse some people. In 3.0.39 the FunctionsAPI was added (https://processwire.com/blog/posts/processwire-3.0.39-core-updates/#new-functions-api), which can be added in the config file, until you do that however, using functions will not work. Here are those examples: // Render your site’s primary navigation echo pages('/')->children->each('<li><a href={url}>{title}</a>'); // Find buildings: built before 1950, 10+ floors, sort by height pages('template=building, year<1950, floors>=10, sort=height'); // Get “email” field from /contact/ page and use it <a href='mailto:<?= pages('/contact/')->email ?>'>Email me</a> These will not actually work out of the box and cause Internal Server errors. I feel like most people learning will look at the API Reference, I don't believe that FunctionsAPI is very well documented. In fact, I doubt new people will read that far back in the blog posts. I do believe that there is a lot of functionality that gets lost in blog posts. What is everyone else's thoughts on this?
  8. Thank you all for your responses. This does in fact help! Turns out it wasn't a curl issue but trying to store and XML object as a session.
  9. I'm using PW's $session. function post_curl($url, $data) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); curl_close($ch); return $response; } $token = $pages->get("template=foxycart")->token; if($_POST['ThisAction'] == "CheckLogin") { $login = post_curl("https://teatumjones.foxycart.com/v/2.0.0/api_json.php", $_POST); if($login) { $json = json_decode($login); if($json->ok === true || $json->details == "Transaction not found") { // Set session to logged in. $session->logged_in = true; // Find user from FoxyCart and store as session. $user = post_curl("https://teatumjones.foxycart.com/api", array( 'api_token' => $token, 'api_action' => 'customer_get', 'customer_email' => $input->post->customer_email) ); $xml = simplexml_load_string($user); $session->customer_id = $xml->customer_id; } else { echo "User or Password incorrect."; } } else { echo "Unable to reach login server at this time."; } } Interestingly, the $session doesn't get removed if I don't use $session->customer_id = $xml->customer_id; I can use in it's place $session->customer_id = "Hello"; and that will be remembered. As soon as any $sessions are set using the $xml data. It just completely forget's all sessions set on that file.
  10. I was wondering if anyone else has come across this? I'm wanting to store information from a cUrl request in a session. The cUrl goes to an external API and does a POST request. I'm wanting to store the session ID after using curl, but I've found that setting any $session after cUrl will cause it to forget all $session set if you leave the page. It's such an annoying, weird thing that PHP does. I've tried using httpWire but that doesn't store the $session but at least it doesn't forget all other session data. Interestingly, the session is only reset if I try to use any of the data from the cUrl and store it in a session. Even if I set the response as a variable first.
  11. Hi @flydev To give a better example. Array 1 (All Pages): array( PageObject(1140), PageObject(1141), PageObject(1142), PageObject(1143) ) Array 2 (Updated Pages): array( PageObject(1140), PageObject(1141) ) Return Array: array( PageObject(1142), PageObject(1143) ) Basically, I want to compare array 1 with array 2 and get rid of things that exist in the array. PageObject is just a page item and (1233) is the page ID. I just made this up for example but it will be a PageArray instance.
  12. Hey, I have a complex bit of code that is working with product variations. I loop through variations that need to be updated (when modifying the variations in any way). I store these in a PageArray() and then I need to compare it against a list of pages. In this instance ->not() would work great, however it expects a selector. It needs to be an $item. What I'm trying to do is to remove a set of items from a list of other items using the API, using remove() or removeItems() deletes the repeater item, it doesn't remove the items from the array.
  13. Tom.

    I believe that ProcessWire automatically sorts out duplicates so you could do $Cats = $pages->find("parent=1086, id!=$page, sort=sort"); $Cats->prepend( $Cats->eq(4) ); foreach($Cats as $Cat) { }
  14. Tom.

    Hi @Nils Wiere If that is the exact code, there is a few issues. $pages->find("brand.title"); I believe will return any page that has a field brand assigned to it. You aren't referring to a specific template. You are also not telling it anything to search. I believe the code you are looking for is as follows. $brand = $page->title; $products = $pages->find("template=brands, brand.title=" . $sanitizer->selectorValue($brand) ); // OR If you want to avoid searching within a template. $products = $pages->find("brand.title=" . $sanitizer->selectorValue($brand) );