Jump to content

Where is $config->ajax coded?


clsource
 Share

Recommended Posts

Hello, 

since my post about RESTful Processwire

https://processwire.com/talk/topic/7159-rest-helper-for-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

/wire/core/WireInput.php

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

get post, put delete etc.

/wire/core/WireHttp.php

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

/wire/config.php

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

 
Link to comment
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);
		ini_set('default_charset','utf-8');

		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; 
		
		$this->setStatus(self::statusBoot);
	}

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
Link to comment
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
 Share

×
×
  • Create New...