Jump to content
buster808

Using Public Function

Recommended Posts

Hi,

I am having problems using the public function in a module.
It will only ever show public function ___execute and nothing after
Example below - I just cant work out why this is happening.

Thanks

// This shows
public function ___execute() {
 
$table = $this->modules->get('MarkupAdminDataTable');
$table->headerRow(['A', 'B', 'C']);
$table->row([1, 2, 3]);
$table->row([4, 5, 6]);
return $table->render();
}
 
// Then this doesnt show
public function ___executeTable() {
 
$table = $this->modules->get('MarkupAdminDataTable');
$table->headerRow(['A', 'B', 'C']);
$table->row([7, 1, 3]);
$table->row([2, 9, 7]);
return $table->render();
}

 

Share this post


Link to post
Share on other sites

Hey @buster808,

First you should make sure that your module class extends Process, and double check the URL you're trying to open (should probably be something like /processwire/your-module/table/).

I can't really see anything wrong with the code you've pasted here. If you could provide us with a proper test case (complete module code), it would be easier to see if there's something else missing. It's OK to strip any unnecessary parts away, but it should be a version of the module that a) is complete and thus should work, but b) doesn't work when you install it and try to use it 🙂

Share this post


Link to post
Share on other sites

Hey Teppo thanks for helping. The full code below ___execute shows but not executeTable

<?php namespace ProcessWire;
 
class CustomAdminPage extends Process {
 
public static function getModuleinfo() {
return [
'title' => 'Custom Admin Page Ketan',
'summary' => 'Minimalistic ProcessModule to show that nobody has to be afraid of building custom admin pages.',
'href' => 'https://processwire.com/talk/topic/17709-how-to-create-custom-admin-pages-aka-processmodules-yes-its-that-simple/',
'author' => 'Bernhard Baumrock, baumrock.com',
'version' => 1,
 
 
// page that you want created to execute this module
'page' => [
'name' => 'customadminketan', // your page will be online at /youradmin/setup/customadmin/
'title' => 'Tutorials',
],
];
}
 
public function ___execute() {
 
 
$form = $this->modules->get('InputfieldForm');
 
$fieldset = $this->modules->get('InputfieldFieldset');
$fieldset->label = 'Please come back and change this frequently';
//$fieldset->collapsed = Inputfield::collapsedYes;
 
//$fieldset->collapsed = Inputfield::collapsedYes;
$field = $this->modules->get('InputfieldMarkup');
$field->description = 'What service are you providing or promoting? Describe your service in a few sentences.';
$fieldset->add($field);
 
$field = $this->modules->get('InputfieldTextarea');
$field->columnWidth = 100;
$fieldset->add($field);
$form->add($fieldset);
 
$button = $this->modules->get('InputfieldSubmit');
$button->value = 'Save';
$button->icon = 'floppy-o';
$fieldset->add($button);
 
$form->add($fieldset);
 
return $form->render();
 
 
}
 
public function ___executeTable() {
 
$table = $this->modules->get('MarkupAdminDataTable');
$table->headerRow(['A', 'B', 'C']);
$table->row([1, 2, 3]);
$table->row([4, 5, 6]);
return $table->render();
}


 
}

Share this post


Link to post
Share on other sites

So, I saved your code at /site/modules/CustomAdminPage.module, installed the module, and opened /processwire/customadminketan/table/ on my site.. and it works just fine 🙂

Are you sure that if you install the code above as a module, it definitely doesn't work for you?

In that case it looks like we might need some additional info. First of all, which version of ProcessWire are you using, and what kind of a setup do you have (Apache or something else, Windows or Linux, are you developing locally or an a server, etc.)

Does everything else in the admin seem to work as expected?

  • Like 3

Share this post


Link to post
Share on other sites

This is really odd I just tested on another server and still the same.

The form shows but the table code doesn't.

 

Share this post


Link to post
Share on other sites

My apologies Teppo

Im new to programming  /processwire/customadminketan/table/  this works fine.

I wanted everything one page

  • Like 1

Share this post


Link to post
Share on other sites
43 minutes ago, buster808 said:

My apologies Teppo

Im new to programming  /processwire/customadminketan/table/  this works fine.

I wanted everything one page

Glad to hear that it's working 🙂

Process modules make execute*() methods available as individual URLs. If you want everything on one page, you can either put it all within the default execute() method, OR you can split your code into multiple methods and use them within the execute() method to render the final output (just don't name them with the execute-prefix, if you don't want them to be accessible in their own URLs.)

It's a bit complicated so perhaps not the best example for a beginner, but if you take a look at the ProcessChangelog module execute() method, you'll see a number of render-prefixed method calls. That's not an "official Process module thing", but rather my own convention – it's simply one approach to split otherwise unbearably long execute method into smaller, more manageable pieces 🙂

  • Like 2

Share this post


Link to post
Share on other sites

Hi Teppo thanks for this.

Just a quick one If I wanted newest submitted data to show in the fields on the form code above.

Would I have to post to database

Or can Forms API take care of this

 

Share this post


Link to post
Share on other sites

You'd definitely have to store the data somewhere. Forms API itself provides the form only, it doesn't save anything yet. Depending on your needs you have a number of options:

  1. Saving the data as config for your module. ProcessWire allows you to save config data for any given module with $modules->saveConfig(), and then retrieve it with $modules->getConfig(). This is a really simple approach, and likely what you'd want here.
  2. If you're using the latest development version of ProcessWire, there's now a brand new $page->meta() method that you can use to store any data to a specific page. In my opinion would be a great use case for that method, but again: it's only available for the very latest development version of ProcessWire (3.0.133).
  3. Saving your data in a custom database table (using $database API variable). This requires you (among other things) to create a custom database table, and if possible, I'd suggest avoiding it – usually it's better to use the API to store data as ProcessWire values. That being said, if you look at the ProcessChangelogHooks install() method, you can see an example of how to create a custom database table automatically when a module is installed.

There are other ways as well, but these are the ones I think fit your needs best 🙂

--

Just for the record, I'm moving this thread to the "Module/Plugin Development" section of the forum. The "Modules/Plugins" section is intended for dedicated support threads for existing (published) modules only, and any development-related questions should be posted to the development subforum instead.

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi Teppo

Truth is I really don't know where to start using the config and page meta method. (Need to learn how to use PW API but find it difficult)
I just need the form to act like an edit page so data stays in fields on update.

An example with one field working would be perfect.

I tried finding contact details for you but your website is offline as more than happy to pay you for this as need a few other bitts too.

Thanks

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...