Leaderboard
Popular Content
Showing content with the highest reputation on 11/16/2016 in all areas
-
I was not aware of this section's existence, and since I've submitted a number of sites to the site submission page, I thought it may be good to post them here, too. So, over the past couple of years I've been using ProcessWire, I've had the opportunity to build a decent number of ProcessWire websites. I initially didn't like the idea of using ProcessWire when I was first required to use it, but I soon came regret even thinking that - ProcessWire is now my favourite CMS! Here are some sites where I've been the primary/sole developer (I must say, I did not design these sites, I just turned the designer's visions into reality: PROGRESS: A Creative Agency This is the second iteration of the company I work for's website. it was built to reflect our amended brand identity and scope as an agency. Hilton Extraordinary F&B This website is access only, so you will be unable to see the site in action, however, I have linked to our case study on our website which has some screenshots. Note that the app is being discontinued, since they want a single sign on system. So for one, it just wasn't going to be simple to do the SSO system on the app. And two, the app was kind of pointless anyway, and they just fell for the old "we need an app for that", when a responsive website is just fine for their needs. The Extraordinary F&B site also protects many important static files by restricting access to them, and using Apache X-SendFile to allow access to them when the user is authorised. TY Logistics This website is four a courier company based in the UK. The animating lines was fairly challenging, but I got there in the end. The animating lines work by generating an SVG path string on the fly, using various elements as reference points, setting the stroke-dasharray and stroke-dashoffset to the path length, and then animating stroke-dashoffset to zero. It utilises ScrollMagic for managing the scroll-based animations. Guy Hollaway Architects This website was built for an architects based in London and Hythe, UK. Folkestone Harbour Arm This was created to list events and information about the newly refurbished and converted Harbour Arm in Folkestone, United Kingdom. Unfortunately, there are no events on the site right now, which makes some areas look rather bare. However, there is a screenshot available on the page for this site on the sites directory. Visit Romney Marsh This was a budget-wise project to promote the Romney Marsh in the south-east of England. It features a Google Maps integration for the listing of attractions and accommodation. And has another, very similar map for events on and around the Romney Marsh. Hythe Care Homes This has to be one of the coolest care home websites I've seen! We developed a site for Hythe Care Homes, a care business consisting of three separate homes for old-aged people. More to come soon when I have time. On my lunch break right now, you see.11 points
-
I just had a duh! moment and thought I should share as it may be useful to others, especially PW beginners. I know a lot of you will go "yeah well duh...." and yeah, well I feel like a bit of an idiot but anyways.... I had a page outputting a table detailing data from about 200 records (PW pages). For each record it searched for child pages of a certain template, probably averaging 3 child pages per record and added some data from those pages to each row of the table. Simple stuff. The page was averaging about 12 seconds to load. Anyway, today I got frustrated enough to try to work out why it was so slow. Turns out I realised that the child pages I was searching for were all direct children, so I changed my search method from $pages->get(....)->find(.....) to $pages->get(.....)->children(.....) and blow me down the page load has gone from 12 seconds to a tad over 1 second. Turns out each child page had many child pages of their own (thousand of pages in total) and all these were being searched with the find() method. Stupid mistake, but I think right from the beginning of my learning of PW the find() method was ingrained. So hopefully this helps some newbies and others like me. Check out http://cheatsheet.processwire.com/page/built-in-methods-reference/page-find-selector/ and http://cheatsheet.processwire.com/page/built-in-methods-reference/page-children-selector/ for more info on these methods and others.11 points
-
First of all, your question is asking to compare apples to bananas. ProcessWire is first and foremost a CMS, but with a great (smallish) framework beneath it, whereas Laravel and the others you named are big feature-rich frameworks. But to answer it anyways: (In it's role as framework) I've never regretted choosing ProcessWire for what it does, but if so rather for what it doesn't. E.g. tests are first class citizens in other frameworks out there and ProcessWire doesn't have that. Also ProcessWire's core is not the kind of framework which does come with all batteries included. If you need more advanced features e.g. like queueing stuff for later processing or handling notifications it's often more manual work, than it might be in your alternatives. On the other hand you'll get great data-modeling tools and the accompanied backend nearly for free. If you rather want to compare ProcessWire to other CMSs the bullet-points would certainly be quite different, as the use-cases are probably quite different.5 points
-
Awesome tips that solves your dot filename issues, I want to throw in an other approach so you won't have that issue that often. When you change the user that runs apache, the ProcessWire install wil handle the renaming of the htaccess among other things. I only recommend this when you are the only user on your mac that uses the internal apache. Changing the user is quite simple: Go to /etc/apache2/httpd.conf, find the block that looks like the block below, and change the user and the group to your short username and the group. In the example I already did that with my name. After changing that name, restart apache and apache will run with You as user. this will solve a lot of user right issues. <IfModule unixd_module> # # If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # # User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services. # # User _www # Group _www User martijn Group staff </IfModule>4 points
-
I don't think this module has the option for overwriting, but this one does: It's a lot more than just a csv to page module so the config settings may seem overwhelming at first, but it should do what you want. You'll want to enable Update mode and maybe even define field pairings in the csv import settings. You may also want to set up config settings for specific pages. Anyway have a stab at it and let us know if you need help - probably best to respond in the module's support thread rather than here.3 points
-
Just tried this and it works: <img <?php echo $page->portfolio_images->first()->getCrop('portfolio-item')->srcset('portfolio-item'); ?> class="lazyload" alt=""> This was the first time I added CroppableImage to a project and it seems great. Some UI facelift here and there could be beneficial though2 points
-
also, consider buying PathFinder on your mac, you will have full control over your file system and will save you a lot of time. I am on a mac since september, and didnt opened the Finder since I tried this program.2 points
-
Thanks, I have moved it from body to html but it's still not perfect, though the bug doesn't appear here. I've removed it now entirely.2 points
-
Yep, that's it - removing the rule fixes the issue. The rule is on the html element actually: html.aos.AdminThemeDefault { overflow-y: scroll; }2 points
-
Welcome to the forum Another option (among others): http://trolsoft.ru/en/soft/trolcommander Free, and you can turn invisible stuff on/off. Or a Finder "extension": https://www.trankynam.com/xtrafinder/ Note that XtraFinder is a bit buggy (and/or Apple's Finder is buggy, so it is impossible to add these features properly by 3rd parties, which is quite possible... Finder has always been buggy too) Also, you need to disable System Integrity to make it work on 10.11 and above: https://www.trankynam.com/xtrafinder/sip.html I've been using XtraFinder for a long time, it is a great timesaver.2 points
-
OK, I think I know what the problem is. SessionCSRF.hasValidToken() doesn't use the argument passed to $form->processInput() to get the CSRF token. It references $input->post no matter what was passed to processInput(). And with an AJAX request $input->post is empty; it seems like it should use the argument passed to $form->processInput(). (Actually, it checks for extended HTTP headers when it's an AJAX request but if they aren't present it then directly references $input->post.) The solution is to set an HTTP header X-tokenname where tokenname is the CSRF token name and the value for the header is the CSRF token value. It's odd the $form->processInput($arg) does take field values from $arg but it doesn't take the token from $arg and instead directly references $input->post.2 points
-
Just been toying around with this a little more. You can now backup the settings for any module anytime you want using the "Backup Current Settings" button. You can also "Restore Settings from Backup" at any time. By default it automatically backs up the settings of any module when it is uninstalled, but you can turn this off if you want. Even with it on, restore on reinstall still has to be manually triggered anyway, so probably no real reason to turn off. And of course you can still manually import settings that you have pasted in from another install. Anyone have any further thoughts? In particular I am looking at @tpr (AOS) and @horst (ALIF) because they are the two module authors who I know have built some sort of dedicated settings backup / migration into their modules. Do you think it would be weird having this module installed and adding this functionality on top of what you have already built into your modules? I guess ideally if this functionality was in the core it wouldn't be an issue because you'd know that everyone has access to it, so no need to build it in.2 points
-
Just posting a teaser at the moment because I am not yet sure if this should be a standalone module, or part of the still unreleased Module Toolkit (https://processwire.com/talk/topic/8410-module-toolkit/). Now available here: https://processwire.com/talk/topic/15702-module-settings-import-export/ It is quite simple in its execution - it adds a Settings Import / Export collapsed fieldset to the top of the module settings page of all modules. You can copy settings from one install and paste into another and click "Import Settings". It works quite like PW's core template and field import/export functionality. Simple as that PM me if anyone is keen to try it before I decide where and how it should be released. Settings are automatically saved when you uninstall a module, so you have an easy way to restore them when you uninstall. Anyone have any thoughts on any of this?1 point
-
This is the first time that I'm going to post anything under the showcase forum, although I have a few ProcessWire powered websites under my belt. This one is special because I think the use case is somewhat unique. Caltex Loyalty Club - initial the situation Caltex Loyalty Club is a customer loyalty and rewards program of Caltex Palawan aimed to provide exciting promos and incentives their customers' continuous patronage. Caltex Palawan originally bought their system from a large software company that also provides card-based solutions. The previous system consist of the following: two high-end Dell servers that are located in two separate Caltex' offices traditional EFTPOS devices for reading loyalty cards MIfare RFID cards as loyalty cards Running within one of the Dell servers was a crude and barely usable loyalty/rewards manager application that runs the whole thing. Here's what I mean: You're free to imagine what the rest of the application looks like. The other dell server acts as a VPN server through which all the EFTPOS devices and the application server connect to. To cut the long story short, this setup was running smoothly for a total of 3 weeks before problems started popping up, mostly because VPN server did not have a static IP address and the EFTPOS devices could not connect. The developers refused to provide service to the system because Caltex Palawan does not want to shoulder the travel and boarding expenses of the developers (since it was just working 3 weeks). We were called in at this point (we being a local tech solutions provider in Puerto Princesa), and we made the VPN server work, but other problems soon surfaced. The whole system was barely working for about 3 years when they finally decided they were fed up with the customer complaints they keep getting everyday. Our Solution We studied the existing system for quite some time to examine where the problems we're coming from. The most obvious one we found was that because the servers were located inside Caltex Palawan's offices, the servers were prone to downtimes caused by power outages and internet connectivity problems. It was obvious that the better way would be a web-based solution that would always be online. We also wanted to replace the bulky and outdated EFTPOS devices with android based NFC device that are more portable, and easier to work with. We retained the cards that originally came with the system since there are thousands left unused, but eventually replaced them with NTAG stickers, and newer cards. To sum it up: A web-based application to manage the loyalty / rewards system Android based NFC device to read the loyalty cards NTAG stickers to act as loyalty cards ProcessWire to the Rescue Having used ProcessWire before, it was our best choice, after considering using Laravel, and other frameworks, because of ProcessWire's key strengths: all custom fields - no unnecessary bloat powerful api scalability Although this straight up looks like it's been lifted from processwire.com's front page, but this really is the case, and these are all we need from a web-application framework to do almost anything! All custom fields Since we are working with a unique dataset, it's impossible for us to find anything out there that would have anything even remotely close to what we need. In the beginning we were planning to use custom database tables that we would deploy alongside ProcessWire. I even posted one time in the forum, asking if there's any way to integrate an ORM library with ProcessWire, and the answer I got was that it would be redundant, and almost surely unnecessary. And this turned out exactly the case! When we designed our database (using ERDs), we we're delighted at how closely we were able to replicate our relational design using templates, fields, and pages. This is mainly due to FieldtypePage. We were able to create meaningful relationships within our templates. We ended up with ~60 templates and ~70 fields. Powerful API About 70% of our code are API calls. The rest are just control structures and simple computations. That's how powerful the ProcessWire API is. So powerful that we did not even need to write a single sql query to complete the whole project. We needed to handle user login, API has it. Session handling, API has it. Selecting and manipulating huge amount of interrelated data, the API has it! Scalability At the onset of the project, the existing CLC program already has some 20 thousand members with hundreds of thousands of transactions. Right now, our current system has around 500,000 pages and counting and were not experiencing any slowdown. How we used ProcessWire The first thing that we decided that our client would not be able to see the processwire admin page. We wanted to present them with a simplified UI that does not present them with anything they don't need. We created a whole frontend UI for the client to use. We had custom forms for all the pages that they can create, and all the actions that they can do. We, on the otherhand, use the admin backend thoroughly in continuously developing, and supporting the system. What the clients see vs what we see: Our setup ProcessWire 2.8 running on a LEMP stack DigitalOcean droplet AjentiV VPS manager Modules we used We used a very minimal amount of modules for the project: ImportPagesCSV - to import the data migrated from the old system FieldtypeDecimal - for all our decimal values Modified RestHelper - from clsource for all the communication between ProcessWire and our android POS app Modified PagesSum from esrch ProcessSelectorTest - for quickly checking some selections Things we had to do on our own Frontend user login Frontend password recovery Fine-grained permission handling for users Cron jobs for scheduled tasks. The rest are API calls, and business logic. The Result Our Caltex Loyalty Club web application is now running on its sixth month without so much as a hiccup! Compared to the previous system that was averaging 200 transactions per day, we are now getting 800 and it's growing. We are running 10 campaigns and promos simultaneously across 18 Caltex Stations all over Palawan, with 30 android NFC terminals communicating to a single ProcessWire installation. We are very happy with ProcessWire in terms of performance, ease of use, and most importantly it's simple and yet very powerful functionality as a web-application framework even though it doesn't primarily market itself as one. PS. Also one of the best things we experienced while doing this project is the awesome, unparalleled community support. Throughout the project, although we had a lot of moments when we just couldn't figure out what to do, never once did we have to ask a question in the forum. A quick search here and there, and someone already helped someone else that faced the same problem we were having. It's almost as if people are being paid to diligently answer all the questions! We most of the time just had to like an answer that was already there! Screenshots and photos Android POS terminals and CSR training1 point
-
Many thanks , Adrian! After adding that namespace and changed all wire("config") to $config , wire("fields") to $fields and wire("templates") to $template in instructions.php , all is OK! Thanks, again!1 point
-
1 point
-
1 point
-
FYI, AOS can also add custom js/css: https://github.com/rolandtoth/AdminOnSteroids#add-custom-css-or-javascript-to-the-admin1 point
-
I've never regretted choosing ProcessWire for any project. There have been a few times recently where I used Laravel, but those were projects where the decisions were made before my involvement. Don't get me wrong, Laravel is great, and I enjoy working with it. There wasn't really anything involved with those projects that made Laravel a better choice than ProcessWire.1 point
-
1 point
-
Got it working, the cron task call the PHP script. Now I am getting another exception, but I suspect my code MariaDB server - I will open a new thread, thanks for your help horst ! @Entil`zha could you update the module ?1 point
-
You can also try https://filezilla-project.org/ or http://www.freefilesync.org/, for example.1 point
-
At first I can't reproduce but there was a similar issue earlier with AsmSelect fields. The cause was that the "body" had an overflow-y: scroll; in CSS, removing that fixed it. If it happens again, could you check what happens if you add/remove "overflow" on body/html tags?1 point
-
Do you mean this button? MediaLibrary is meant to avoid adding files and images to every page anew. Such functionality would copy the selected file/image over to the current page, which would be the opposite. I seem to recall that there's been a module somewhere in the forum that lets you add files or images from other pages, you might try google search with site:processwire.com/talk/ to find it. It should be possible to tweak that module then to only allow MediaLibrary pages if that is your requirement.1 point
-
I completely agree with @Martijn Geerts - that's a much better approach, but I also think that as a developer it is important to be able to see hidden files, so I would still go with the terminal command to make these visible.1 point
-
To follow on from @szabesz - you should also consider Forklift: http://www.binarynights.com/Forklift/ - dual pane file manager, ftp and much more!1 point
-
I tried a few different things trying to get sub-selectors to work in the selector array format and I couldn't get it working either. Maybe someone else will chime in with a tip - otherwise I'd say it is a bug and you should create a GitHub issue for it.1 point
-
Awesome. Thank you both for you quick replies. I knew there must be a way! - D1 point
-
Hah. Someone was faster. Tip for the terminal: To get to that directory you can enter "cd " (cd with a space) and then drag the folder where the htaccess.txt is located into the terminal window. Hit enter. Then the terminal switched to that directory. Then you can use the "mv" command adrian posted above.1 point
-
By default Mac doesn't let you view "hidden" files which start with a period. You can change this setting in the terminal: defaults write com.apple.finder AppleShowAllFiles -bool YES killall Finder Then Finder should let you rename. Otherwise you can just rename directly in the terminal: cd /pathto_htaccess.txt/ mv htaccess.txt .htaccess Of course you could do it from anywhere without cd 'ing into the directory, but thought this might be easier to understand as I am not sure your experience level with terminal commands.1 point
-
I just converted all my code to use the string format instead and it is working, so this seems like an issue specific to the array format.1 point
-
Ok, the new version supports adding files and images. It works in both standard and field pairings modes. I haven't added support for descriptions/tags yet - will wait to see if anyone has the need. It should work for local server paths to files/images, as well as remote urls. Please test and let me know if you have any problems.1 point
-
Pretty much anything is possible with PW. Make a start by yourself and if you have any specific problems just ask in the forums.1 point
-
Well, most important thing is the compiler/namespace feature: https://processwire.com/blog/posts/processwire-3.0.14-updates-file-compiler-fields-and-more/ or in more detail: https://www.google.hu/search?as_sitesearch=processwire.com%2Fblog&as_q=recipe#q=namespace+site:processwire.com%2Fblog Non core/Ryan modules might fail, so it is recommended to read up on them too. And most importantly I would certainly clone it to a dev environment and upgrade that instance of the site firts, just to see what actually happens....1 point
-
Hi, Quick tips Bookmark these two Google queries: tutorial site:processwire.com/talk recipe site:processwire.com/blog Whenever you are in need, just edit the first words accordingly Learn by doing, eg: (4 part tutorial): http://blog.mauriziobonani.com/processwire-basic-website-workflow-part-1/ OOP is "easy", read this one once a month and also study simple ProcessWire modules: http://www.startutorial.com/homes/oo_beginner Find simple ProcessWire modules/profiles in the directory, install them, change them, abuse them. Sooner than you think you will get a hang of it.1 point
-
Here are two macros that I started to use recently to avoid passing full page objects and make things easier. I usually set "common" pages in ready.php like this: // Pages $view->homepage = $pages->get(1); $view->contactPage = $pages->get(1033); // PageArrays $view->menuItems = $pages->find('id=1010|1020|1030,sort=sort'); But instead of this I set only ID (selector): // Pages $view->homepage = 1 $view->contactPage = 1033; // PageArrays $view->menuItems = 'id=1010|1020|1030,sort=sort'; Now in latte template files I use the macro "n:page" or "n:pages", which automatically sets the "$p" variable ("$pArr" in case of n:pages). Basically it sets the context: <a n:page="$contactPage" class="contact" href="{$p->url}">{$p->title}</a> <ul n:pages="$menuItems" n:inner-foreach="$pArr as $p"> <li class="{$p|activeClass|noescape}"> <a href="{$p->url}">{$p->title|noescape}</a> </li> </ul> You can use this if you prefer "normal" macros instead "n:macros": {page $contactPage} <p>{$p->httpUrl}</p> {/page} And here are the macros (put it in site/ready.php): $view->_addMacro['page'] = array( 'page', '$p = \ProcessWire\wire("pages")->get(%node.word)', ';' ); $view->_addMacro['pages'] = array( 'pages', '$pArr = \ProcessWire\wire("pages")->find(%node.word)', ';' );1 point
-
Hi there, I'm not entirely sure what it is that you're looking for, but if your problems really start as soon as you step into the world of object-oriented programming, I would suggest grabbing a copy of Programming PHP (most likely available from your local library) and seeing where that takes you. If you want to really understand how ProcessWire internals work, it's important to understand how object-oriented programming works, and also how PHP works Other "general programming resources" you might find useful are the Codecademy PHP course, which is a pretty good introduction to many basic PHP features, and of course PHP: The Right Way, which is more a collection of best-practices, but contains a lot of valuable information nevertheless. Others can and will no doubt chime in and suggest tutorials, articles, etc. strictly related to ProcessWire, but in my opinion you should first make sure that you get the foundations right.1 point
-
I think the easiest way to do this is with Javascript/jQuery. Not too hard to write a script for this from scratch (that's what I've done in the past) but Google reveals a nice looking plugin that does it all for you: http://renaysha.me/anchorific-js/1 point
-
Hi, I am developing a site where I need to sum a specific field value across a large number of pages selected with a selector string. For example, I am keeping track of the stock of specific products. The stock is influenced by various stock movements. I have a template for stock movements, with fields "product" (Page type) and "quantity" (Integer type). Currently, I am searching for the pages and adding the quantities in two different steps: // For a given $product $movements = $pages->find("template=stock-movement, product=$product, quantity!=0"); $stock = 0; foreach ($movements as $movement) { $stock += $movement->quantity; } This is fine, but I am doing this very often, and I would like to improve the performance of this calculation, since the quantity of stock movements can grow very large. To do this, I was thinking of using the SUM function offered by MySQL to achieve similar optimizations as what is achieved by the $pages->count() function. Ideally, this would translate into a $pages->sum() function that could be called as follows: // For a given $product $stock = $pages->sum("template=stock-movement, product=$product", "quantity"); I have tried looking through the code of the Pages, PageFinder and DatabaseQuerySelect classes in the core to get some inspiration, but I fear that I don't understand well enough how the query mechanism works to be able to adapt it to create the function mentioned above. Could anyone help me with this? Thanks a lot in advance, Eric1 point
-
For Windows users there is the Laragon version: https://laragon.org/download.html1 point
-
It isn't designed to support this. But I also don't see much disadvantage for this usecase. Lets assume the width you want to support is 1400, 960, 480. Setup the image field with min-width: 1400 and min-height: 788 (= 1400 / 16 * 9) Create a cropsetting image16x9, call it with 100% quality as master-source for the variations $master = $page->images->first()->getCrop("image16x9", "quality=100"); $large = $master->width(1400); $medium = $master->width(960); $small = $master->width(480); Or directly use the markup srcset module from @tpr and only pass the master to it!1 point
-
Hi kongondo, Thanks for the quick reply and the welcome. I had actually already read the topic that you mention, and this is what prompted my need: I would like to save a "stock" field for each product, but this field would have to be calculated each time a stock movement is saved, and calculating this field is precisely what takes so much time. In the meantime, I continued looking into the problem, and I think that I came up with a solution with the following module: class PagesSum extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Pages Sum', 'version' => 1, 'summary' => 'Adds a $pages->sum($selectorString, $fieldName) function to sum the value of a specific field over a list of pages selected by a selector string.', 'singular' => true, 'autoload' => true ); } public function init() { $this->addHook('Pages::sum', $this, 'sum'); } public function sum($event) { $selectorString = $event->arguments(0); $fieldName = $event->arguments(1); // Find all the pages associated with the selector string $pageFinder = new PageFinder(); $idQuery = $pageFinder->findIDs(new Selectors($selectorString), array('returnQuery' => true)); $idQuery->set('orderby', array()); $idQuery->set('groupby', array()); $idQuery->set('limit', array()); $stmt = $idQuery->execute(); $idArray = $stmt->fetchAll(PDO::FETCH_COLUMN); // If no pages were found, return 0 if (count($idArray) == 0) { $event->return = 0; return; } $idString = implode(',', $idArray); // Get the table name for the given field name $field = $this->fields->get($fieldName); // If no field with this name is found, return 0; if (!$field) { $event->return = 0; return; } $tableName = $field->getTable(); // Run the SUM query $sumQuery = new DatabaseQuerySelect(); $sumQuery->select("SUM(data)"); $sumQuery->from($tableName); $sumQuery->where("pages_id IN ($idString)"); $stmt2 = $sumQuery->execute(); list($total) = $stmt2->fetch(PDO::FETCH_NUM); $event->return = $total; } } In my tests, it is about 60 times quicker to calculate the sum with the function $pages->sum($selectorString, $fieldName) than looping over the pages (for about 12000 pages). I would appreciate any feedback, in case there are any other optimizations to be achieved, or any errors I haven't thought about. And I hope that this might maybe be useful to others too!1 point
-
Can we have options for CC and BCC please ryan (and then Teppo in SwiftMailer )? It's not mega urgent, but these do come in handy in a few situations.1 point
-
You've found one of the times where a custom table would be best The connection is already done actually if you're using the same database as your ProcessWire install (may as well) - this way you can use the existing $database connection. SiNNuT's example above should probably be $mydatabase to differentiateas that bit of code is for connecting to another database entirely. PDO is basically a database abstraction layer (think my terminology is right there). The underlying database is still mySQL, but PDO means that the same queries could be used for many different types of database backend (Microsoft SQL server etc). There's an example from StackOverflow here that I'll borrow from and amend to do a basic query using ProcessWire's $database: http://stackoverflow.com/questions/767026/how-can-i-properly-use-a-pdo-object-for-a-select-query $query = $database->prepare("SELECT * from your_table where field_name = :name"); $query->execute(array(':name' => $name)); while ($row = $query->fetchAll()) { // Do something with your rows } The reason for preparing the select query with the :name placeholder (in this example) is that your variable (or string) for :name gets properly escaped to prevent SQL injection. It's a little more verbose, but it does the job nicely. I'm pretty sire you could just have done "WHERE field_name = $name" but the above is safer if you're not sure what someone might pass to that query. For your counting requirements you might be able to do adapt the following query from this forum topic: http://processwire.com/talk/topic/3515-processwire-24-compatibility-for-modules/ ): $query = $db->prepare("SELECT COUNT(*) FROM my_fake_table WHERE name=:name"); $query->execute(array(":name" => $name)); $count = $query->fetchColumn(); The queries are a bit different to regular mySQL, but there are a lot of PDO query examples out there - a quick Google search for PDO SELECT DISTINCT should get you started.1 point
-
Your simplest best would be to just extend ProcessWire most basic starting point, which is Wire. This enables your class to have access to API variables (through $this), enables any of your methods to be hookable (that you precede with 3 underscores), and makes the file possible to translate with language support. Another option is to extend WireData. This is the same as Wire, except that you gain $this->set() and $this->get() methods that are accessible both in and outside of the class. It essentially means your class can function as a shared data container. The set() and get() can also be accessed by $this->key = 'value'; and $value = $this->key. The last utility class to mention would be WireArray, which is meant for storing an array of objects. This one is a little more complex than the other two (though it's still quite simple), and I'm guessing it's not what you need in this case, so won't go into detail unless you want me to. You don't necessarily have to extend any of PW's classes. But if you want $this->property; access to the API variables, you'd want to implement your own __get() method in your class: public function __get($property) { return wire($property); // or Wire::getFuel($property); }1 point