Is there some reason you don't want to use the Login package? It's very flexible and powerful.
MODx starts its own session, and by default uses database storage rather than file storage. If you need to access the MODx session, then you need to know the name of the MODx session, and have your script set the session_name and the other session initialization functions before starting the session.
-
- 5 Posts
I'm currently using the Login package and it's working fine but I need to customize certain parts of it and don't understand package script enough to change it. I was hoping to just use php instead so I can make any adjustments needed.
I need new registered accounts to send a confirmation e-mail to their e-mail, which Login already does perfectly. But I also need it to send a confirmation e-mail to the admins so they can also approve the new account since the membership is not open to the general public.
I'm trying to set it up the way you're describing. I'm using the following code:
<?php
define('MODX_CORE_PATH', '/pathtomodxcore/' );
require_once ( MODX_CORE_PATH.'model/modx/modx.class.php' );
// Create an instance of the MODx core
$modx = new modX();
// Initialise the core to access the default 'web' context
$modx->initialize('web');
And getting the following error:
Fatal error: Call to a member function get() on a non-object
Any help would be greatly appreciated since I'm not sure if I'm on the right path or not.
Perhaps a posthook would be useful? A posthook is just a snippet that is run after a new user has been registered. Register your posthook with the &postHooks property, and in the snippet send the email to the admin.
-
- 5 Posts
Thanks I'll be reading up on that tonight.
-
- 5 Posts
was I on the right path for creating a session? Beacause i'd prefer to just use this code if possible.
-
- 24,544 Posts
You were on the right track. The error message should give you the line number where the get() is failing. The odds are that it's not a problem with instantiating MODX, but some other object. Usually it's a failed getObject() or getCollection() call with no sanity check.
That said, I would do it with a Register postHook as Susan suggests. A postHook is just a snippet that you name in the Register snippets &postHooks property (e.g., &postHooks=`EmailAdmin`). In the register postHook snippet you can do this:
if (isset($hook)) {
$userObj = $hook->getValue('register.user');
$userProfileObj = $hook->getValue('register.profile');
$userEmail = $userProfileObj->get('email');
$userName = $userObj->get('username');
/* send the email here */
}