We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6059
    • 45 Posts
    Hey i am new to Modx hope this is the right section for my question, if not please move it. rolleyes

    Ok i want to get data from my own tables (no modx tables) make a list from the result and link it to another site.
    I made a snippet that generate the List and links, and i generate a snippet that show the detailinfo for the link clicked, like a detailpage.
    But i can not click a link to go to detailpage because all links are the same, because i have only one detailpage. At usual php site i have a list with links and a parameter like id (table row id) to identify the element i want to show on detailpage, but how to do this with mody?
    And i want to use SEO Friendly URLs, i know how to set pagetitle, longtitle and description from snippet but how to set the resource alias? Hope you know what i mean, it like a usual website were on one site much links to detailpages are and a dynamic php site as detailpage wich loads all infos.
      • 4172
      • 5,888 Posts
      stripped down to the basics you can try something like that:

      say you have a field alias in your custom-table for friendly-URLs and your detailspage has an alias ’details’
      in your listing snippet you will have something like that:

      <?php
      
      $objects = $modx->getCollection($classname,$c);
          foreach ($objects as $object){
              $objectArray = $object->toArray();
      	    $objectArray['url'] = $modx->getOption('site_url').'details/'.$objectArray['alias'];
             	$output .= $modx->getChunk($tpl, $objectArray);
      	}



      create a plugin, which listens for the event ’OnPageNotFound’ with something like that:


      <?php
      if ($modx->event->name != 'OnPageNotFound') return;
      
             /*
             * set resource-ID where you have your details-snippet
             * this can also be custom-system-settings or plugin-properties
             */
      
             $pageid['details']='9999';
      
              /* handle redirects */
              $search = $_SERVER['REQUEST_URI'];
              $base_url = $this->modx->getOption('base_url');
              if ($base_url != '/') {
                  $search = str_replace($base_url,'',$search);
              }
              $search = trim($search, '/');
      
              /* get resource to redirect to */
      		$params = explode('/', $search);
      		$pagealias=$params[1];
      
              // check if requested object exists
      
      		$_REQUEST['alias'] = $params[2];
      
              if (isset($pageid[$pagealias]) && $object = $modx->getObject($classname,array('alias'=>$_REQUEST['alias']))){
                  /* forward to detailspage */
                  $this->modx->sendForward($pageid[$pagealias]);        	
              }
              return false;	
      


      this will send you forward to your details-page where you can get your detail-object with

      $object = $modx->getObject($classname,array('alias'=>$_REQUEST['alias']));


      may be there are small bugs. But this is the idea how you can do it in modx-Revo.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 22303 MODX Staff
        • 10,725 Posts
        Awesome Bruno17 — we should get you contributing to documentation. tongue