changes need in url manager in yii - php

I have a url www.xy.de/glossar/anzeigen-programming
I want to use this url as www.xy.de/anzeigen-programming.
Last parameters are a variable. I want to show content after searching from database respect to last parameter.In urlmanager what have to do?

you can update your routes in config file.
Simply add something like this:
'glossar/<page:\w+>' => '/',
more info about routes could be found here

Related

How can I get current URL in Yii 1.x?

I want to got my current page URL using Yii 1.x.
This is my current page:
http://example.com/abc/def
and I want to got full URL or last parameters.
To get the current url you can do this.
Outside view files use this:
Yii::app()->controller->getId()
Yii::app()->controller->getAction()->getId()
Inside view files:
$this->getId()
$this->getAction()->getId()
Or simply:
Yii::app()->request->requestUri

Change URL in CakePHP

I have a Page in Cakephp that looks like
www.example.com/posts/next_posts
i.e. I have app/View/posts/next_posts.ctp
but I have Categories1, Categories2, Categories3,.... in Database.
How do I change the URL so that I assign a Variable of Database and it looks like
www.example.com/categories1/next_posts
www.example.com/categories2/next_posts
www.example.com/categories3/next_posts
By using the router. Read this chapter:
http://book.cakephp.org/3.0/en/development/routing.html
It will map a URL to a controller and action and passes arguments based on the URL. There are examples on that page as well if you're looking for that.

Send parameter to controller in Yii

I am working on admin panel in yii and want to update record so when so i want to send record id on href click so url become
http://localhost/firstapp/backend/vehicle/edit/1
but its not working it gives error as "Unable to resolve the request "backend/vehicle"." I am trying this from long time please help
You can pass variable by get method, like "/site/index?asd=xyz&pqr=qwe" and this can be access by $_GET.
If you want to pass variable in codeigniter style, i.e. by using '/', You can use name parameter in url manager. You can get more info here : http://www.yiiframework.com/doc/guide/1.1/en/topics.url#using-named-parameters
You should provide more information about your question for better help.
However, suppose you have www.example.com/controller/action url. if you want to pass some variable to action, first you need to define a rule in url manager in config/main.php like this:
"controller/action/<variable1>/<variable2>"=>"controller/action"
Now if the url was "controller/action/test1/test2", in your action the value of $_GET['variable1'] will equal to "test1" and $_GET['variable12'] will equal to "test2" .
Note that user-defined url manager rules must be BEFORE the yii default url manager rules.

Yii - how to make url as readable?

I am creating a realestate website, I want my url to be readable,
For example my site url is http://sitename/property/3, (3 represents property id)
I want to change it like this link
My question is how they are using "Residential-Apartment-Flat-in-Park-View-City-Gurgaon-4-BHK-for-Sale-spid-H13544257" this part in url.
Of course they are using id and all. How can I replace "property" with something like "residential-property-in-india" in my url and it should be changing dynamically according to search.
I hope it is clear what I want to do...
Everything is in the Yii guide
For example the folling urls config in the url manager component
array(
'posts'=>'post/list',
'post/<id:\d+>'=>'post/read',
'post/<year:\d{4}>/<title>'=>'post/read',
)
Will generate link like http://example.com/post/2004/My-title-that-can-be-long
You can tweak it to match your need,if I were you I'll read the Yii guide very carfully
At the last of rules array place this rule
'<page>'=>'someControlles/someAction',
And you will get in someControlles/someAction parameter. $page = 'any_text'. Another way to create your own UrlRule.

Remove id and rename action in urls in yii

Is it possible to remove id from url and rename action name?
For example if I write this:
'production' => 'products/index',
it works fine - in url I can see just "production", and is called 'products/index' page.
But if I write
'audits' => '/customPages/1',
Then it gives me
The system is unable to find the requested action "1".
But as far as I understand this 1 is id , and its not an action, its a parameter in action.
How can I get '/customPages/1' page, but in url show something else?
So why do not you just try this
'audits' => 'controller/action/id/1',
Suppose the controller name is SITE and action is Target so you can do this
'audits' => 'site/target/id/1',

Categories