We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • It seems that no config file is found.
      • 36345
      • 26 Posts
      ah, ok...

      The Extra had installed with this set: The folder where the plugin config files are load from - {core_path}components/customrequest/

      I'd tried before adding configs/ at the end but no change but now when I add it the debug code gives me:

      property/355/355/355.html
      
      Array
      (
          [property/] => Array
              (
                  [resourceId] => 10
                  [alias] => property/
                  [urlParams] => Array
                      (
                          [0] => property
                          [1] => name
                          [2] => location
                      )
      
                  [regEx] => 
              )
      
      )


      for: http://www.domain.com/property/355/355/355.html

      Without the debug I get the homepage still. [ed. note: xgarb last edited this post 9 years, 8 months ago.]
        • 36345
        • 26 Posts
        OK.. I appear to have it working.

        The problem with still redirecting to the homepage turned out to be due to me overwriting a line of code in the plugin.

        I had to make a couple of changes to make it work as well.

        For this url www.domain.com/property/london/thepalace/355 (the final part is the id of the property - the rest SEO)

        I have the following config
        <?php
        $settings['property'] = array(
            'resourceId' => 10,
            'urlParams' => array('location','name','property')
        );

        (notice 'property' is the last element)

        At line 209 in customrequest.class.php the following debug
        echo "<br><br>KEY: ".$setting['urlParams'][$key];
        echo "<br> VALUE: ".$value;

        gives
        KEY: location
        VALUE: london

        KEY: name
        VALUE: thepalace

        KEY: property
        VALUE: 355
        in the browser (hence order of urlParams in config above) so I knew the correct data was being created.

        I then changed
        $_REQUEST[$setting['urlParams'][$key]] = $value;
        to
        $_GET[$setting['urlParams'][$key]] = $value;


        because REQUEST didn't appear to work.

        I didn't realise how easy it is to make Modx create a page for a specific URL with whatever content you want. In my case it might have been easier for me to just take the last part of the URL and send it to the resource as a GET parameter for processing.
        [ed. note: xgarb last edited this post 9 years, 8 months ago.]
        • Setting $_REQUEST['x'] in the CustomRequest code does not set $_GET['x'] automatic. So you have to change the CustomRequest code to $_GET (as you have done) or use $_REQUEST in your snippet code.
            • 36345
            • 26 Posts
            Just for my own notes (and maybe helpful to someone)

            To make this URL: domain.com/property-street-name-town-1234.html
            show this page under the hood: domain.com/index.php?id=3&pid=1234

            create a plugin with the 'onPageNotFound' box ticked with the following code...


            $param_alias = $modx->getOption('request_param_alias');
            $get = $modx->getOption('GET', $modx->request->parameters, '');
            $pageFilenameAndExt = $modx->getOption($param_alias, $get, '');
            
            $pageFilename = substr($pageFilenameAndExt, 0, -5);
            
            if (substr($pageFilename, 0, 9) == 'property-'){ // is a property detail page
            
            	$match = array();
            	if (preg_match('#(\d+)$#', $pageFilename, $match)) { // some magic
            		$propertyID = $match[1];
            	}
            
            $_GET['pid'] = $propertyID;
            $modx->sendForward(3);
            }


            This is a mix of code that I found in various places so it might not be optimal. The first three lines especially seem a long way round but I couldn't work out a better way.
            • You could use CustomRequest for this instead of writing an own plugin.

              Configuration in CMP (since version CustomRequest 1.1.0):
              Configuration Name: Property
              Alias Path: property-
              Resource: ResourceNameWithID3 (3)
              URI Parameter: ["pid"]
              Regular Expression: #(\d+)$#

              Untested, but should work this way.
                • 46459
                • 7 Posts
                Hi Jako,

                I am having issues on getting CustomRequest to use any regex in path. I try even changing the delimiter, verified the regex to see if it's valid.

                I got it to work with static paths, example
                path: news/99/video

                This works fine, now when I try regex is does nothing, example
                path: #.*?(news/)$#
                path: ~[a-zA-Z]+\/(\d+)\/video~

                Among other regex tried.

                Any ideas why?

                Thanks in advance.

                  • 3749
                  • 24,544 Posts
                  Looking at the code, it appears that there's a 'regex' setting or property in the config that needs to be set.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 46459
                    • 7 Posts
                    I searched on settings, and around modx manager I don't see a setting.
                      • 53611
                      • 4 Posts
                      Hi,

                      I have tried few recommended examples at http://jako.github.io/CustomRequest/usage/ but only allias path with "tst" appeared to work: http://modx.localhost.com/tst opens my page with resource ID = 13 (http://modx.localhost.com/test.php)
                      When changing allias path to "tst/" (adding slash) the example it doesn't work anymore and opens page 404.

                      I also tried Pagination example AS IS
                      allias path is #.*?(page/)#, URI paramener is ["page"], RegEx is #(\d+)#
                      with http://modx.localhost.com/page/test.php and http://modx.localhost.com/page/13 . It also opens page 404.

                      What I do wrong?

                      P.S. I just installed CustomRequest today, so its the newest version of plugin. I have SEO Tab installed. Could it influence CustomRequest plugin somehow?