pwFoo

Members
  • Content Count

    648
  • Joined

  • Last visited

Community Reputation

283 Excellent

About pwFoo

  • Rank
    Hero Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

6,636 profile views
  1. With FormData added to the fetch call $input / $_POST is populated! So with fetch it can be fixed at client side.
  2. Yes, but I can't use the PW $input, right? But found a solution with FormData and without (!) Content-Type Header
  3. Works fine with FormData object and without set Content-Type Header... var body = new FormData(); body.append("name", "Bob"); body.append("age", 27); fetch("http://127.0.0.1/fetch.php", { method: "post", body: body }).then(function(response) { console.log(response); return response.JSON(); }).then(function(result) { console.log(result); }); <?php $res = $_POST["name"]; print_r($res); die();
  4. Would be nice to have fetch() get / post handled by $input in PW. @marcus Which library do you use?
  5. pwFoo

    Hi @Robin S thank you very much! It was a little bit strange to debug because I needed some module un-/install and module list refreshs until it works, but the problem should be solved by change "$this->page->template" (was http404 inside of autoload modules init()) to "$this->templates->get('MyTemplate')" Add template settings from your example module! Looks like that was important. $t->compile = 0; // even though module and template not compiled by FileCompiler?! $t->noPrependTemplateFile = true; // important?? I don't use appended / prepended files $t->noAppendTemplateFile = true; // important?? I don't use appended / prepended files If compile = 0 was needed it's strange, because template / module not compiled. I checked it in /site/assets/cache/FileCompiler and logs...
  6. pwFoo

    Hi @Robin S, autoload module and init() method doesn't work. I disabled FileCompiler, but still not works. Because it's redirected to http404 before the existing template is set inside of the module. public function init() { $this->log->message("ServiceWorkerJS module autoload"); $template = $this->page->template; $this->log->message("TEMPLATE CURRENT: {$template}"); $file = $this->config->paths->siteModules . $this . '/templates/ServiceWorker.php'; $this->log->message("NEW RUNTIME FILE: {$file}"); $template->filename = $file; $this->log->message("CHECK TEMPLATE RUNTIME FILE: " . $template->filename); //$this->log->message("CHECK PAGE URL: " . $this->page->url()); // DISABLED BECAUSE IT FAILS WITH AUTOLOAD! } The log shows the template change runtime works fine, but it's to late to get the correct and expected page. URL is changed to http404. 2018-06-30 09:23:45 admin http://localhost/pw/serviceworker.js ServiceWorkerJS module autoload 2018-06-30 09:23:45 admin http://localhost/pw/serviceworker.js TEMPLATE CURRENT: 2018-06-30 09:23:45 admin http://localhost/pw/serviceworker.js NEW RUNTIME FILE: C:/xampp/htdocs/pw/site/modules/ServiceWorkerJS/templates/ServiceWorker.php 2018-06-30 09:23:45 admin http://localhost/pw/serviceworker.js CHECK TEMPLATE RUNTIME FILE: C:/xampp/htdocs/pw/site/modules/ServiceWorkerJS/templates/ServiceWorker.php 2018-06-30 09:23:47 admin http://localhost/pw/serviceworker.js ServiceWorkerJS module autoload 2018-06-30 09:23:47 admin http://localhost/pw/serviceworker.js TEMPLATE CURRENT: 2018-06-30 09:23:47 admin http://localhost/pw/serviceworker.js NEW RUNTIME FILE: C:/xampp/htdocs/pw/site/modules/ServiceWorkerJS/templates/ServiceWorker.php 2018-06-30 09:23:47 admin http://localhost/pw/serviceworker.js CHECK TEMPLATE RUNTIME FILE: C:/xampp/htdocs/pw/site/modules/ServiceWorkerJS/templates/ServiceWorker.php Autoload module is loaded twice during one page (re-)load, but page is redirected before the autoload module changes the template. FileCompiler is off (namespace in files, site/assets/cache/FileCompiler/site/modules/* is empty). Correct page should be instead of "serviceworker.js" instead of "http404". So how to prevent redirect to http404 with my autoload module? Where change the template to be early enough to prevent the redirect to http404? Example module need to deliver a serviceworker file to the browser from the root directory. Autoloaded with condition of template works fine. So initial the template is set, module is autoloaded, but page is redirected to http404. 'autoload' => 'template=ServiceWorker', There was a module->get() inside of basic-page. Conditional autoload based on template doesn't work. So I changed it to 'autoload' => true,
  7. pwFoo

    Thanks @Robin S, I'll try it with autoload module and disabled FileCompiler.
  8. pwFoo

    Hi @Robin S, I know there are workarounds with additional code in init.php or a hook. But I try to save and use the template inside of the modules directory to avoid workarounds outside of the module directory (autoload module with hook, additional code in init.php, copy modules template to site/templates). A nice solution would be to set the needed template file in modules install() method and save the custom template path to the page / template.
  9. Good to know that "$page->process = $this" works to, but the process page could be configured by module info in later PW versions (topic is very old, I know...) Will a custom un-/install() method in process module overwrite the "default" methods (create page, set process field to module, ...) or will it extend the default process module un-/install? The page to create is set in module info as shown in the ProcessHello example // page that you want created to execute this module 'page' => array( 'name' => 'helloworld', 'parent' => 'setup', 'title' => 'Hello World' ), Anything to do if I try to extend / modify the default un-/install()? Should I hook after module install method and should that work? $this->addHookAfter('install', function (HookEvent $event) { // custom code }); And what do that line in example mean in example module install() / uninstall()? parent::___uninstall(); // always remember to call parent method Would be nice to know the default process module un-/install() methods or is it just a installPage() / uninstallPage() call?
  10. pwFoo

    Same with subscribed content. How to save content subscriptions with PW?
  11. I have client side code which create a notification api subscription and send it to the server (PW, process module). Now I think about how to save the subscription? { endpoint: "https://fcm.googleapis.com/fcm/send/<DEVICE_ID>", key: <KEY>, token: <AUTH_TOKEN>, expirationTime: null } URL and DEVICE_ID is different dependent on browser (android, chrome, firefox, edge). How and where (in the page tree) should I save multiple user subscriptions? If a unsubscribe is executed the subscription have to be removed from the database / user. So I need a identifier to delete the subscription.
  12. Searched for a PW / PHP issue and missed the needed Content-Type to get $_POST populated
  13. It's fetch() related... fetch(subscribeUrl, { method: 'post', credentials: 'same-origin', headers: { 'Content-type': 'application/json' }, body: JSON.stringify({ subscription: subscription }) }) Change content type... fetch(subscribeUrl, { method: 'post', credentials: 'same-origin', //headers: { 'Content-type': 'application/json' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded'}, body: JSON.stringify({ subscription: subscription }) }) https://stackoverflow.com/questions/36669911/post-not-retrieving-data-from-javascripts-fetch
  14. I try to get POST data inside of my process module. Post request is sent by ajax with payload. But $this->input->post() or $_POST is empty here? public function executeSubscribe() { // get subscription from client and save to user / db //$array = array("me" => 'you'); // works fine! Can output with console.log at client side //$array = $this->input->post('subscription'); // empty //$array = $this->input->post(); // empty //$array = (array) $this->input->post(); // empty //$array = $_POST; // empty $array = (array) $_POST; // empty $this->render($array); } protected function render($out) { header('Content-Type: application/json'); echo json_encode($out); exit(); } I tried the post url with and without slash (I know the topics about ajax, post and trailing slash), but POST data is empty every time. Is it process module related? GET works fine in "execute()" method.
  15. pwFoo

    Thanks @Robin S, I decided to use php copy / unlink to un-/install the needed template file as simplest solution.