I would like to build a platform that contain some versions control.
Now I would like to create for each version folder inside the controller folder so I can merge all version related controllers inside.
For example controller folder:
1.0.0/default.php
2.0.0/default.php
3.0.0/default.php
(So in this example 1.0.0 is the version number and default is the controller name)
So I would like to create some routing rules so that version structure will work from URL:
http://www.mywebsite.com/1.0.0/
Any idea how to do it? also there may be more then one controller for each version for example:
1.0.0/default
1.0.0/login
1.0.0/member
here my routes info:
$route['default_controller'] = 'default';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Thanks
You can do as follows inside your routes file:
$route['1.0.0'] = '1.0.0/default';
or if you want it more dynamic:
$route[(:version)] = "$version/default";
Use subFolders
When using this feature the first segment of your URI must specify the
folder. For example, let’s say you have a controller located here:
application/controllers/products/Shoes.php
To call the above controller your URI will look something like this:
example.com/index.php/products/shoes/show/123
Related
This is the application structure
-app
-controllers
-v1
-home.php
-login.php
-models
-v1
-home_model.php
-login_model.php
-views
-v1
-home
-index.php
-login
-index.php
My default controller is v1/home.php
I want to remove v1 from the url while routing meaning the url should read www.abc.com/login instead of www.abc.com/v1/login
So when i release a v2 version of the app i can write another rule in the routes and v1 and v2 code both will be live at the same time.
here is what I have tried
$route['default_controller'] = "v1/home";
$route['v1/(:any)'] = "/$1";
try these routes instead
$route['default_controller'] = "v1/home";
$route['(:any)'] = "v1/$1";
in future when v2 is ready, simply change it to
$route['(:any)'] = "v2/$1";
Hello Codeigniter support two types of routing rules
1)Wildcards
2)Regular Expressions
I prefer Wildcards
in routes just place this one
$route['login/(:any)'] = "v1/login";
A URL with "login" as the first segment, and anything in the second will be remapped to the "v1" class and the "login" method.
means your change www.abc.com/login instead of www.abc.com/v1/login
check it once routing in codeigniter here https://ellislab.com/codeigniter/user-guide/general/routing.html
.......
I am using the latest version of CodeIgniter on Server2008 with IIS7.5
I have all of my CI files in a folder mywebsite.com/survey
nps = Controller
survey = Function
client_id = variable base64 encoded client number
I have a script that runs when you visit:
http://mywebsite.com/survey/nps/survey/client_id/MjgzOTcyMW
But I want for it to run when you visit:
http://mywebsite.com/survey/MjgzOTcyMW
How do I set up my routes.php?
I currently have:
$route['/:any'] = 'nps/survey/client_id/';
try
$route['(:any)'] = 'nps/survey/client_id/$1';
or
$route['survey/(:any)'] = 'nps/survey/client_id/$1';
You have to make sure you don't mix up your routes here:
Using just $route['/:any'] would be wrong (even if you had the (:any) correct.
To properly define a route), remember that the left hand side is the pattern route, and the right hand (after the =) is the translated controller/method/parameter format.
So define the route (after all your other routes) as they are to be ordered from MOST specific to least specific (similar to ALLOW/DENY rules etc;):
$route['survey/(:any)'] = 'nps/survey/client_id/$1';
I want to organize my views in packages / folders to avoid a long list. With the (great) new router, a view is provided by default that we can change by creating a new one with a convention name. For example:
match('/').to('home');
uses:
"home" handlebars template
App.HomeView
App.HomeController
Now I want to use:
"my_package/home" handlebars template (works)
App.MyPackage.HomeView
App.MyPackage.HomeController
When I use the gem "ember-rails" (the GIT version) and the generator:
rails g ember:view my_package/home
I get:
DemoEmberRails.MyPackage::HomeView = Ember.View.extend({
});
that is not a correct javascript code (seems to be an extract for ruby code).
I tried:
DemoEmberRails.MyPackage = {};
DemoEmberRails.MyPackage.HomeView = Ember.View.extend({
});
But it's not used by the router.
How to do that?
I think you should Namespace them using Ember.Namespace. I'm still not sure if the router will automatically search namespaces but it may?
http://emberjs.com/api/classes/Ember.Namespace.html
As you've said
match('/').to('home');
expects AppName.HomeRoute, AppName.HomeView and AppName.HomeController. So if you have a template with data-template-name="home" and a view similar to
AppName.HomeView = Ember.View.extend({
teplateName: 'home'
});
then ember will automatically connect the / route with this view.
The new ember routing guides are quite helpful here.
It looks like this is currently unsupported, however, a pull request exists to add this feature.
See:
https://github.com/emberjs/ember.js/pull/1679
Got a controller in codeigniter who handles different sub sites.
site/index/1 fetches content for subsite A
site/index/2 fetches content for subsite B
Now we decided to register domain names for these sub sites.
so what we need:
http://www.subsite1.com -> default controller should be site/index/1
without the site/index/1 in the URI.
http://www.subsite2.com -> default controller should be site/index/2
without the site/index/2 in the URI.
I fiddled and tried to play with routes.php but getting nowhere..
Can somebody point me in the right direction?
in your routes.php file you need to set this:
$route['default_controller'] = ($_SERVER['SERVER_NAME'] == 'http://www.subsite1.com' ? "site/index/1" : "site/index/2");
and if your trying to force it somewhere when some weird url is types in:
$route['404_override'] = ($_SERVER['SERVER_NAME'] == 'http://www.subsite1.com' ? "site/index/1" : "site/index/2");
and for the second one just switch it to 2
I want to group my controllers, views and models into public/ and members/ subfolders.
But for the public stuff, I don't want /public/ to show in the URL, so:
http://mysite.com/ & http://mysite.com/section/
should point to: /public/home & public/section/
How should I change routes.php to accommodate this?
(I'm fine with members/ stuff having members/ in the url)
To make http://mysite.com/ point to /public/home you will need to mark public/home as your default controller. You will also need to add a specific route to make http://mysite.com/section point to /public/section. Try this (the regex is a little dubious in my opinion, but may do what you want):
$route['default_controller'] = "public/home";
$route['section/(.*?)'] = "public/section/$1";
Kindly see if this works for you:
$route['section'] = "public/section";
Your index page would remain as "public/index.php"
You don't need to add routes for every controller.
This works for me:
$route['members'] = 'members'; // route members to members
$route['members/(.*?)'] = 'members/$1'; // route members/... to members/...
$route['(.*?)'] = 'public/$1'; // route anything but above lines to public/...
The first two lines are intentionally redundant to protect 'members' segment from being routed to 'public'. And the third line does the magic.