Chris Rosenau Posted December 9, 2013 Share Posted December 9, 2013 I am going through the DEMO code and I came across this: wire('input')->whitelist('sort', $sort); It appears to be some function, but I can't find it. Can someone tell me what WIRE does and if there is any documentation on it? Thanks! Chris Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 9, 2013 Share Posted December 9, 2013 It's because of scope. This answer has been given atleast 10 times on this forum. In ProcessWire we have variables like: $page, $pages, $sanitizer, $config, $user, $input, $templates etc. Those can't be accessed directly in function or class scope. They can be accessed via wire('page'), wire('config') etc. etc. and you can access them inside a class witch $this->pages. ( depending on the scope of the methode inside the class ). The wire('') function can be from accessed everywhere. More information is given on the api docs an throughout the forum here. Don't understand me wrong but I think you should read http://processwire.com/api/ before or while exploring demo's etc. The next question could be, where can I find the methode whitelist. etc. etc. I've read the api docs many times. There's next to loads of information, a way of thinking. It's all written very well & it will make you understand the whole philosophy of ProcessWire and it's enjoyable. At first it's a puzzle, but when the first pieces are in place, the rest will follow. 5 Link to comment Share on other sites More sharing options...
arjen Posted December 9, 2013 Share Posted December 9, 2013 Everyone learns different. I tend to think I'm like you Martijn. First read as much as you can then explore the code. Some others dive straight into the deep. @Chris: you can use Google to search the forum. I.e. the query "site:processwire.com wire function" would have given you loads of information. 3 Link to comment Share on other sites More sharing options...
teppo Posted December 9, 2013 Share Posted December 9, 2013 .. and of course there's always GitHub. If you're really wondering "what is function x, where does it come from and what does it do", try searching 4 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 9, 2013 Share Posted December 9, 2013 Tnx Teppo, learned another great thing 1 Link to comment Share on other sites More sharing options...
alan Posted December 9, 2013 Share Posted December 9, 2013 @Chris Rosenau I also had a similar question to yours though I got there via a different route. Although what I've said below has already been answered by @Martijn I'll answer in the way that I 'got' this in case it also helps. I had been cheerfully using code such as: $input->whitelist('sort', $sort); (and $input is of course detailed in the API). But my uses had been in 'in-line' PHP code (not in functions). Then later I started to write functions and all of a sudden stuff stopped working, which is when I had what Martijn notes above explained to me, that the scope matters. In other words to do as I did above but in a function I needed to replace the 'special' / ProcessWire $input with wire('input') so the following is the same but will work in a function (or in in-line PHP code): wire('input')->whitelist('sort', $sort); Now when writing a function I automatically just see myself writing $something and replace it with wire('something'). And many just write the wire('abc') way all the time, whether in a function or not as it makes the code transportable (work whether it's used in a function or not). 2 Link to comment Share on other sites More sharing options...
Chris Rosenau Posted December 9, 2013 Author Share Posted December 9, 2013 Sorry, I have been looking through the API docs but didn't see this there. Also thanks for how to search the forums. Hopefully I will ask something more constructive next time. I love processwire and you guys are super kind for answering my basic questions. One of the problems I found was that the API docs at http://processwire.com/api/ are really basic. I did a search via Google as suggested above and found the full blown API docs located here: http://processwire.com/apigen/ Link to comment Share on other sites More sharing options...
Martijn Geerts Posted December 9, 2013 Share Posted December 9, 2013 It's like the game checkers, a few moves and no game is the same. And BTW, you're welcome. Link to comment Share on other sites More sharing options...
diogo Posted December 9, 2013 Share Posted December 9, 2013 One of the problems I found was that the API docs at http://processwire.com/api/ are really basic. I did a search via Google as suggested above and found the full blown API docs located here: http://processwire.com/apigen/ Basic but great The apigen docs were automatically created by scanning the code for classes and useful comments. They're not more than a nice alternative to reading the code itself. 2 Link to comment Share on other sites More sharing options...
pwired Posted December 10, 2013 Share Posted December 10, 2013 With this link http://processwire.com/apigen/ I found something about wire but nothing about wirecopy() that was mentioned by Soma. Link to comment Share on other sites More sharing options...
teppo Posted December 10, 2013 Share Posted December 10, 2013 @pwired: ApiGen docs are outdated, based on 2.2.0 codebase. Method wireCopy was added six months ago and isn't even current master branch yet. Link to comment Share on other sites More sharing options...
pwired Posted December 10, 2013 Share Posted December 10, 2013 Thanks for mentioning that Teppo. I looked at the code of wirecopy and found that the code: function wireCopy($src, $dst, $recursive = true) { if(substr($src, -1) != '/') $src .= '/'; if(substr($dst, -1) != '/') $dst .= '/'; $dir = opendir($src); if(!$dir) return false; if(!wireMkdir($dst)) return false; while(false !== ($file = readdir($dir))) { if($file == '.' || $file == '..') continue; if($recursive && is_dir($src . $file)) { wireCopyFiles($src . $file, $dst . $file); } else { copy($src . $file, $dst . $file); $chmodFile = wire('config')->chmodFile; if($chmodFile) chmod($dst . $file, octdec($chmodFile)); } } closedir($dir); return true; } looks very similar with what you find on google about copying a dir with php, like this code: copy_directory('/directory1','/public/directory1') function copy_directory($src,$dst) { $dir = opendir($src); @mkdir($dst); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($src . '/' . $file) ) { recurse_copy($src . '/' . $file,$dst . '/' . $file); } else { copy($src . '/' . $file,$dst . '/' . $file); } } } closedir($dir); } So for the moment I let wirecopy() be a part of processwire and concentrate on creating my own php scripts as I still need to learn a lot about php. I like to have a bunch of php scripts sitting there on my hosting server, that I can run directly from my browser. Fascinating all the things you can do with php. But of course if I could make a Tab or module somewhere in processwire, so that I can copy dirs directly from there, that would be even more cool !! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now