jaxon-core icon indicating copy to clipboard operation
jaxon-core copied to clipboard

Directory Registration

Open edrobinson opened this issue 3 months ago • 4 comments

Hi Thierry, I have taken your advice and structured my project with def, class, and view files and it works splendidly! Thank you very much... I should have listened in the first place. The change wasn't a major task, Just a lot of copy, cut and paste.

Here is the code for my Admin Login page:

Defs File:

<?php
/* Admin Login Page defs */
use Jaxon\Jaxon;
use function Jaxon\jaxon;

$jaxon = jaxon();

$jaxon->register(Jaxon::CALLABLE_CLASS, AdminClass::class);

//Process or display?
if($jaxon->canProcessRequest())
{
	$jaxon->processRequest();
}else{
	$view = new AdminView(); 
}

Registered Class File:

<?php
/*
    Admin Login Page Class
	The administrator credentials are in the name "Administrator."
	The password is the md5 hash of the password.
*/
use Jaxon\Jaxon;
use function Jaxon\jaxon;

class AdminClass
{
    use PageClassTraits;  //All things common...

    public function processForm($data)
    {
        $resp = jaxon()->newResponse();
        $datalist = json_decode($data, true); //to an assoc array
        extract($datalist);
		$di = new Dependencies();
		$db = $di->getEzDB();
		$pwhash   = md5($password);
		$qry = "select username, password from users where name = 'Administrator'";
		$row = $db->get_row($qry, ARRAY_A);
		
		
		if($username == $row['username'] && $pwhash == $row['password'])
		{
			$_SESSION['isAdmin'] = true; //Turn on the admin indicator
			$_SESSION['username'] = 'admin';
			$resp->call('loginOk');
		}else{

			$resp->call('loginFailed');
		}
		return $resp;
    }
}

View File:

<?php
// Admin login page view
class AdminView
{
    use PageClassTraits;  
 
    public function __construct()
    {
        $this->setup();
        $this->jaxon = $this->di->getJaxon();
        $this->completePageSetup();
    }
    
    //Finish the template vars and display the page
    public function completePageSetup()
    {
        $this->smarty = $this->di->getSmarty(); //Instance the Smarty engine
        
        $this->JaxonCode();//Generate the Jaxon JS and CSS scripts
        $this->smarty->assign('title', 'Admin Login');
        $this->smarty->assign('pagename', 'Admin Login');
        $this->smarty->assign('helpname', 'adminlogin');
        $this->showPage('adminlogin.tpl');
    }
}    

On a whim, I decided to try putting all of my classes in one directory and registering that directory and capturing the generated JavaScript.

This also works splendidly! I just wrote a short PHP script to do the generation.

The issue is that the "jaxon.config.requestURI" contains the name of my generation script.

I can add a small hack to my pages JavaScripts to set it to the URI that I want if need be. Is there any other way to do this?

Is it even worth messing with in your opinion? The generated code is less than 150 lines and the project is already blazingly fast.

Thanks, Ed

P.S. I want to use Grav for my docs and I like the theme you used for the Jaxon docs but I cant find it anywhere.

edrobinson avatar Apr 01 '24 19:04 edrobinson

Hi Ed,

I'm pleased to see you using more Jaxon features, and I hope it makes you developer life easier.

By default, Jaxon will guess the URL where to send the Ajax requests. That's why the jaxon.config.requestURI value defaults to your generation script. You can also set that value using the core.request.uri config option in your defs file.

$jaxon->setOption('core.request.uri', $ajaxUri);

Unfortunately, the site where I got the theme for the Jaxon website has closed a while ago. The theme name is Habitat, may be you can find it elsewhere.

feuzeu avatar Apr 02 '24 11:04 feuzeu

Thanks for your reply, Thierry.

The set-option() seems like the simplest solution.

I couldn't find the Habitat theme so I may roll my own.

Thanks again, Ed

On Tue, Apr 2, 2024 at 5:37 AM Thierry Feuzeu @.***> wrote:

Hi Ed,

I'm pleased to see you using more Jaxon features, and I hope it makes you developer life easier.

By default, Jaxon will guess the URL where to send the Ajax requests. That's why the jaxon.config.requestURI value defaults to your generation script. You can also set that value using the core.request.uri config option in your defs file.

$jaxon->setOption('core.request.uri', $ajaxUri);

Unfortunately, the site where I got the theme for the Jaxon website has closed a while ago. The theme name is Habitat, may be you can find it elsewhere.

— Reply to this email directly, view it on GitHub https://github.com/jaxon-php/jaxon-core/issues/122#issuecomment-2031778532, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFCS54KBKTWNZ7A4K4AGMDY3KJ63AVCNFSM6AAAAABFSCW3TSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZRG43TQNJTGI . You are receiving this because you authored the thread.Message ID: @.***>

-- Ed Robinson Ph: 208-376-2680

edrobinson avatar Apr 02 '24 17:04 edrobinson

Hi Ed,

You can find the Habitat template files here: https://github.com/jaxon-php/jaxon-website/tree/master/user/themes/habitat/html I think it can be use safely, I mean without any licensing issue.

feuzeu avatar Apr 03 '24 13:04 feuzeu

Thanks, Thierry, I'll have a look. Ed

On Wed, Apr 3, 2024 at 7:01 AM Thierry Feuzeu @.***> wrote:

Hi Ed,

You can find the Habitat template files here: https://github.com/jaxon-php/jaxon-website/tree/master/user/themes/habitat/html I think it can be use safely, I mean without any licensing issue.

— Reply to this email directly, view it on GitHub https://github.com/jaxon-php/jaxon-core/issues/122#issuecomment-2034544071, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFCS564CRL3UAXRQQUOUTTY3P4SDAVCNFSM6AAAAABFSCW3TSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZUGU2DIMBXGE . You are receiving this because you authored the thread.Message ID: @.***>

-- Ed Robinson Ph: 208-376-2680

edrobinson avatar Apr 03 '24 19:04 edrobinson