Jump to content

Class 'Context' not found in


AlainGau

Recommended Posts

I have the below PHP file in my module folder that is call with an ajax post (jquery from UI).  And I am getting the following error: Class 'Context' not found in ... when I trigger the POST

 

I am running PS 1.6, how can I access the context from this file??

<?php
define('_EXTERNAL_SCRIPT_', 'true');

include(dirname(__FILE__).'../../config/config.inc.php');
include(dirname(__FILE__).'../../init.php');
include(dirname(__FILE__).'../../classes/Cookie.php');

Context::getContext()->cookie->__set('myData', $_POST['data1']);


?>

 

Link to comment
Share on other sites

thanks but it was my path accesses that were wrong: 

include(dirname(__FILE__).'../../config/config.inc.php');
include(dirname(__FILE__).'../../init.php');
include(dirname(__FILE__).'../../classes/Cookie.php');

should be as below to work, since I am in the modules/mymodule folders..

include('../../config/config.inc.php');
include('../../init.php');
include('../../classes/Cookie.php');
 

 

 

 

Link to comment
Share on other sites

so, with correct paths you can use Contentx object with static functions?

 

The way it is defined Context::getContext - you can use it with static functions. If the object is not defined yet, it will create one:

	/**
	 * Get a singleton context
	 *
	 * @return Context
	 */
	public static function getContext()
	{
		if (!isset(self::$instance))
			self::$instance = new Context();
		return self::$instance;
	}

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
×
×
  • Create New...