{"id":19614989,"url":"https://github.com/infostreams/php-rails-routing","last_synced_at":"2025-04-28T02:31:03.745Z","repository":{"id":148959862,"uuid":"6170631","full_name":"infostreams/php-rails-routing","owner":"infostreams","description":"Rails like routing for PHP","archived":false,"fork":false,"pushed_at":"2015-11-27T08:48:04.000Z","size":15,"stargazers_count":8,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-30T06:15:01.165Z","etag":null,"topics":["php","router"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/infostreams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-11T08:18:57.000Z","updated_at":"2023-04-14T08:26:36.207Z","dependencies_parsed_at":"2023-04-14T08:26:36.025Z","dependency_job_id":null,"html_url":"https://github.com/infostreams/php-rails-routing","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infostreams%2Fphp-rails-routing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infostreams%2Fphp-rails-routing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infostreams%2Fphp-rails-routing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infostreams%2Fphp-rails-routing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infostreams","download_url":"https://codeload.github.com/infostreams/php-rails-routing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224092034,"owners_count":17254152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","router"],"created_at":"2024-11-11T10:54:50.018Z","updated_at":"2024-11-11T10:54:51.216Z","avatar_url":"https://github.com/infostreams.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Rails like routing for PHP\n==========================\n\nInstallation\n------------\nFirst, navigate to the directory that contains the script that you want to use  \nas the main entry point for your application.\n\nBasically, the installation comes down to: setup the .htaccess file, and\ninclude 'router.php' from your main script.\n\nIn smaller steps, this would translate to:\n\n1. Put router.php somewhere where it can be included from that script\n2. Copy 'htaccess.txt' to the directory that contains your entry script\n3. Rename the 'htaccess.txt' file to '.htaccess'\n4. The default 'htaccess.txt' file assumes your main script is index.php. If that's not the case, change accordingly.    \n5. Include the 'router.php' file from your main script\n6. Set up the routes. Examples below or in 'example/index.php'\n\nExamples\n--------\n(these examples assume the script is running in the 'example/' subdirectory)\n\n\trequire('router.php');\n\t\n\t$r = new Router();\n\t\n\t// The default page people will see, e.g. this is a\n\t// mapping for http://\u003clocation\u003e/example\n\t// -\u003e runs HelloController-\u003eoverview()\n\t$r-\u003emap(\"\", \"Hello::overview\");\n\t\n\t// mapping for http://\u003clocation\u003e/example/hello/en\n\t// -\u003e runs HelloController-\u003eworld()\n\t$r-\u003emap(\"hello\", \"Hello::world\");\n\t$r-\u003emap(\"hello/en\", \"Hello::world\");\n\t\n\t// mapping for http://\u003clocation\u003e/example/hello/fr\n\t// -\u003e runs HelloController-\u003emonde()\n\t$r-\u003emap(\"hello/fr\", \"Hello::monde\");\n\t\n\t// mapping for http://\u003clocation\u003e/example/\u003cfilename\u003e.\u003ctxt|json\u003e\n\t// -\u003e runs FileController-\u003edownload($filename, $ext) \n\t//    where $filename matches \u003cfilename\u003e and $ext is either 'txt' or 'json'\n\t$r-\u003emap(\":filename\\.:ext\",\n\t\t\t\"File::download\", \n\t\t\t// regular expressions determine what is valid for 'filename' and 'ext'\n\t\t\tarray(\"filename\"=\u003e'[\\w\\d_-]+', \"ext\"=\u003e\"(txt|json)\"));\n\t\n\t// generic mapping for http://\u003clocation\u003e/example/\u003ccontroller\u003e/\u003caction\u003e\n\t// -\u003e for example http://\u003clocation\u003e/example/person/all will run \n\t//    PersonController-\u003eall()\n\t// -\u003e or http://\u003clocation\u003e/example/organisation/add will run\n\t//    OrganisationController-\u003eadd()\n\t$r-\u003emap(\":controller/:action\");\n\t\n\t// generic mapping for http://\u003clocation\u003e/example/\u003ccontroller\u003e/\u003cid\u003e\n\t// -\u003e for example http://\u003clocation\u003e/example/person/2 will run \n\t//    PersonController-\u003eview(2)\n\t// -\u003e or http://\u003clocation\u003e/example/organisation/3 will run\n\t//    OrganisationController-\u003eview(3)\n\t$r-\u003emap(\":controller/:id\", \n\t\t\tarray('action'=\u003e'view'), \n\t\t\tarray(\"id\"=\u003e\"[0-9]+\")); // only allow numeric values for 'id'\n\t\n\t\n\t// any other initialization you need\n\n\t// Make sure to or require() your controller classes' files prior to $r-\u003erun()\n\t// (same-file controllers can go at the bottom of index.php)\n\n\t$r-\u003erun();\n\t?\u003e\n\n\n\nChangelog\n---------\nBased on http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/\nbut extended in significant ways:\n\n1. Can now be deployed in a subdirectory, not just the domain root\n2. Will now call the indicated controller \u0026 action. Named arguments are\n   converted to similarly method arguments, i.e. if you specify :id in the\n   URL mapping, the value of that parameter will be provided to the method's\n   '$id' parameter, if present.\n3. Will now allow URL mappings that contain a '?' - useful for mapping JSONP urls\n4. Should now correctly deal with spaces (%20) and other stuff in the URL\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfostreams%2Fphp-rails-routing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfostreams%2Fphp-rails-routing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfostreams%2Fphp-rails-routing/lists"}