Jump to content
clsource

Where is $config->ajax coded?

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

 

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);
		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

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.

  • Similar Content

    • 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
    • By EyeDentify
      I as have been a bit confused for some time about how the "Markup Regions" functionality in Processwire worked.
      But i have know read a bit more and think that i am getting to grips with it. And Markup Regions is going to be huge.

      To aid me in understanding Markup Regions better i started to read the Source code for the new "Regular" theme in conjunction with the Blog about the markup regions.
      It helped me a great deal to understand the basics and more fine details of it.

      A tip is to open both links and use the Source code of the "Regular" theme while reading the blog post.
       
      The Source code:
      https://github.com/processwire/processwire/blob/dev/site-regular/templates/_main.php
      The Blog post:
      https://processwire.com/blog/posts/processwire-3.0.62-and-more-on-markup-regions/
       
      I hope this could help others starting out with markup regions.
      Just take it slow and read it a couple a times and soon you will see the greatness of markup regions.

      /EyeDentify 
×
×
  • Create New...