Pages

Showing posts with label modx revo. Show all posts
Showing posts with label modx revo. Show all posts

Thursday, December 19, 2013

Code for Create or Update Resource in Modx Revo

Code for create new resource in Modx Revo :

                    $class = 'modResource';
                    $resource= $modx->newObject($class);
                    $resource->set('context_key', 'web');
                    $resource->set('content_type', 1);
                    $resource->set('pagetitle', PAGE_TITLE); //  here you enter your new resource pagetitle
                    $resource->set('parent', PARENT_ID); // here you enter parent id in which you want to see you new resource
                    $resource->set('isfolder', false);
                    $resource->set('published', true);
                    $resource->set('template', TEMPLATE_ID); // set template id
                    $resource->set('pub_date', strftime('%Y-%m-%d %H:%M:%S',strtotime(PUBLISH_DATE))); // set publish date
                    $resource->set('searchable', $this->modx->getOption('search_default'));
                    $resource->set('cacheable', $this->modx->getOption('cache_default'));
                   
                    $resource->_fields['content']= $res_content; // set resource content in $res_content
                    $resource->save();

now it will create new reource in your modx. Now,

   
Code for create new resource in Modx Revo :

            $newResourceUpdate = $modx->getObject('modResource',RESOURCE_ID); // set resource id
            $newResourceUpdate->set('template',TEMPLATE_ID);
            $newResourceUpdate->set('parent',PARENT_ID);
            $newResourceUpdate->set('pub_date', strftime('%Y-%m-%d %H:%M:%S',strtotime(PUBLISH_DATE)));
            $newResourceUpdate->save();

After this it will update your resource values.

Comment it and ?Share it if it helps you.

Code for Duplicate resource in modx revo

 Here is the code for Duplicate resource in modx revolution :

            $oldResource = $modx->getObject('modResource',RESOURCE_ID); // set resource id from which you want to Duplicate resource
             if (empty($oldResource)) return $modx->error->failure($modx->lexicon('resource_err_nfs',array('id' => $props['resourceID'])));
           
            if (!$oldResource->checkPolicy('copy')) {
                return $modx->error->failure($modx->lexicon('permission_denied'));
            }
           
            /* get parent */
            $parent = $cat;
           
            $newResource = $oldResource->duplicate(array(
                'newName' => NEW_TITLE,  // New Title which you want to see in new resource
            ));
            if (!($newResource instanceof modResource)) {
                return $newResource;
            }
           
            $modx->invokeEvent('OnResourceDuplicate',array(
                'newResource' => &$newResource,
                'oldResource' => &$oldResource,
            ));

Comment it and Share it if it helps you.

Tuesday, October 15, 2013

migx inside migx in Modx Revo

Here i am showing code for migx within another migx in Modx Revolution

BackEnd :
first you have to written below code in "Form tabs" when you create migx TV in which you want to show another migx,

{"field":"institutions","caption":"Institutions","inputTV":"another_migx_name","renderer":"this.renderChunk"},

this will create another migx inside your original migx and store values in it.

FrontEnd :
now in frontend in main migx write simple migx code for fetch values from main migx.
[[!getImageList?
           &tvname='migxTVname`
           &tpl=`mainChunkName`
]]

in another migx for fetching values you can write like this code,
[[!getImageList?
        &value=`[[+institutions]]`
        &tpl=`Chunk_name`
]]

now it's done, and it will show your inside migx values.

If this helps you comment it and share it.

Wednesday, March 6, 2013

Get resource id from resource name in modx revolution


$resource = $modx->getObject('modResource',Resource_Id);
$longTitle = $resource->get('pagetitle');

Here, from above code you can get pagetitle from resource id(Resource_Id).



Get resource id from resource name

$resource = $modx->getObject('modResource','Resource_Name');
$longTitle = $resource->get('id');

in this code you can get resource id from resource pagetitle('Resource_Name').

Get template id from template name modx revolution

$templateObj = $modx->resource->getOne('Template',array('templatename'=>'Template_Name'));
$templateid = $templateObj->get('id');

Here, in this code "Template_Name" is template name from which user want to get template id.

Wednesday, December 12, 2012

TV image preview modx Revo

There is a bug in modx revo that in manager i can't see image preview in TV.

Solutions is :

So, following the method mentioned in the bug report, I simply changed Line 219 in core/model/phpthumb/phpthumb.class.php:

From :
$this->config_document_root = (@$_SERVER['DOCUMENT_ROOT'] ? $_SERVER['DOCUMENT_ROOT'] : $this->config_document_root);

To :
$this->config_document_root = (@$_SERVER['DOCUMENT_ROOT'] ? '/home/username/public_html' : $this->config_document_root);

and it's worked for me.