-
Posts
349 -
Joined
-
Last visited
-
Days Won
4
Everything posted by da²
-
Hi @Alamut, You can do this with URL hook: https://processwire.com/blog/posts/pw-3.0.173/#telling-processwire-what-page-to-render Another solution is to create a template and a unique page "product-sheet" to display all your products. So the URL will always be the same except for the product ID.
-
The message I deleted was answering this (I think so), but I was proposing the exact same solution as this: So I don't get what is the problem with this solution? Then you juste have to edit the selector string of the status field, so that it searches only statuses that have the same "course parent" as the current course. Something like selector="template=status, course_parent.id=page.parent.id". I'm not sure about the selector, I didn't use PW since a few months.
- 13 replies
-
- hooks
- pagereference
-
(and 1 more)
Tagged with:
-
*nothing* Just wrote a proposal until I found you already did that. 😅
- 13 replies
-
- hooks
- pagereference
-
(and 1 more)
Tagged with:
-
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. 🙂
-
This is an example from PHP documentation. Just saying that I discovered right now that constants are now allowed in traits since 8.2. ^^
-
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.
-
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.
-
So what do you think about this book after some weeks?
-
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/" } },
-
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.
-
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