Jump to content

Recommended Posts

Posted

Is there any way (module?) to execute basic api commands from inside the PW admin?

For example, say I wanted to do a (one-off) something like set a field value to "this is a default value" for all pages with a specified template; What I do presently is temporarily add some code to a template file and then browse to a page which uses that template; Then once the commands are run I delete the code from the template.....

$p = $pages->get("template=test");
$p->of(false);
$p->set( 'fieldx', 'this is a default value' );
$p->save();

The PW API is so good, so coupling it with such a cumbersome method to achieve a simple pages update seems dodgy. Am I missing something? I find myself doing this type of thing quite often, so how does a real PW geek (as opposed to a wannabe PW geek ;-)) achieve the above?

Posted

You can add anything you want in /site/templates/admin.php, which is the file that is first called when accessing the admin. Incidentally, this is actually also a place where you can add hooks that pertain only to the admin (though it is generally cleaner to do so in a module).

  • Like 2
Posted

I usually executed such scripts over the command line (bootstraping ProcessWire).

Maybe you could use Hanna Code if you'd like to write the code in the admin?

  • Like 2
Posted

one of the first pieces of wisdom i got from Soma was about making a template from where you can execute api stuff;

this is needed on every site, because you'll always need some "api playground" where you can test things and run things to change, add, fix content..

my setup is to have a template called tools, and then a subfolder in the templates where i store all of the scripts that i will run on that tools template, then i just include the one i'm currently using into it and go from there.

Sometimes when developing a new part of a live site, i can just clone a template, run it under tools and set the virtual page to anything in the site (example, $page = $pages->get(1012); )

but mostly i'm doing complex imports from other systems like joomla, or from spreadsheets with a lot of custom stuff and dependant/related pages, formatting etc..

  • Like 8
Posted

OK, so there is not a "console" or the like for executing API calls, just thought perhaps there was a module or something which covered this, seems to be for nearly everything else :-)

Several solutions, all  better than I'm currently doing, thanks guys.

@Macrura, I think I'll set this up as you describe and see how it goes. If it's got the Soma seal of approval.... say no more.

  • 1 year later...
Posted

I know this is old, but in case new users stumble across this, the Console Panel in TracyDebugger is what you are looking for :)

http://processwire.com/blog/posts/introducing-tracy-debugger/#console-panel

screen_shot_2016-08-20_at_6_54_13_am.png

 

The other option for @muzzer's specific request of:

$p = $pages->get("template=test");
$p->of(false);
$p->set( 'fieldx', 'this is a default value' );
$p->save();

is to check out the "Field Set Or Search And Replace" action in the new AdminActions module which provides a GUI for setting the value of a field on many pages at once:

Screen Shot 2016-12-03 at 8.18.22 AM.png

  • Like 6

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...