We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    We are working on an frontend-editor for 096.xx. Now I’m trying to run it on revolution. Our ajax-connector for 096 is running on a document for webusers and as a module for manager-users like quickedit, so the manager-user can send also modx-tags to the database.
    In revolution I created an manager-action for that. Seems to work so far as I was hoping.
    One of the problems I have now:
    In 096 I send the updated page-content successfull back after saving the modified content(s) with $modx->sendForward($docid).
    In revolution I get
    <html><head><title>Error 404: Page not found</title></head><body><h1>Page not found</h1><p>The page you
    requested was not found.</p></body></html>

    Now my first question (I’m sure there are coming much more how todo things in revo, because I have a lot of deprecated functions in use now): What is the proper way in revolution to get a rendered page for a given resourceid?

    thanks for your help
    Bruno
      -------------------------------

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
      • 4172
      • 5,888 Posts
      I tried
      	$resource = $modx->getObject('modResource', array ('id'=>$docid), true);
      	        $output = $resource->process();


      then I get

      <b>Fatal error</b>: Call to a member function get() on a non-object in <b>E:\xampp\htdocs\revolution
      \core\components\wayfinder\wayfinder.class.php</b> on line <b>53</b>

      this is the line 53 in wayfinder.class.php:
                  'id' => $this->modx->resource->get('id'),


      seems not to be the right way for that

      [Edit]
      This seems to be better:
      	$modx->resource = $modx->getObject('modResource', array ('id'=>$docid), true);
      	
      	echo $modx->resource->process();


      is that the way we can do it?

      [Edit2]
      No, its better but not really good.

      plugins, snippets, tvs are not processed this way as it sendForward does in 096
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 22303 MODX Staff
        • 10,725 Posts
        $modx->sendForward() is the proper way. I’m not sure I completely understand the scenario though. Are you sure your target Resource is valid, published, accessible, etc.?
          • 4172
          • 5,888 Posts
          aah, great! I see

          }).send('reload=wrapper&docid='+brunoclass.doc_id+edited +'&docurl='+encodeURIComponent(document.URL));


          with

          $modx->sendRedirect($_POST['docurl']);


          does it now. sendForward did not work here.

          Thanks
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 4172
            • 5,888 Posts
            exists anywhere a function like this which returns an array of Tvs or, maybe better, modTemplateVar-Objects:

            getTemplateVars($TvnameIds=’*’, $fields = "*", $docid=’’, $template=’’, $published=’1’ , $sort = "rank", $dir = "ASC");
            /*
            *TvnameIds - TvNames or TvIds, ’*’ gets all:array
            *$fields - Fieldnames, ’*’ gets all fields:array
            *$docid - ResourceId, ’’ && $template == ’’ gets all TVs:string
            *$template - TemplateId, ’’ && $docid == ’’ gets all TVs:string
            *$published - 2 gets published and unpublished:string
            *
            */

            if not I will try it
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 4172
              • 5,888 Posts
              What I have now is that, seems to work so far

              <?php
               function getTemplateVars($Tvnames, $docid ){
                      global $modx;
              
                      $resourceId = $docid;
                      $resourceClass = 'modDocument';
                      $resource = $modx->getObject($resourceClass, $resourceId);
                      $docid = $resource->get('id') == $resourceId?$resourceId:'new';
                  
                      if ($docid == 'new')
                      {
              			$tvObjects = $modx->getCollection('modTemplateVar');
              			$resourceFields = $modx->getFields($resourceClass);
                      } else
                      {
                          //$tvs = $modx->getTemplateVars($Tvnames, $fields = "*", $docid, $published , $sort = "rank", $dir = "ASC");
                          //$resourceClass= isset ($_REQUEST['class_key']) ? $_REQUEST['class_key'] : 'modDocument';
                          //see manager\controllers\resource\tvs.php
                          $tvObjects = $resource->getMany('modTemplateVar');
              			$resourceFields = $resource->toArray();
                      }
                      $tvs = array ();
                      if (is_array($tvObjects) && count($tvObjects) > 0)
                      {
                          foreach ($tvObjects as $tvObject)
                          {
                              $tv = $tvObject->toArray();
                              if (in_array($tv['name'], $Tvnames))
                              {
                                  $tvs[$tv['name']] = $tv;
                              }
                          }
                      }
              
                      //merge documentfields to tvfields
                      foreach ($resourceFields as $key=>$field){
              			if (in_array($key,$Tvnames)){
              					$tvs[$key]['name'] = $key;
                                  $tvs[$key]['value'] = $field;
              			}
                      }
              		/*
              		if (count($Tvnames) > 0)
                      {
                          foreach ($Tvnames as $Tvname)
                          {
                              $Tvname = trim($Tvname);
                              if ( isset($resourceFields[$Tvname]))
                              {
              					$tvs[$Tvname]['name'] = $Tvname;
                                  $tvs[$Tvname]['value'] = $resourceFields[$Tvname];
                              }
                          }
                      }
                      */
                      return $tvs;
              	
              }
              ?>
              
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 22303 MODX Staff
                • 10,725 Posts
                If you just want the TV’s irregardless of a specific Resource, you use the getCollection() method of xPDO, which the modX class extends:
                $tvCollection = $modx->getCollection('modTemplateVar', "`name` IN ('" . implode("','", array('footer', 'header', 'Test.One')) . "')");


                If you want all the TV’s and values specific to a Resource:
                $resource = $modx->getObject('modResource', 12);
                if ($resource) $tvCollection = $resource->getMany('modTemplateVar');
                  • 4172
                  • 5,888 Posts
                  Thanks for clearing that, Jason.

                  Quote from: OpenGeek at May 28, 2009, 08:14 AM

                  If you just want the TV’s irregardless of a specific Resource, you use the getCollection() method of xPDO, which the modX class extends:
                  $tvCollection = $modx->getCollection('modTemplateVar', "`name` IN ('" . implode("','", array('footer', 'header', 'Test.One')) . "')");


                  If you want all the TV’s and values specific to a Resource:
                  $resource = $modx->getObject('modResource', 12);
                  if ($resource) $tvCollection = $resource->getMany('modTemplateVar');


                  Can I also have an criteria for "`name` IN (’" . implode("’,’", array(’footer’, ’header’, ’Test.One’)) . "’)" in getMany?

                  Another question to revo beta now: Is the new beta release the same as revision 5070?
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 28215
                    • 4,149 Posts
                    Quote from: Bruno17 at May 29, 2009, 01:01 AM

                    Can I also have an criteria for "`name` IN (’" . implode("’,’", array(’footer’, ’header’, ’Test.One’)) . "’)" in getMany?
                    Yes. $modx->getMany(’Alias’,$criteria);


                    Another question to revo beta now: Is the new beta release the same as revision 5070?

                    Yes. beta-1 is the 5070 revision of SVN.
                      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                      • 4172
                      • 5,888 Posts
                      when I use

                      			$criteria = "`name` IN ('" . implode("','", $Tvnames) . "')";
                                  $tvObjects = $resource->getMany('modTemplateVar',$criteria);
                      			$resourceFields = $resource->toArray();
                              }
                              $tvs = array ();
                              if (is_array($tvObjects) && count($tvObjects) > 0)
                              {
                                  foreach ($tvObjects as $tvObject)
                                  {
                                      $tv = $tvObject->toArray();
                      				print_r($tv);
                                      if (in_array($tv['name'], $Tvnames))
                                      {
                                          $tvs[$tv['name']] = $tv;
                                      }
                                  }
                              }


                      I get only the fields of site_tmplvars. Without $criteria in getMany I get all fields from table site_tmplvars and modx_site_tmplvar_contentvalues

                      I think there is something wrong with my $criteria??
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!