-
Posts
341 -
Joined
-
Last visited
-
Days Won
3
da² last won the day on December 7 2023
da² had the most liked content!
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
da²'s Achievements
Sr. Member (5/6)
230
Reputation
-
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. 🙂
-
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/" } },
-
da² started following Custom class autoloading in templates , Using Composer , Adding multiple pages to page reference field within a foreach php and 3 others
-
Adding multiple pages to page reference field within a foreach php
da² replied to Liam88's topic in Getting Started
Oh OK you are talking about permissions, I thought it was about the field "view" option (open, closed, open not editable...). 🙂 -
Adding multiple pages to page reference field within a foreach php
da² replied to Liam88's topic in Getting Started
This should change nothing for the API, field is not editable in admin pages but from the API you can edit it. -
Adding multiple pages to page reference field within a foreach php
da² replied to Liam88's topic in Getting Started
Sometimes change tracking is not working properly and before to save the page we have to do this: $assetPage->trackChange('content_tags'); $assetPage->save(); -
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.
-
Hi, maybe you can find help in this post:
-
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?
-
Language selector: URL segments are lost when switching language
da² replied to da²'s topic in Multi-Language Support
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.- 1 reply
-
- 1
-
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).
-
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? 🤔
-
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?
-
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.
-
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.