We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7674
    • 4 Posts
    Hello.

    I create new resource with my snippet.
    After success creation I need to redirect to created resource.
    To generate redirect url I user $modx->makeURL();
    But url is empty.

    Here is my code:

    <?php
    if(isset($_REQUEST[’status’])){
    if(isset($_REQUEST[’broadcast_name’])){
    $broadcast = $modx->newObject(’modResource’);
    $broadcast->set(’pagetitle’,$_REQUEST[’broadcast_name’]);
    $broadcast->set(’description’,$_REQUEST[’broadcast_description’]);
    $broadcast->set(’published’,1);
    $broadcast->set(’template’,2);
    $broadcast->set(’searchable’,1);
    $broadcast->set(’cacheable’,1);
    $broadcast->set(’createdby’,$modx->user->get(’id’));
    $broadcast->set(’publichedby’,$modx->user->get(’id’));
    $broadcast->set(’parent’,2);

    if($broadcast->save()===true){
    $id=$broadcast->get(’id’);
    $url = $modx->makeUrl($id,’’,’’,’full’);
    print_r($url." ".$id); // here url is empty, but id is correct.
    }
    }
    }​

    if use this method:
    header(’Location: http://turncamon.com/index.php?id=’.$broadcast->get(’id’));
    all works fine.

    But I want do this with modx api.

    If anybody know what could be the reason, tell please.
      • 26903
      • 1,336 Posts
      Try $id = (int)$id before you pass it to makeUrl
        Use MODx, or the cat gets it!
        • 7674
        • 4 Posts
        shamblett, thanks for your reply. I’ve already tried this, but there was no changes. I also have tried to make url with non-existing id and effect was the same. And I’ve tried to do this with static id, that way all worked fine. Also there is no any error in logs, but url is empty sad