Routing in Kohana without showing controller name - kohana-3.3

I want to create a routing in Kohana Framework Version 3.3.1.
I want URL like http://www.test.com/male/London and internally they will act like below URL-
http://www.test.com/list/search/London
I want to hide the controller and action name from the URL.
Any help is greatly appreciated.

This can be accomplished by using routes in bootstrap.php and/or a module's init.php file.
For example, you could set up a route for (male/<location>) and then your default controller would be list and the action search.
You could then access the location within the controller/action by using $this->request->param('location'); to be used in whatever DB query you need it.
Confused? Have a read through this section of Kohana Docs and it should all make sense.

You have to do two changes in your file:
Bootstarp file :
Route::set('list', 'male/<id>' )
->defaults(array(
'controller' => 'list',
'action' => 'search',
));`
And second is you can make your link like
href="<?php echo URL::site('male/'.id, TRUE) ?>">
And this route file should above at your default route file.

Related

CakePHP 2.x: How can I overwrite an URL pointing to the index page?

I'm getting this issue:
Router::connect('/',array('controller' => 'Controller','action' => 'login'));
This will show www.mysite/controller/login as the site URL
I would like to overwrite www.mysite.com/controller/login with just www.mysite.com, but still go to the login page. Does anyone know how to do it with Cake 2.x?
The behavior It's not exactly as you describe.
What the following does:
Router::connect('/',array('controller' => 'Controller','action' => 'login'));
is allow you to type www.mysite.com in your browser, and get the view that www.mysite.com/controller/login renders.
It works like an url rewrite instead of a redirect. Therefore, the above should work as expected. However, if it's not an example, try to name your controller differently, as it may cause trouble with CakePHP.
As stated by Inigo Router::connect() just connects a route/URL to a controller action. So with your defined route you should be able to goto www.mysite.com and your login action will be served (although I'm not sure that it is a good idea to have the base URL act as the login page).
It does not prevent www.mysite.com/controller/login from working as this is one of CakePHP's default routes.
To disable the default routes you need to remove this line from routes.php:-
require CAKE . 'Config' . DS . 'routes.php';
Be warned, if you remove this line you must have defined routes for all your pages in your app's routes file. This is not necessarily a bad thing, Beware the Route to Evil is a good read in regards to this.
As I used the "Auth" component I had to add in the function
beforeFilter()
of my controller this line:
$this->Auth->allow('anAction', 'anotherAction', '**login**');

Laravel Redirects POST request to GET

I have a very strange problem.
I'm Posting a form with some files to the server but for some reason Laravel is redirecting my request with GET and of course I get a MethodNotAllowedException.
Here is the code for my Routes: Routes
I'm testing the route::post('/admin/article'), just returning all the input
Here is my front-end form: Form
I'm using CKEditor
Every time I include an image inside the editor of "cuerpo", Laravel redirects my request to GET /admin/article, which does not exists.
The funny thing is that if I just input plain text it works fine ....
I've had the same problem, and the solution for me was to use Laravels built-in form opener and change my routes, like this (Adding a named route):
Route::post('/admin/article/', array('as' => 'admin.addArticle', 'uses' => 'AdminController#addArticle'));
And open your form like this (using the named route):
echo Form::open(array('route' => 'admin.addArticle'));
I don't know why this works, and a normally created form does not.

How to hide url in angular?

Is it possible to not using angualar routes, because if I defined an routes like:
app.config(function($routeProvider){
$routeProvider.when('/home')
})
my url will look like www.app.com/#home,
I dont want to change url, just www.app.com nice and clean, in this case how to defined template for defferent controller and how to load the template in ng-view, and how to pass url parameter?
any idea?
You cannot do that with the built-in routing mechanism because path is required for every route. However, you can use ui-router library in order to create URL-less states and navigate to them using either code or directive.
I created this plunker to demonstrate how to use ui-router to navigate among states without modifying URL.

How to control page get parameter in Yii CListView?

Using Yii 1.1.12. I have a CListView with ajax turned off:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'ajaxUpdate' => false,
)); ?>
The url for the link to the second page looks like:
http://www.example.com/products?Product_page=2
I want the url to look like:
http://www.example.com/products?page=2
How can I achieve this?
(A bonus would be to also describe how to get a url like http://www.example.com/products/page/2)
Update
As pointed out by elbek, I see the CListView has a pager property of type CLinkPager. This in turn has a pages property of type CPagination which has a property pageVar which is described as:
name of the GET variable storing the current page index. Defaults to
'page'.
Sounds like it could be what I'm looking for, not sure how to modify this from the CListView though.
Additionally to change the pageVar you have to modify the $dataProvider. You can do this when you are defining it in the controller action:
$dataProvider=new CActiveDataProvider('Products',array(
'pagination'=>array(
'pageVar'=>'page'
)
));
Alternatively you can of course modify the $dataProvider in the view itself before using it in the CListView : (not recommended-owing to separation of concerns)
$dataProvider->pagination=array('pageVar'=>'page');
$this->widget('zii.widgets.CListView', array(/*rest of your code*/));
But with this change, to make your url look like http://www.example.com/products/page/2 you'll need to slightly change the rule in urlManager from Suvera's answer:
'products/page/<page:\d+>'=>'products/index',
Note: If you don't need that type of url, you don't need the above rule, just specifying the pageVar does it.
enable the urlManager component on your config. And add the following rule at the top.
'urlManager'=>array(
......
'rules'=>array(
'products/page/<Product_page:\d+>'=>'products/index', //Add it in top
...........
...........
),
),
the above rule will create a url something like http://www.example.com/products/page/2
The value part in the rule products/index is products controller and index action (this is important, so point it out to your actual route).
you can even create urls whatever way you want.
ex 1:
'products/<Product_page:\d+>'=>'products/index'
will give you http://www.example.com/products/2
ex 2
'TheAvengers/vs/Loki/<Product_page:\d+>'=>'products/index'
will give you http://www.example.com/TheAvengers/vs/Loki/2
I think CListView has pager attribute(from its parent class)
You can try to set some attributes for this. I think it is CLinkPager instance.

Trying to set the right URL - Struts 2

I have a Struts2 app and I'm having a bit of a problem:
at the first page (index.jsp) I have a javascript line that sets the url to './admin/Search' like this:
window.location='./admin/Search';
that sends me to the login page and if I have access it will redirect me directly to the mentioned page. The problem is that, after that, all my actions keep this first namespace '/admin'. Other actions just do not have this '/admin' namespace, for example, they could have a '/users' namespace. In this cases the server can't locate the right action because it will look for /admin/myAction in the struts.xml file. It's like struts 2 doesn't change the whole namespace/action. It just replaces the action and that's it. I really need help on this guys! Thanks.
You need to change the package namespace specified in the in struts.xml files. That will help you redirect your namespace inside your application.

Resources