Jump to content

da²

Members
  • Posts

    346
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by da²

  1. Ho nice, I think this is more a book that you should read when you are already a OOP developer and want to go further in structuring your code. Starting the book without OOP knowledge is quite a bigger challenge. 🙂
  2. This is an example from PHP documentation. Just saying that I discovered right now that constants are now allowed in traits since 8.2. ^^
  3. Usually languages uses this convention for constants, caps and underscore to separate words : Inputfield::COLLAPSED_HIDDEN I add a doubt but yes, PHP 8.2 supports constants in traits. <?php trait ConstantsTrait { public const FLAG_MUTABLE = 1; final public const FLAG_IMMUTABLE = 5; } class ConstantsExample { use ConstantsTrait; } $example = new ConstantsExample; echo $example::FLAG_MUTABLE; // 1 ?> About the hyphen in variable name, I bet most languages would refuse it, because hyphen is an operator.
  4. I add to Git site and wire. On wire I have some Git patches that I may apply again after updating to a new version, and each wire version may solve or add bugs, so I add it to version control. So .gitignore files exclude vendor directory and : I need some files in assets, so I exclude everything that is not needed and keep the rest. I also add the database.sql to Git, a clean version ready to be deployed on a new site. Everytime I do changes in admin I export the DB.
  5. So what do you think about this book after some weeks?
  6. To be honest I'm not an expert with composer, I did some research to configure properly PHP and found this way. It's working locally, working on production server, PhpStorm is not complying and generates the corresponding namespaces when I create a class... so I think this is good. 🙂
  7. Hello, Yes this is where I manage my namespaces and dependencies and it works fine. "autoload": { "files": [ "wire/core/ProcessWire.php" ], "psr-4": { "Rfro\\Rfrorga\\ProcessWire\\": "site/templates/", "ProcessWire\\": "site/classes/", "Rfro\\Rfrorga\\WebApi\\": "webApi/", "Rfro\\Rfrorga\\Cron\\": "cron/" } }, "require-dev": { "phpunit/phpunit": "9.5.28", "dbrekelmans/bdi": "^1.0" }, "autoload-dev": { "psr-4": { "Rfro\\Rfrorga\\ProcessWire\\": "site/src-tests/" } },
  8. Oh OK you are talking about permissions, I thought it was about the field "view" option (open, closed, open not editable...). 🙂
  9. This should change nothing for the API, field is not editable in admin pages but from the API you can edit it.
  10. Sometimes change tracking is not working properly and before to save the page we have to do this: $assetPage->trackChange('content_tags'); $assetPage->save();
  11. Did you try this kind of selector? There's no loop, you directly get the repeater item. The part with "owner" is not mandatory, it depends if you want to do the search on a specific page or not.
  12. Hi, maybe you can find help in this post:
  13. It's hard to say what is your problem because $user->givenname should work if the template "user" has a field givenname with a value. So the problem is not this code, it's elsewhere. You shouldn't need this, I didn't even know it exists and I added 27 fields on the "user" template in my current project. 🙂 Where does $user variable comes from in your code? Does the "user" template have all the properties? What var_dump($user) returns?
  14. If the developer have to manage segments, here is an update of the documentation example: <select onchange='window.location=$(this).val();'> <?php $urlSegments = $input->urlSegmentStr(); foreach($languages as $language) { $selected = ''; // if this page isn't viewable (active) for the language, skip it if(!$page->viewable($language)) continue; // if language is current user's language, make it selected if($user->language->id == $language->id) $selected = " selected=selected"; // determine the "local" URL for this language $url = $page->localUrl($language); // output the option tag echo "<option$selected value='$url$urlSegments'>$language->title</option>"; } ?> </select> Maybe this could be included in documentation, since it seems to me this should be the default behavior.
  15. If using an AI, why not simply ask it to fix spelling? Then you do the search on the corrected word, AND the user provided (in case AI did a mistake itself).
  16. Hello, I've recently updated a multi-language site to use the page names module. Reading the documentation there's nothing to do to make url segments to work with localized urls: Also documentation provides an example of a language selector: <select onchange='window.location=$(this).val();'> <?php foreach($languages as $language) { $selected = ''; // if this page isn't viewable (active) for the language, skip it if(!$page->viewable($language)) continue; // if language is current user's language, make it selected if($user->language->id == $language->id) $selected = " selected=selected"; // determine the "local" URL for this language $url = $page->localUrl($language); // output the option tag echo "<option$selected value='$url'>$language->title</option>"; } ?> </select> Problem: When I'm on a page mysite.com/fr/page-name/17175/, after switching language I go to mysite.com/fr/page-name/, the last url segment is lost and the page displays a 404 because it requires this segment. Is it the expected behavior? Is there something in the API I should use to make PW takes care of segments? Or do I have to manage the segments myself, using $input? 🤔
  17. Hmm, I don't need it on my side. Are you using the correct namespace? I added a directory Test in site/classes/, inside a class Foo with this namespace: <?php namespace ProcessWire\Test; class Foo{} And in a template.php I instanciate it: use ProcessWire\Test\Foo; $test = new Foo(); If you're using the same code, maybe it comes from my composer.json but I would be surprised. I updated the composer.json, but only to add my own namespaces. ** looking my composer.json and... Hoooooo yes I know why... 😁 ** "autoload": { "files": [ "wire/core/ProcessWire.php" ], "psr-4": { "Rfro\\Rfrorga\\ProcessWire\\": "site/templates/", "ProcessWire\\": "site/classes/", "Rfro\\Rfrorga\\WebApi\\": "webApi/", "Rfro\\Rfrorga\\Cron\\": "cron/" } }, I don't remember why but I added a namespace for site/classes. 🤔 Probably for the same problem as you... Could it be a cleaner way to solve your issue?
  18. I don't understand why this is necessary: $classLoader->addNamespace("ProcessWire", __DIR__ . '/classes'); I don't need this to get auto-load of custom classes.
  19. Hi, I tried the same a while ago and it appears PW is forcing custom classes to be in site/classes directory. The code seems to be in ProcessWire.php: $cfg['paths']->data('classes', $cfg['paths']->site . "classes/"); Maybe you can overwrite this in your own config.php? Not sure if this is a good idea. ^^ But these classes dependencies can be in any package in site/templates/YourPackage (parent/abstract classes, Traits...). On my side the code I put in page classes is only related to the model part (getting/setting data), I don't use them to do rendering or controller stuff. The main part of the code is in my packages in site/templates. So I'm not really annoyed by the fact they have to be in the same directory, but I admit it would be better to put them in their related package.
  20. Hi, check this: https://github.com/processwire/processwire-issues/issues/1774#issuecomment-1618267798 EDIT: I missed that, my answer considers that you are using PW language management.
  21. Maybe first check the global parameter : https://stackoverflow.com/a/21411933 Especially if you didn't create virtual hosts for each site.
  22. Hello, When reading this, I think it's related with .htaccess not processed, I might be wrong but that's the first thing I would look at. How do you configure the VirtualHosts of each site? Is there a directive AllowOverride? https://stackoverflow.com/questions/35251032/how-to-create-virtual-hosts-in-mamp
  23. Another idea close to the @bernhard one: lock the quantity field so it's not editable add a field "quantity to add" in saveReady hook, load page without cache to get real quantity and update it with "quantity to add" field.
  24. @flydev I've played with ZipArchive recently and had some issues when unzipping on Linux (but not on Windows with 7zip), because I forgot to exit() PHP script after outputting headers and zip file. So I know a zip file can be opened on some software and not on other if it contains a problem. For the @MarkE issue, I'm wondering if it could come from the 2 lines in Duplicator.module where you update the zip archive without providing a flag in $zip->open()? Line 566 : if ($zip->open($pwbackup['zipfile']) !== true) { Line 939 : if ($zip->open($zipfile) !== true) { I don't really believe this solution, but I've seen a lot of posts like that when searching for my own issue: https://stackoverflow.com/a/17975009
  25. Hi, I don't think you'll see differences between MySQL and MariaDB, and LightSpeed supports .htaccess so this is a good news. To test it, it depends on your habits, I'm not a MacOS user, why not installing a Debian distribution in a virtual machine? MariaDB is the default database, and LightSpeed has a sh script to install it. On Windows I would use Linux WSL. There's also OpenLightSpeed in official Debian packages, but I don't know the differences: https://www.howtoforge.com/how-to-install-lomp-stack-openlitespeed-mariadb-and-php-on-debian-11/
×
×
  • Create New...