Jump to content

Where is $config->ajax coded?

Recommended Posts


since my post about RESTful Processwire


was quite popular (thanks for showing it in the newsletter by the way :D )

I'm planning to include some of the helper code inside the PW core

and then make a pull request in the hopes that merges with the current dev branch.

So far I have identified 3 files that I should modify


So I can add a "params" method in order you can have any params for any request method

get post, put delete etc.


So I can add method to send put delete patch requests, etc. and get JSON output


So I can add more fieldContentTypes and Header types for the response.

In the same file however, you got this

 * ajax: This is automatically set to TRUE when the request is an AJAX request.
$config->ajax = false;

Where I can find the code to set this?

So I can add

$config->post = false;

$config->get = false;

$config->put = false;

$config->delete = false;

And set them when a page is requested when a verb is used to call an endpoint.

Thanks! :D


Share this post

Link to post
Share on other sites

I believe this is set in /wire/core/ProcessWire.php on line 80 (at least on latest dev branch)

	 * Populate ProcessWire's configuration with runtime and optional variables
	 * $param Config $config
	protected function config(Config $config) {

		$this->wire('config', $config, true); 

		ini_set("date.timezone", $config->timezone);

		if(!$config->templateExtension) $config->templateExtension = 'php';
		if(!$config->httpHost) $config->httpHost = $this->getHttpHost($config); 

		$config->https = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443);
		$config->ajax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
		$config->cli = (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || ($_SERVER['argc'] > 0 && is_numeric($_SERVER['argc']))));
		$config->version = self::versionMajor . "." . self::versionMinor . "." . self::versionRevision; 

Not sure if this would also be the place to add what you are planning, that is a bit beyond me.

Using Sublime and i'm guessing most other editors you can very easily do a 'Find in Files...' for 'config->ajax' to see where it is used in the whole codebase. But it is defined in ProcessWire.php

  • Like 1

Share this post

Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By clsource
      Hello, I finished this toy project. A simple API to show data for Chilean Birds.
      Used to flex my PW and React muscles, since a lot of time has passed since making something with those techs.

      Code: https://github.com/NinjasCL/chileanbirds-api
      Frontend (React): https://aves.ninjas.cl
      Backend (PW): https://aves.ninjas.cl/api
      Hope you like it 🙂

    • By pwFoo
      Hi, I try to convert a rest api client to WireHttp and seaching for the option?
      verify=false // curl --insecure, self signed certificates
      Haven't found such a option in api documentation or source code (quick search...).
      Are self signed certificates supported by WireHttp?
    • By louisstephens
      I am wondering, how do you pass a variable into wire('page')->get() inside a function? I have been looking through the forums, but unfortunately I have not found the answer yet.
      My current set up is:
      function generateNewPages($parentPageName) { $p = new Page(); $p->template = "parent"; $p->parent = wire('pages')->get('/home/'); $p->name = $parentPageName; $p->title = $parentPageName; $p->of(false); $p->save(); $p2 = new Page(); $p2->template = "child"; $p2->parent = wire('pages')->get('$parentPageName'); $p2->name = "child"; $p2->title = "Child Page"; $p2->of(false); $p2->save(); } When I try to run it by passing in a title like generateNewPages('Demo');, "Demo" is created, but when it gets to the child page I get:
      Unknown Selector operator: '$' -- was your selector value properly escaped?
      Is there a way to pass the $parentPageName to "wire('pages')->get('$parentPageName')" ?
    • By thomasaull
      I recently started to build Vue SPAs with ProcessWire as the backend, connected with a REST API. Thanks to code and the help of @LostKobrakai (How to use FastRoute with ProcessWire) and @clsource (REST-Helper) I got it up and running pretty quickly and now have put all of it in a site profile for others to use. It includes the REST API with routing for different endpoints, JWT Auth and a simple Vue SPA which shows the process of logging in a user (nevertheless, you don't have to use the Vue part, the API will work on it's own).
      Check it out here: https://github.com/thomasaull/RestApiProfile
      I'm pretty sure, it's not the perfect or most sophisticsted solution, but it gets the job done for me…
      Feedback or Improvements are very welcome
      Update: This site profile is a module now: https://github.com/thomasaull/RestApi
    • By Pixrael
      I have a technical question that maybe you can guide me to a solution/idea.
      I know an online tool that publishes product information and updates prices/inventories regularly from marketplaces such as Amazon, Ebay, etc. to a Wordpress website ... can get the orders information, auto-order it and send back the tracking numbers. All this is done through the Woocommerce API. They don't have an API or CSV option to access this features..
      Is it possible to create fake REST endpoints (a clone of WooCommerce) on my site to accept requests from that external website and process this data my way inside PW? The requests to a REST endpoint are POST like in regular forms submits?
      Sorry I don't have to much technical background about this
      https://woocommerce.github.io/woocommerce-rest-api-docs/?php#create-a-product https://woocommerce.github.io/woocommerce-rest-api-docs/?php#update-a-product https://woocommerce.github.io/woocommerce-rest-api-docs/?php#retrieve-an-order
  • Create New...