<?php
$doc = $modx->newObject('modDocument');
$doc->set('parent',5);
$doc->set('alias',index);
$doc->set('pagetitle','teste');
$doc->set('template','Geral'); /* I think you'll need the template's ID here */
$doc->set('published',1);
$doc->set('cacheable',0);
$doc->set('hidemenu',1);
$doc->setContent('<p>This is my content</p>');
$doc->save();
You mention that you used to make modules in Evo...
Revo has CMP -- custom manager pages, which replaced modules...
try them.
Resources or documents are for the front-end, CMP are for the manager.
Website: www.mercologia.com
MODX Revo Tutorials: www.modxperience.com
MODX Professional Partner
Quote from: x3m4ik at Oct 02, 2010, 01:42 PM
Quote from: BobRay at Oct 02, 2010, 01:13 PM
<?php
$doc = $modx->newObject('modDocument');
$doc->set('parent',5);
$doc->set('alias',index);
$doc->set('pagetitle','teste');
$doc->set('template','Geral'); /* I think you'll need the template's ID here */
$doc->set('published',1);
$doc->set('cacheable',0);
$doc->set('hidemenu',1);
$doc->setContent('<p>This is my content</p>');
$doc->save();
Thank you. A good example of how to insert a TV but a new resource?
An example with TVs. See formit2resource:
http://modxcms.com/forums/index.php/topic,54204.msg313114.html#msg313114
Here is one way:
<?php
$template = $modx->getObject('modTemplate',$modx->resource->get('template')));
$fields = array(
'name'=>'NewTV',
'type'=>'option',
'caption'=>'New TV',
'description'=>'My New TV',
'elements'=> 'red||blue||green',
'default_text'=>'red',
'display'=>'default'
);
$tv = $modx->newObject('modTemplateVar', $fields);
$intersect = $modx->newObject('modTemplateVarTemplate');
$intersect->addOne($tv);
$intersect->addOne($template);
$intersect->save();
$tv->setValue($id,'value'); /* ID is the id of the resource you want to set the TV for */
I mean, how to set a value for an already established TV to create a document using the Api?
Or is it impossible until I know the ID document?
Sorry, I’m using translate.google
Quote from: x3m4ik at Oct 02, 2010, 10:46 PM
I mean, how to set a value for an already established TV to create a document using the Api?
Or is it impossible until I know the ID document?
Sorry, I’m using translate.google
You do need to know the document ID, but if you just created it and saved it, you can retrieve it with getObject() and then set the TV:
<?php
$resource = $modx->newObject(('modDocument', array('name'=>'MyNewDoc'));
$resource->save();
$resource = $modx->getObject(('modDocument', array('name'=>'MyNewDoc'));
$id = $resource->get('id');
$tv = $modx->getObject('modTemplateVar',array('name'=>'MyTv'));
$tv->setValue($id,'value');
$tv->save()
If you’re not using your code within a modx context you have to create the modx object:
require_once 'YOUR_PATH_TO/config.core.php';
include_once MODX_CORE_PATH . 'model/modx/modx.class.php';
$modx= new modX();
Add-On to easily manage your multilingual sites:
Babel