Revo 2.1.0 rc4
I have a php file that is outside the manager and I need it to be able to access a user.
I’m using javascript to load the php file, so I’m not sure how to load/get to $modx in the php.
<script>
var url = '/my/file.php';
loadXMLDoc(url);
</script>
I found this:
<?php
$modx_core_path= '/home/USERNAME/public_html/core/';
define('MODX_CORE_PATH', $modx_core_path);
define('MODX_CONFIG_KEY', 'config');
require_once MODX_CORE_PATH .'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('mgr');
?>
But it doesn’t seem to do anything, when I try:
<?php
$user = $modx->getObject('modUserProfile', $userID);
$user->set('fullname', $name);
$user->save();
// or even this
$user = $modx->getObject('modUser', $userID);
$user->set('password', $pass);
$user->save();
?>
(the php is in one file)
You may or may not want to use the code I write. It's probably all against the syntax rules of php and MODx.
Carpet Cleaning
Can you not just put the PHP into a snippet and call that instead of the external file ?
Thanks, I got it working. I think it was may have been correct before, but I have a plugin that processes when a user is saved and that may have been causing the code not to work.
@lucas
I did learn some things from the page you gave me to the docs.
@paulp
How would I call a snippet using javascript? Put the snippet on a page of it’s own?
What the page does, instead of reloading everytime, it calls the php page to save the information when the user hits submit.
You may or may not want to use the code I write. It's probably all against the syntax rules of php and MODx.
Carpet Cleaning
Great, thanks for the help Lucas.
I'm running a shopping cart called Jcart, it doesn't runn very well as a snippet, despite my best try. How would I build this is as a plugin?