Jump to content

theoretic

Members
  • Posts

    101
  • Joined

  • Last visited

Everything posted by theoretic

  1. I've found the solution. Hope this will be helpful to someone ) //options for AsmSelect should be (int)key=>value pairs $options = [ 1=>'A value', 15=>'Another value', 200=>'And even more', ]; //default values should be array of keys, not values $defaultValues = [ 15, 200, ]; //options can also be an array of (int)keys $otherOptions = [ 25, 35, 45 ]; ... $config = [ [ 'name' => 'myField', 'type' => 'AsmSelect', 'label' => $this->_('My field'), 'options' => $options, 'value' => $defaultValues, ], ... ];
  2. Hm, not bad, not bad ) Could be a working solution if we'll extend the default Page class with some extra data. Thanks )
  3. Thank You @da²! Both ways are usable. But I still think it's a bit "patchy", especially hardcoding the paths/URLs of the default images. Having a "regular" image inputfield allowing to upload images, add some metadata to them etc. could be a much better solution. That's why I had the idea of creating the second set of per-template fields.
  4. Hi fellas! And thanks for Processwire! Couldn't find myself an answer to a question which appears to be not too complex. I'm developing a configurable module which uses a MyModule.config.php file to store its config fields. I'd like to use the AsmSelect fieldtype with some (maybe dynamic) options there. Basically it's dead simple: $config = [ [ 'name' => 'MyFieldName', 'type' => 'AsmSelect', 'label' => $this->_('My config field'), ], ... ]; This code displays the AsmSelect, but I have no idea how to add options there. Tried some staff like this: $config = [ [ 'name' => 'MyFieldName', 'type' => 'AsmSelect', 'label' => $this->_('My config field'), 'options' => [ 'name1' => 'value1', ], ], ... ]; , but couldn't get any result. I know that it's possible to define config inputfields right inside the .module file, but I'd like to separate the config from module itself (and the MyModule.config.php is a perfect way to do so). So dear Santa, do You have any idea on how to add some options to my inputfield? Thanks in advance )
  5. Hi fellas! And thanks for Processwire! I have an idea which, I suppose, might appear interesting to the PW community. I'd call it "template fields". Come on, we have it already! Any template may have fields, it's Processwire basics. Yes. And no! The fields attached to any template are used with the pages having this template, but not with the template itself. Feel perplexed? A short pseudocode example to explain what I'm trying to say. //one-of-my-templates.php ... foreach( $productPages as $productPage ){ $productImage = $productPage->image? : $productPage->template->image; //outputting some html etc. } ... Default field values (e.g. default images) are not a strong point of Processwire. Okay, we can use 3rd-party modules like @Macrura's Settings Factory (but oops, SF doesn't support image fields). Or we can create a dedicated "defaults" page with dedicated "defaults" template having all necessary fields... hmm, looks like a patch, yes? At last, we can give up and use some hardcoded image urls (yes, it's "patchy" again!). Using a kind of $page->template->image could be a much better solution. Let's imagine a second set of data fields bound to any template. The first one represents the fields used like $page->myfield. The second one could be used in the following way: $page->template->myfield or even $template->myfield. This approach may give us much more flexibility than PW already has, and I don't suppose it should be too complex to implement. Maybe it will be reasonable to make a module offering this new functionality. Think I possibly could do this... but would like to see the community reaction first. So what do You think friend? Is it worth doing or not? Thanks in advance for any opinion.
  6. Wow it's just incredible! @BitPoet You're the best ) It's so rare to see a new module being created as a response to a forum question! Love the Processwire community ) Thank you fellas!
  7. Hi friends! And thanks for Processwire ) Maybe I'm missing something, but it appears that PW doesn't have a dedicated selector for text length. Possible selector: $selectedUsers = $users->find("name.length<=5,sort=name.length"); Expected output: Bob Andy Maria ( Steven and Andrea will be skipped because that names are too long ) Of course it's possible to filter the find() results using some custom function, but having a native selector instead could be a better practice. So does that silver bullet really exist? If no, I think it could be useful to many happy PW developers )
  8. @da², sorry, forum says that I have no permission to see the content You've quoted ( Could You please copypaste it here?
  9. Hi friends! And thanks for ProcessWire! There's an inconvenience in ProcessWire file translation process which, I think, deserves a topic here. It's a common case to have same translatable phrases in different translatable files. Using a translation context (in fact, a separate file holding all that phrases) is also a common case, at least for me. Generally i call that context I18N_GLOBAL. So my typical translation may look like this: <?=__( 'Accept', I18N_GLOBAL )?> The problem is that ProcessWire translation interface is context-agnostic. If You have to translate multiple files containing the same 'Accept'-related piece of code, it will be always treated as not translated yet, even if I18N_GLOBAL file is already translated. Quite annoying, especially if You have lots of phrases to translate. So dear Santa, could You please make translation interface context-aware and to mark all the phrases (in all the files) which already have translation in my I18N_GLOBAL file as translated? Or maybe I missed something, and there's a possibility to tweak some settings and achieve this? Thanks in advance for any possible advice or idea )
  10. Hi friends! And thanks for Processwire! While supporting a 5-years-old Processwire project I found that there are both InnoDB and MyISAM tables there. Personally I think that InnoDB is better for Processwire. MyISAM tables came from some modules written years before. Since I like websites to be fast, I altered all MyISAM tables to InnoDB. At first glance, it was a good solution, website is running fast and smooth. Could there be caveats? Maybe I'm taking some implicit risks? I Would like to discuss this.
  11. @bernhard, thanks! Quite an elegant solution, works like a charm.
  12. Okay, thanks! Admin pages are handled in their normal way, have nothing specific to add here. As to the frontend, the form is ajax-submitted to an API endpoint written by myself.
  13. Hi friends! And thanks for Processwire! I have an interesting question. Couldn't find an answer myself. Let's suppose we have a hook of this kind: $wire->addHookAfter("Pages::saveReady", function($event) { $user = $event->arguments(0); //some manipulations with user data } This hook can be triggered both by frontend (there are some forms there allowing users to edit their profiles) and by backend (when superuser saves user page). I'd like this hook to have different behavior in these two cases. My first guess was like this: $wire->addHookAfter("Pages::saveReady", function($event) { $user = $event->arguments(0); $page = event->object; if( $page->template == 'admin' ): //some admin-specific manipulations with user data } No way! $page is always null, no matter how the hook was triggered. Any idea how to guess which page has triggered the hook? Thanks in advance for possible help 🙂
  14. Hi @AndreasWeinzierl! Got into same trouble. Fortunatelty, it can be fixed quite easily. Just uncomment //namespace ProcessWire; at the very beginning of the module. Have no guess why @kixe had commented it. Works fine after uncommenting, at least for me )
  15. Hi friends! And thanks for Processwire! I have an interesting question concerning selectors. Let's suppose we have an "inventory" template with "owner" repeater holding all users who owned this inventory. The last repeater item represents the current owner. Is there any possibility to select an inventory page by some data contained in its last owner repeater item? Some pseudocode to clarify what i want: //getting inventory recently owned by different users by currently owned by current user $myInventoryPage = $pages->get("template=inventory,owners(last).id={$user->id}"); Using owners.id is not an option here because the "owner" repeater may contain the current user in any position, not the last one. Thanks in advance for any idea!
  16. Hi friends! And thanks for Processwire! Maybe i'm missing something, but i have no idea how to select an (admin) page by the process it uses. It could look this: "template=admin,process=my_process_name" This could be a great help while using a perfect ProcessSettingsFactory module (many thanks to @Macrura!). That module allows to create admin settings pages, each holding a certain set of configurable data fields. Getting that fields is a piece of cake: $settings = $settingsFactory->getSettings('general'); //'general' is the name of admin page holding the settings $phone = $settings->phone; Works great when we need quite a limited number of settings. But when the things are getting bigger, it becomes quite reasonable to create a number of settings pages and to organize all the settings into a unified structure. Here's an example how it could be: //getting all settings pages $settingsPages = $pages->find("template=admin,process=ProcessSettingsFactory"); //creating the settings object $settings = (Object)[]; //putting all data from settings pages into $settings object foreach( $settingsPages as $settingsPage ){ $settingName = $settingsPage->name; //e.g. 'general' $settings->$settingName = $settingsFactory->getSettings($settingName); } //now we can use the $settings object echo "<a href=mailto:{$settings->general->email}>Mail us!</a>"; This approach definitely requires a process-specific selector. Guess that it could also be implemented at module level but having a specific selector for process could be useful in a large number of tasks. Will appreciate any idea )
  17. @Jan Romero, You're super cool! That extra slash in form action value resolves the problem. Thanks a lot!
  18. Hi friends! And thanks for Processwire! I've got a strange PW behavior which i cannot explain. Maybe i'm missing something. I have a form with method=post and action=action_page (different from page where the form resides). I'm trying to use post vars in the action_page's template. Both $_POST and $input->post() are empty. Deeper analysis shows that PW performs a http 301 redirect to action_page after the form is submitted, so all post vars are no longer available. How can i prevent PW from doing so? Did some simple tests to find the reason, i'm 95% sure that the redirect is triggered by PW. Thanks in advance for any advice!
  19. Hi everybody! And thanks for Processwire! I like PW hooks and use them in almost all of my projects. But it appears i'm missing some functionality. Some pseudocode to explain my wishlist: //somewhere in site/ready.php addHookClass('Page(template=my_template)::my_data', function($event) { ... } //somewhere in site/templates/my_template.php var_dump($page->my_data); //should output a multilevel array or nested objects $page->my_data->set('some_var',$some_value); //doesn't write to database $page->my_data->save(); //$page->save('my_data') is not applicable here because my_data is not a regular PW data field In fact i'm trying to create a solution for manipulating per-user settings (how to display some data on some pages etc.) but this approach may appear to be useful in different cases. Any suggestions are welcome!
  20. Just to clarify the situation. It appears that i've run into Firefox memory issues. I have many Firefox tabs and windows opened at the same time, and sometimes it may lead to strange effects concerning sessions and cookies. So it's not a Processwire-related issue. Hope this will be useful for someone.
  21. Hi guys! And thanks for Processwire! I got a strange issue concerning user system behavior. Maybe it's a bug in Processwire, maybe i'm missing something. I'm developing a site having 2 different user templates: the native user template and member template. The alternative user template setup has been done according to official tutorial. What's working fine: "Regular" users can log in and log out as intended Member users also can log in and log out as intended using $session->forceLogin($memberUser) and $session->logout() "Regular" users (all having superuser permissions) can access admin pages and use them Member users have their own set of permissions, they cannot access admin pages What's buggy: Both $session->forceLogin($memberUser) and $session->logout() have no effect on "regular" user sessions. Logging in/logging out regular users have no effect on member user sessions. Member users can only access their own personal pages with member template, trying to access other member pages gives 404. The only project-specific thing which could potentially lead to this behavior is the empty password field for any member user. They always log in using $session->forceLogin() and credentials obtained from external API. Tried to assign a password for one of member users; that user could log in/log out using admin page but the above-described bugs were still the same for him. Have no idea how to fix this, will appreciate any help. Thanks in advance! P.S. I'm using Processwire 3.0.201 in both dev (Windows) and test (Linux) environments.
  22. Thanks @matjasp! It's exactly what i've missed.
  23. Hi friends! And thanks for Processwire! I've found a... hmm, not a bug but rather missing feature. Let's imagine we have a field of type Page Reference. Due to some reasons (e.g. for having possibility to create new pages directly from inputfield) we assigned a Parent page to Selectable pages settings of our inputfield. Later we decide that we n o longer need that Parent page setting. And - voila! - there's no possibility to unset it. In fact, this impossibility may lead to errors like "A page does not have necessary parent" which may appear while populating our inputfield programmatically. At the moment, the only way to fix this is to edit the database manually and to delete the parent settings from 'data' column. Hope this will be fixed in later versions of Processwire. Thanks again!
  24. @Pixrael, good question! I thought that PW database uses InnoDB by default but it was wrong. Did an InnoDB migration without changing any code, the concurrent tests are experiencing the same troubles as before with MyISAM, but now there will be more space for experiments. Thanks!
  25. Hi friends! Many thanks for the brilliant Processwire! I have an interesting question concerning concurrent requests. I'm working on a PW-driven API which should pass some tests required by my client, including a so-called concurrent request test. The test harness generates a certain number of unique http requests and "fires" them in almost no time (they're received by webserver with time difference of the order of milliseconds). However far from real life use cases, this test is absolutely required by my client. Experiencing such a high (however short) load, PW reveals some weaknesses mainly concerning database interaction. Almost all concurrent requests should update a PW-driven numeric data field (in fact a database table). Concurrent requests try to increment/decrement its value, and after that a final check of the field value is performed. In most cases the final check fails. In-depth study shows that PW may receive new requests before the current request is processed, and this may lead to wrong final value. I tried some possible solutions: Wrapping field-changing operations in a database transaction. No success. Using mysql table lock. In my case this also didn't give a versatile result. Writing a lock mechanism denying any operation with data field until the previous request(s) are ended. Not versatile enough again. Organizing request queue. Maybe the best possible solution, but didn't try it yet. So what are your ideas in this case? Any possible approach is welcome ?
×
×
  • Create New...