Quote from: xpix at May 01, 2008, 12:22 PM
To start I would like to use modx API to connect to the database. Something like you would do with the DB pear package.
Next step will be to check if modx’s user management is the one I need to define roles for the users.
The secret here is understanding the foundation of the new MODx, which is xPDO. In the new architecture, the old DocumentParser class is gone, replaced by the modX class, which just so happens to be a subclass of xPDO. An xPDO object represents a unique connection to the MODx database, and, in the case of modX, decorates the xPDO class with content management functionality. And to understand xPDO, you would do well to first understand
PDO itself. xPDO is designed to quickly provide a domain model (i.e. the classes defining your application) for a relational model (i.e. the database tables responsible for storage of persistent objects), and the relational layer, including scaffolding (a.k.a. CRUD), are made possible through PDO.
So now, instead of writing SQL queries to access MODx data, there is a complete set of classes with a consistent set of methods for working with all of the data MODx deals with.
Quote from: xpix at May 01, 2008, 12:22 PM
Since a project is a document with diffrent TVs (a different number of tv’s for each project, they might be the same) each document might need a diffrent template so I would need to create templates on the fly every time a project is created.
Quite simple to achieve, something like this (authentication/security issues not covered here; you would need to create some kind of service for your application to use to login and get a valid user session with proper permissions to do these things):
<?php
$template = $modx->newObject('modTemplate');
$template->set('templatename', 'NewTemplateName');
$template->set('description', 'my new template');
$template->set('content', '<html><head></head><body></body></html>');
if ($template->save()) {
// template was successful
} else {
// save failed; handle the error
}
?>
Quote from: xpix at May 01, 2008, 12:22 PM
Here is how I think the app will work
From adobe air I will be querying php files, something like Ajax requests. In those php files I would like the load the Modx framework and use it instead of creating my on classes.
While that is certainly a valid approach, why not let MODx manage your Ajax services? These are after all just MODx resources that respond to URL’s. You’re replacing an MVC framework with individual PHP files at that point; why give up all the advantages MODx will provide in helping you manage those services?
Quote from: xpix at May 01, 2008, 12:22 PM
I would like to know what will I need from the modx package to make it work.
<?php
define('MODX_CORE_PATH', '/path/to/core/');
define('MODX_CONFIG_KEY', 'config');
require_once(MODX_CORE_PATH . 'model/modx/modx.class.php');
$modx= new modX();
$modx->initialize('contextname');
?>
Quote from: xpix at May 01, 2008, 12:22 PM
Ex: Create a new project:
modx->createDocument(parameters);
modx->addTV(name1,DocumetID);
modx->addTV(name2, DocumetID);
Ex2: Create Users
modx->addUser(name1,role1);
modx->addUser(name2,role2);
<?php
// create a document and pass all the field values as an associative array
$document = $modx->newObject('modDocument', $parameters);
// now save...
$document->save();
// first get the modTemplateVar objects representing a template variable
$tvX = $modx->getObject('modTemplateVar', array('name' => 'X'));
$tvY = $modx->getObject('modTemplateVar', array('name' => 'Y'));
// now set values for them for specific documents if they are unique values
// (otherwise, they automatically get the default_text value for the TV via the template)
$tvX->setValue($document->id, 'new value for X and new document ' . $document->get('id'));
$tvY->setValue($document->id, 'new value for Y and new document ' . $document->get('id'));
?>
Hope that helps a little...