Jump to content

bmacnaughton

Members
  • Posts

    148
  • Joined

  • Last visited

Everything posted by bmacnaughton

  1. Thanks for the links. So if I am understanding correctly, you recommend creating pages with unique names for both situations: the SVG/PNG file pair and the unique-URL to SVG/PNG mapping, e.g., something like this (forgive any errors, I'm coding it right here): // create new page $p = new Page(); $p->template = 'svg-png-page'; $p->parent = '/repository'; $p->svg_png_name = $the_file_name; $p->user_id = $user->id; // populate other meta-data here $p->save(); So then, in another place, when I want to find all the saved images for this particular user, I would do something like: $items = $pages->find("template=svg-png-page, user=$user->id"); Then I would iterate on $items as any other array (or WireArray). And it would be similar for the unique-short-URL to image mapping - the template would hold a single field, a reference to the svg_png_name (or the page ID or a file), something similar to: // create new page $p = new Page(); $p->template = "unique-url-mapping"; $p->parent = '/maps'; $p->file = $the_file_name; // populate any additional meta-data $p->save(); Does a page have to have a name or title? Thanks for the pointers so far.
  2. Can you expand on this a bit or point me at some docs? Point me at an example code? I'm new enough to PW that what you're saying sounds good, but I'm not sure what to do based on it.
  3. I'm working on a web site that allows the user to create vector graphics that end up being saved as both PNG and SVG files. Each end-user is mapped to a PW user via their email. They can create as many vector graphics images as they would like, each of which is saved as PNG and SVG. We would like to make the PNG file directly accessible via a unique URL (not the actual file location). I'm kind of new to PW, so pardon me if I'm missing obvious things. My solution so far has been to store the files in a user-ID-based directory where the filename encodes various bits of information about the image. When the user navigates to their repository, the file names are read and packaged into a data structure for straightforward access. All of that is done with PHP code, nothing is PW specific. I arrived at this because I didn't know how to: 1) store an arbitrary number of SVG and PNG files in the DB in a way that links them to the specific user. 2) store the meta-information about the SVG and PNG files in such a way that it can queried seamlessly as other PW fields It seems to me that the only way to do this is to create my own DB tables (or single table that stores meta-information and a reference to the files or blobs if the files are in the DB). But maybe I'm just not looking in the right place. This also comes up in that I'd like to create a short-URL that maps to a specific file. Doing this with a separate table, where key short-URL maps to file-reference, is the way I'd naturally do it. But is there another way to do so? This may be a bit unclear, but the root of the question is how do I store an arbitrary number of items using PW?
  4. Yes, that's basically what I'm doing now except I'm using wireDecodeJSON because it will return an empty array for an empty JSON array. I don't have to special-case checks. Yes, I thought it would be a nice feature. I spent a lot of time trying to dig the payload out of $input before I gave up and went to PHP-native code. Thanks for looking.
  5. No, I hadn't but I just scanned through it. I don't see how it would give me the contents payload of an AJAX POST. I can see how to use this module to send a GET that returns JSON data (public function getJSON). Maybe I'm just not getting it but how would you use this to create a page to process an AJAX POST where the payload of the request is the JSON data? The issue I'm wrestling with is how to get the payload; I have a solution but was wondering if there was a better way. Reading back on my post I can see I wasn't as clear as I had thought - the web pages initiate JSON posts in JavaScript using JQuery's ajax function. The ProcessWire pages just handle the AJAX POST; they don't initiate them.
  6. I have a couple pages that just do JSON transactions. In them I confirm $config->ajax is TRUE and the $_SERVER['REQUEST_METHOD'] is 'POST'. But then the only way I have found to get the JSON payload is to use file_get_content('php://input') then use either decode_json or wireDecodeJSON to return an associative array. It would be great if the $config->ajax is set for PW to create $input->json (or possibly $input->xml if the payload is XML though I think that is less relevant). Is there a cleaner way to handle this than what I am doing?
  7. I can do that. I wanted to check to make sure there was no standard way to do so before I went that route. Thank you.
  8. I didn't ask this very well. I'm trying to find out if there is a way to specify the values at the time the field is being created, not within the field code itself. $field = wire('modules')->get("InputfieldPasswordGeneric"); I'm looking for the rough equivalent of: $field = new InputfieldPasswordGeneric($config); where $config is an associative array that can override the defaults for selected properties so the field is configurable. Does that make sense?
  9. I create a new user, add some custom properties to it, and save the user to the DB. But it appears that the custom properties are not saved to the DB. Is this expected behavior? What should I do to save custom properties in the DB? $u = new User(); $u->name = $form->get('username')->value; $u->pass = $form->get('password')->value; $u->email = $form->get('email')->value; $u->addRole('guest'); // add custom fields $u->validation = $validation; $u->timestamp = time(); // i can see in the log that the $user object has validation in it $log->save("wrote validation: $validation to user (\$u->$u->validation)"); // save the user to the DB $u->save();
  10. Don't I know it! Usually I try to explain to someone why the bug is impossible and it becomes obvious to me. But there was no one here for me to explain how right the code was.
  11. I would like to provide a way to for the caller to configure an Inputfield when getting it, i.e., when either __construct or init is called, as opposed to having to set each field independently after the field has been instantiated. How would I do that? What I have now: // get a password field $field = wire('modules')->get("InputfieldPasswordGeneric"); $field->attr('id+name', 'password'); $field->attr('size', 40); $field->required = true; $field->label = 'Password:'; What I'd like to do (conceptually): $defaults = array( 'required' => true, 'label' => 'Password:', 'allow_whitespace' => false, 'numDigits' => 0, ); $field = wire('modules')->get("InputfieldPasswordGeneric", $defaults); $field->attr('id+name', 'password'); $field->attr('size', 40); I could just create a property, like defaults, and decode that. But the code won't see that until rendering time so will have to do additional processing each render. It seems like it belongs at initialization or construction time.
  12. :\ I'm sorry. Thank you. I had looked at that many times and failed to see it yet it is so obvious now. I had specifically looked at my usage vs. the line that was there and just couldn't see the difference. Repeatedly. I don't have a good explanation. I owe you a beer. And I owe you a better question next time too. Thank you for pointing out what should have been obvious to me.
  13. PW 2.5.3. I tried changing the InputfieldText to Inputfield before I sent the last message and got the same result I previously did. The diff is an HTML side-by-side file. Nothing looks strange to me - that's why I'm looking for some external factor. Am I missing something obvious?
  14. The only difference I see (and I should have included this) is that I am extending InputfieldText. I just tried changing to Inputfield rather than InputfieldText and it doesn't change things for me. class InputfieldMine extends InputfieldText { public static function getModuleInfo() { return array( 'title' => __('Inputfield of Mine', __FILE__), 'summary' => __("Inputfield", __FILE__), 'version' => 101, 'permanent' => false, ); } I'm working on my own password from the existing InputfieldPassword module; I can send a the file if that would help but I've attached a compare. For me, looking it over nothing is obvious. Is it possible that the module is not installed correctly? My module name does not show up when I look at setup->fields. Thank you for the time you've already put into this. passwordcompare.html
  15. I've created an Inputfield module but have some questions about how the initialization works. The field works, but I don't understand how the class is being initialized and default values supplied to ___render. If I don't set the value in my code that executes wire('modules')->get('InputfieldMine') then no default value is supplied to ___render even though it's clearly set in __construct. Excerpted logic for my module/class (InputfieldMine): public function __construct() { parent::__construct(); $this->set('minLength', 6); wire('log')->save('trace', "__construct $this->minLength"); } public function init() { parent::init(); // other stuff $ml = $this->minLength; wire('log')->save('trace', "init $ml"); } public function ___render() { $ml = $this->minLength; wire('log')->save('trace', "___render $ml"); } I'm writing a log in __construct, init, and ___render. Excerpted logic from where I'm using the InputfieldMine: // get a my field wire('log')->save('trace', 'B4 LOAD'); $field = wire('modules')->get("InputfieldMine"); wire('log')->save('trace', "AFTER LOAD $field->minLength"); // ellided setting of attributes and properties $field->minLength = 6; wire('log')->save('trace', "AFTER SET $field->minLength"); $form->add($field); I'm writing a log before loading the module, right after loading the module, and after setting the minLength. The log sequence I get is: B4 LOAD __construct init AFTER LOAD AFTER SET 6 ___render 6 So it's clear that the ->get method causes both the constructor and the init function to get invoked as I'd expect. What's not clear to me is why the value set in __construct isn't get-able after $this->set('minLength', 6); is executed. The 6 is present in a var_dump - it's in the data: array['minLength']. If I remove the line: $field->minLength = 6; right before the "AFTER SET" log call then the value is null when ___render is called. What is the purpose of setting minLength to 6 in the constructor? And how would I cause the Inputfield to use it?
  16. Thanks for this. Can you expand on charset issues? If the DB and the site all use UTF-8 then I don't understand why this would be a problem.
  17. Are there any behind-the-scenes reasons that whitespace is not allowed in passwords, or is it a policy choice? I've found that people can remember phrases that mean something to them well so they make longer, more secure passwords/passphrases.
  18. I was able to delete after changing the permanent value in the module and refreshing. Thanks.
  19. I modified an existing module to experiment with creating an Inputfield module. While core modules are good examples, I shouldn't have copied the "permanent => true" part in getModuleInfo. Can I just delete that record in the modules table in the DB or are there dependencies I need to clean up?
  20. Thank you! (And I never even mentioned this was my first PHP project as well - maybe it was obvious.) I left out a few details that I'll fill in, but this let me find the issue. I'm running Ubuntu 14.04 LTS, 64-bit, with MariaDB, nginx, and PHP5. Ubuntu has a nasty habit of creating their own versions of builds for almost everything mostly due to the way they like things to be configured. In order to get readline support to begin with (the Ubuntu standard version didn't ship with it) I had to build PHP from sources. So I now have two different versions of PHP installed - one in /usr/bin and another in /usr/local/bin. And as you noted, they both use different php.ini files. It turns out the the command line php reference is more recent, but has an empty php.ini file. It's easier for me just to run the same one as the server even though Ubuntu has now updated their cli version to include readline support.
  21. Thank you. I looked for it on the site; never really thought to look locally. But your answer highlights where built-in modules are stored - thank you. This is also a missing piece for me in terms of how the API maps to the files that implement the function. Very useful answer.
  22. Where can I find a list of all field types? I've been to http://modules.processwire.com/categories/fieldtype/ and http://modules.processwire.com/categories/inputfield/. But while they list a number of field types they don't seem to list the basics, e.g., InputfieldText, InputfieldHidden, InputfieldSubmit. I am seeing these in the context of $field = wire('modules')->get('InputfieldText'). If someone can just point me at documentation for constructing fields in this way it would be great. In particular I'm looking for a list of the field types and what classes get attached to the items (or how classes are attached to them).
  23. Yes, it works fine - PDO support is apparently available. The installation program showed it present. I also just installed a new copy of PW and it installed, recognizing PDO was present.
×
×
  • Create New...