We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12793
    • 293 Posts
    I’d like to know how to integrate existing PHP script in Modx

    Suppose that I’ve some PHP pages (MVC) that show records in a table and make some changes in table, another page that read values from a web services.... a these page have a MVC structure and I like to integrate these pages in Modx Layout, attach the code of my view and keep Model and Controller.

    Thanks
      • 22840
      • 1,572 Posts
      to include php in modx just create a snippet, then call the snippet into the page, for example if you create a new snippet and call it mysnippet add [[mysnipper]] to either the page content or template.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You will in most cases be able to simply have a single include line in your MODx snippet to include your existing .php file. Sometimes it needs a bit of tweaking, though, especially to properly format your code’s output.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 12793
          • 293 Posts
          Thanks for your replies, but suppose that I’ve 10 PHP pages (10 views pages) and other X pages for the controller.... these pages are linked (for example for read paramters during the page call) ... how can integrate this solution in ModX?

          Thanks
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Then the including snippet would need to have a conditional to determine which script to include.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 12793
              • 293 Posts
              Excuse but I don’t know what do you mean!

              In snippet I can add PHP code

              but if my "small PHP web application" is composed by many pages ... how can I do this?

              Thanks
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                It depends on the application, and how it determines which page to display.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 12793
                  • 293 Posts
                  Suppose that I’ve these pages:

                  list.php
                  listmananager.php
                  the allow to show records

                  detail.php
                  detailmanager.php
                  that allow to show detail of each record, selecting a specific record of the list
                  in each row of list grid I’ve a link like this detail.php?ID=12 for open each detail page


                  I’d like to include the list of records page (in modx template) and when a user select a record open the detail page (in modx template)


                  Can you tell me the solution that I’ve to use?

                  Thanks

                    • 12793
                    • 293 Posts
                    Please help me!!!

                    Are many days that I’m trying to resolve this probem?

                    Thanks
                      • 3749
                      • 24,544 Posts
                      I think the starting point would be to create a MODx document for each php file. Each of those pages would have nothing but a call to its own snippet and that snippet would just have an include statement to include the one appropriate php file. You’ll probably need some tweaking to get that to work, but it may be easier than rewriting the whole application in MODx.

                      As an alternative, you could leave your whole original application as is outside of MODx, style it to look like the MODx site, and put links from one to the other.
                        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