I have two subdomains pointing to the "web" directory in my Symfony 1.4 implementation and would like to route to certain modules/actions based which subdomain was used to arrive at the site
sub1.domain.com --> module1/action
sub2.domain.com --> module2/action
Is there an easy way to do this in routing.yml? Customize index.php, parsing the host for subdomain?
Take a look at this chapter in More With Symfony. It does essentially the same thing by creating a custom route that checks the subdomain... It uses the DB but you could omit that if you dont need to hit the DB.
I'd rather write an execution filter or custom routing class.
Check out this example: http://www.symfony-project.org/more-with-symfony/1_4/en/02-Advanced-Routing
Related
So I am working on a project and I have decided to use php laravel framework, but when it comes to things like creating a new page and dealing with page redirects etc, am I right in thinking that all these will be handled in the route/web.php file so all the pages for my application will be defined in the route along with the view ?
I was thinking what if my application grows to have dozens of pages is it best practice to define each one on the route or are there better ways to handle this?
Yes, the best way to do routing is laravel to have each route for . each page, the only exception is when you have dynamic routes, for example, if you have a route that checks for users id or category for some product etc and it looks something like this Route::get("/product/{$category_id}","FrontController#methodForGetingProduct").
And later in Controller, you define what will you send and receive of the information and what view should be returned.
you can follow this type routing .......
I am currently learning Symfony2 and so far I really like the framework. However, I have a situation that I don't know how to solve.
I have a Symfony2 application that has two bundles: Frontend (prefix: /) and Admin (prefix: /admin; this prefix is changeable). Now, I am trying to add AngularJS application in HTML5 mode (the URLs don't have a hash).
Here is how I want to achieve this:
Create a "sub-bundle" that will have the following prefix: /admin/_api. Here are two examples on how they will look like: POST /admin/_api/users or GET /admin/_api/users/10
Create a 404 page in Admin bundle that will load the AngularJS template.
The reason for doing this is simple. When I open the path /admin/users/10 for the first time, the AdminBundle error page will open the AngularJS template. And AngularJS router will route /admin/users/10 to the necessary controller. Then, the AngularJS controller will make a request to GET /admin/_api/users/10 and send the returned JSON data from the server to the AngularJS view.
For the first problem, even if the solution is not the most elegant one, I can add prefixes in the AppBundle's configuration. But my main problem is the second one. How can I create a bundle based error page?
I have set up a simple app for now using ReactJS for the frontend and Laravel(5.1) for the backend.
All is OK but I woudl like to make the URLS look normal, as in the removal of the '/#' from the URL.
So
example.co.uk/#/about
becomes
example.co.uk/about
This is not an issue as I achieve this, but when I do it activate it, then the Laravel routing kicks in and flags a route error.
Is it possible to prevent Laravel form activating / doing this so that ReactJS takes over and works.
If so it would also be nice, so that if a Laravel route is set / wanted then it does use that one.
EG: These are ReactJS routes that would have used the '/#'
example.co.uk/about
example.co.uk/details
example.co.uk/listings
Then if I got to the following URL's then they are controlled by Laravel's routing?
example.co.uk/api/...
example.co.uk/admin/
Thanks
You need a catch-all route that will execute the same main controller action regardless the URL. Add the following to your routes.php
Route::get('{path?}', 'Controller#action')->where('path', '.*');
This way all URLs will go to Controller#action, that should display the base view for your application - the one that runs the ReactJS application.
I have a project where I need to mask the url.
Before: example.com/pogi/ako/
After: example.com/ako/
The application is created using codeigniter. Thoug the one found on the sub-directory have another webservice created with codeigniter as well. I tried doing some configurations I know with .htaccess and httpd.conf, but I was not able to make it run.
In the file "application/config/routes.php" add the line:
$route['ako'] = 'pogi/ako';
This will make is so that any request that comes through to example.com/ako will actually go to example.com/pogi/ako but it won't look like that.
Hope this helps!
You may want to remember how Codeigniter Handles URLs, you mentiond Sub Directory in your Question which also is Codeigniter Based Web Service !
When you are Running first Codeigniter App it will Catch your requested Url and get the related Controller and it's Method to Handle it !
Your Controllers can be nested in Sub Directory too ! also as #Ross Mentioned in his answer, this behavior can be override using Routes !
I’m a recent user of Codeigniter and am developing a simple backend CMS to manage pages.
Based on a URL (in this example I have hidden “index.php”) : mysite.com/pagename
I would like the system to detect if there is a value of “pagename” in my database, if there is, I need the system to re-route to a custom controller (eg: Pagemaker) and if there is no record called pagename, just do it’s normal thing (i.e. find a controller called pagename)
Currently I have:
$route['(:any)'] = "pagemaker/create/$1";
whereby all requests are forwarded to my custom function.
However I want to change this structure so that if the page does NOT exist in the db, the traditional codeigniter request process is followed.
Can anyone offer any advice about how to complete this? Or any advice about routing custom CMS’s in codeigniter in general?
The best solution is to upgrade to CI 2.0 because it's stable enough and it gives you plenty of useful features.
In your case, set the following route:
$route['404_override'] = 'pagemaker';
If the router doesn't know where to go it just goes to pagemaker controller. This can then check if the first uri segment exists and if not you create a custom 404 page instead of the crappy default one.
And I don't want to hear any of this "Oh but it's not released yet" crap, I've been using it CI 2.0 for almost a year. ;-)
I can think of two possibilities:
1) Edit your custom function to let it redirect your client when page's not in the db
pseudo code:
if($dbresult == null){
redirect("http://yoursite.com/"+$this->uri->segment(3));
}
2) Edit the router class of CI so it will first check if the page's in the db and if not, just continues. This may be somewhat messier as you need a db connection in your Router.php