Jump to content

TomPich

Members
  • Posts

    85
  • Joined

  • Last visited

  • Days Won

    3

TomPich last won the day on September 15

TomPich had the most liked content!

About TomPich

  • Birthday 02/26/1976

Contact Methods

  • Website URL
    https://www.situp-webcreation.com

Profile Information

  • Gender
    Male
  • Location
    Strasbourg

Recent Profile Visitors

721 profile views

TomPich's Achievements

Full Member

Full Member (4/6)

77

Reputation

  1. Yes... I tried Repository first, then I tested with another suffix (Repo), and it didn’t change anything (and I then commented it out...). The addnamespace does all the job. So I don’t get what this addSuffix does. My guess is that it allows better performance when there are a lot of classes, pointing out the sub-folder to look into. But then, so does the namespace ProcessWire\Repository; I can't figure it out...
  2. If I don’t use it, ProcessWire is apparently not able to import classes in the Repository Subfolder
  3. Hey guys, @da², @fliwire, thank you for your help. It pushed me in the right direction. I got my things done and wanted to share with whoever would find that useful. Here was my need: a specific folder to store some classes, usable easily across templates (ie "use Class" and not "include ...". These classes wouldn’t fit (IMO) into a DefaultPage class for separation of concerns matter. And I didn’t want to try to develop a module, seemed an overkill and time is running... I decided to store my custom classes files into some subfolders of the /site/classes folder. At first, I used a /site/src folder (and it worked), but as the classes folder already exists, I thought it made more sense to use this folder. This is my architecture ├── site/ │ ├── assets │ ├── classes/ │ │ ├── Repository/ │ │ │ ├── AbstractRepository.php │ │ │ └── ContactRepository.php │ │ ├── DefaultPage.php │ │ ├── HomePage.php │ │ └── Utils.php │ ├── modules │ └── templates └── wire For autoloading use PW autoloader, in put in init.php $classLoader = $wire->classLoader; $classLoader->addNamespace("ProcessWire", __DIR__ . '/classes'); Then the magic happens. My ContactRepository.php, for example : namespace ProcessWire\Repository; use ProcessWire\Utils; class ContactRepository extends AbstractRepository { // my stuff here... } and when I need it in a template file : namespace ProcessWire; use ProcessWire\Repository\ContactRepository; $contactRepo = new ContactRepository; $speakers = $contactRepo->getAllSpeakersAndModerators(); Remarque: In the init.php file, I tried with and without $classLoader->addSuffix("Repo", __DIR__ . '/classes/repositories'); // does not change anything $classLoader->addPrefix("Repo", __DIR__ . '/classes/repositories'); // does not change anything I can't really grasp in which situation this useful, and the doc is quite short... 😅 So with this file structure, I can really get a step further in logic handling and code maintenance. Hope someone will find this useful. Cheers
  4. Hi guys, I know this has been asked already a few times here, but I couldn’t find a working solution for me... Working on a quite big project and I feel it can get messy quite easily. I need to tidy my code a little but. So here is the situation: I have quite a lot of data handling to do in the front side of my website. This involves querying on an external DB and processing the data. I started to write some methods in a DefaultPage class and that works well, but this will end with a very big file with tens of methods not related to the same logic. What I would like, is to have a src/ folder in my site/ folder, with all the custom classes in relevant subfolders. I tried this: // in site/init.php $namespace = 'ProcessWire\\App'; $classLoader = $this->wire('classLoader'); if (!$classLoader->hasNamespace($namespace)) { $srcPath = 'src/'; // target folder is /site/src $classLoader->addNamespace($namespace, $srcPath); } Inside this site/src/ folder, there is a MyClass.php file, with the class MyClass namespace App; class MyClass { const hello = "hello"; } And in my template file: namespace ProcessWire; use App\MyClass; <?= MyClass::hello ?> But I can’t get class loaded... 😔 I tried variation with namespace and use, but it didn’t work... Any help please ? Thank you!
  5. It definitely is useful. 😊 Thanks @virtualgadjo
  6. Thank you so much @Robin S. Your answer is more than I expected... That’s what I love about you guys, in this forum. I don’t get only the answer I was asking for... I get detailed help that anticipates my need!😊
  7. Hey Robin, Thanks for your work. It looks like this module would fit my need for something – could you confirm please? I need to retrieve data from an external database (I’m okay with thay), something like an array of id => value. I’d like the select options to show the value, and then store the pair id / value in the field. Can I do that with this module?
  8. Thanks a lot @szabesz, that definitively enlightens me. I’ll give it a try when I come to this part. Again, thanks!
  9. Great. That works well. For whom it could be useful, this is the code of my DefaultPage class: class DefaultPage extends Page { public WireDatabasePDO $dblfa; public function __construct(Template $tpl = null) { parent::__construct($tpl); $this->dblfa = new WireDatabasePDO(/* credentials */); } public function getParticipants() { $request = "SELECT * FROM participants"; $query = $this->dblfa->query($request); $items = $query->fetchAll(\PDO::FETCH_ASSOC); $query->closeCursor(); return $items; } }
  10. Hello processwirers, My client has a quite specific need and I have no clue about how to handle it. Visitors can buy events ticket on this site, but they don't have a client account (that’s part of the spec). Once they bought their ticket, all data are stored in an external database. If they want to check their booking, they have to enter their e-mail in an input field. From there : Processwire send them a mail with a single use url When client go to this page (no password requirement, so url must be like a hash), Processwire retrieve from the external database all the info needed) and display it. The page is deleted after a while (let say 24h) to avoid excessive amount of pages (about 10.000 visitors are expected) I’m okay with fetching data in an external database. My problems are: how to associate the email address to the temporary page url? how to handle the "temporary" aspect of these pages? Any help/suggestions/clues will be greatly appreciated... 😅 Thanks
  11. Thanks! 😊 I’ll check if that solves my in the DefaultPage class.
  12. Hi there, I know there are several posts about this subject, but they provide the answer I’m looking for. I’m working on a website on which some data as to be read and/or stored in an external database (which is also accessed by another app). What’s the cleanest way to achieve that? My first idea was to exclusively use DefaultPage class. Something like: class DefaultPage extends Page { private \PDO $dblfa; public function __construct(Template $tpl = null) { parent::__construct($tpl); global $config; $this->dblfa = new \PDO("mysql:host=" . $config->lfa_dbHost . "; dbname=" . $config->lfa_dbName . "; charset=utf8", $config->lfa_dbUser, $config->lfa_dbPass); } public function getParticipants() { $request = "SELECT * FROM participants"; $query = $this->dblfa->query($request); $items = $query->fetchAll(\PDO::FETCH_ASSOC); $query->closeCursor(); return $items; } } But this generates some subtle bugs : in front: $pages->get(...some ID...) returns null (only when the DefaultPage class defines $this->dblfa, otherwise it works fine). in admin: one of the page, with over 300 children, returns PagesLoader: SQLSTATE[08004] [1040] Trop de connexions [pageClass=ProcessWire\DefaultPage, template=un_inter] (un_inter is the child template) So I want for this solution: In site/config.php $config->dblfa = new \PDO("mysql:host=" . $config->lfa_dbHost . "; dbname=" . $config->lfa_dbName . "; charset=utf8", $config->lfa_dbUser, $config->lfa_dbPass); In site/classes/DefaultPage.php class DefaultPage extends Page { public function getParticipants() { global $config; $request = "SELECT * FROM participants"; $query = $config->dblfa->query($request); $items = $query->fetchAll(\PDO::FETCH_ASSOC); $query->closeCursor(); return $items; } } It works perfectly, but it doesn’t feel “clean” for me. I’d like to handle all the external database logic in the same file (ideally DefaultPage.php as I will need to implement some methods, so init.php would not be the best in my very limited knowledge). Both solutions actually fetch the data, no problem with that. Anyone to shed some lights about that? Thanks guys.
  13. Hello, I would create a template with the sidebar content fields (without PHP file associated, as it is not intended to be displayed as a page), and create a page (let’s call it sidebar-page for our discussion) with this template. Then, in your post template, just call the content of your sidebar-page, something like $sidebar = $pages->get({sidebar-page-id}. Then you can use any field of this page in your post. Hope my explanation is clear enough... 😊
  14. Hi @mel47, I would split the string with duplicate dates into an array, then use array_unique to get rid of them, then join the array into a string
  15. Welcome @floko, I don't really get your problem. What is the link url you’re supposed to get when using contact persons? What is the response code of this blank page ?
×
×
  • Create New...