Jump to content

TomPich

Members
  • Posts

    85
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by TomPich

  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 ?
  16. Hello @dan222 and welcome to this forum! To push a site online : go to your db manager on laragon and export your db as a sql file then, from your hosting control panel, create a db (or empty it if it already exists) and import your local db with FTP, copy your local files in your hosting folder for your site (don’t forget to change the database config in /site/config.php file) And that’s all. ? Now, you can be a bit more efficient by using an "if" statement for your database config, so that you don’t have to worry about changing them when you push your site online (see below) using ssh/rsync to synchronize your local and distant files I’m sure you can optimize database export/import too, I didn’t dig in yet... // db config online / on localhost if ( $_SERVER["HTTP_HOST"] === "my-online-url.com") { $config->dbHost = '...'; $config->dbName = '...'; $config->dbUser = '...'; $config->dbPass = '...'; } else { $config->dbHost = 'localhost'; $config->dbName = 'my-local-dbname'; $config->dbUser = 'root'; $config->dbPass = ''; } $config->dbPort = '3306'; I generally need 4 minutes to pull or push a website after or before working on it, if it involves db update. If it’s only changes in files, it’s done in 10-15 seconds.
  17. Hey @JCVinso, Your admin looks perfectly normal. You see all the pages of the website. From there, you can edit them (hover → edit button). Can you explain what do you want to achieve? What can of options do you expect to see in the admin?
  18. I also like to give my clients some links to articles about PW : Article on PW by IONOS Article on PW by London web agency Net Dreams Article on PW by British web agency Presto ProcessWire vs WordPress on cmscritic.com And nice websites built with PW : Australian Antartic Program Nienburg Mittelweser Peggy Guggenheim Collection Herzzentrum Bonn Austrian Bankers Association BMW Dealersites University of Florida / IFAS Assessment and hundreds of others on this page.
  19. Thanks @Neue Rituale, I’ll try that right away.
  20. Will definitely try this module ?
  21. Hi @d'Hinnisdaël, Just wanted to say (again) how awesomissimo is your module. It’s a real asset in the scale when trying to convince a client to switch from WP to PW. They often fear to be lost with a new admin interface. But thanks to Dashboard, I can demonstrate how easier it is. ?
  22. Hi guys, I was wondering if the action buttons for each page in page tree could be : All always visible (always immediately see Hide, Unpublish, Trash... when hovering over page link) Hidden selectively even if the action is possible (like always hide the Lock button) About the Add new button, I noticed something that is a bit weird : Let say I have a P template that may have children based on template C1 and C2. C1 and C2 can only have P as parent. So these conditions are enough to get a link with the "Add new" button, and it works perfectly. Now, let’s imagine I have two roles defined : chief-editor and contributor. Chief-editor can create pages based on C1 and C2 and can see both "Add new" links. Contributor may only create pages based on C2. They should only see "Add new C2" link. But they actually can see both links, and when they try to create a C1 page, they get an error saying "ProcessWire: ProcessPageAdd: Template page-post is not allowed here (/p-page-url/)". Which is absolutely right, as they are not allowed to create C1 pages. But it’s confusing for the user. Did I misconfigure something here? Or is it something that should be fixed?
  23. Very old indeed, but still useful... and still working ? Who said plugins needed to be updated every week ? Oups... wrong forum... ? I’ll open an issue on Github.
  24. Hey there, I had the same need (hide page tree for certain roles). Used https://processwire.com/modules/admin-restrict-page-tree/ module. Worked like a charm, except that I had the same problem than @DL7, i.e. the bread crumbs provide links to the page tree. The page tree is not displayed, but a page saying "Login" with an "Edit profile" button is shown. That may be a bit confusing for users. So I add a few lines to the module, in order to optionnaly skip the bredcrumbs rendering (a hook, and a checkbox to choose whether you want to display the page tree for restricted users). It works well with AdminThemeUikit (I didn’t test it with the default admin theme). I thought this might be useful to other users. @Wanze, @netcarver if you want to have a look at it, maybe for module update? It would be my first contribution to a PW module... ?
  25. Sounds great. It would cover my needs. Do you treat these users as PW users? Or did you make a kind of "front user" profile using a custom template? In the last case, i wouldn’t be so sure on how to handle security matters and sessions.
×
×
  • Create New...