Yii - how to make url as readable? - php

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.

Related

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.

typo3 - realurl by id

I'm using typo3 and realurl.
In my extension I generate some ID's (next and previous page) and everything works fine up to this point. An example link looks like:
/index.php?id=12
The link takes the visitor to the specific page, but this link is in the url as well. Of course I generate this linke exactly like this:
$GLOBALS['TSFE']->baseURL . "index.php?id=" . $banner->getPrevious();
So, it is exactly what i expected. But how can i turn this url into a seo-friendly URL?
Is there something like $realUrl->createUrlFromId()? :P
I checked the manual, looked in some forums, but 99% of the time it is something related to TypoScript, which I don't need (from my point of view) in this case.
Edit:
Here is the .htaccess:
http://pastebin.com/DBXjLYjp
Thank you in advance
RealURL hooks into several core methods to generate links, and manipulates the result to be a speaking URL. So, no, it does not offer an own method, but extends existing ones.
You don't use a link generation, but build it by yourself. RealURL therefore can not access your link.
The htaccess only converts speaking urls back into GET-params.
Use a method like pi_linkToPage, a link viewhelper, or a TypoScript typolink to generate a link.
$myLink1 = $this->pi_linkToPage('example', 42);
$myLink2 = $this->cObj->typolink('example', array(
'parameter' => 42,
));

changes need in url manager in yii

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

Finding path name to use as a slug for custom built cms with PHP

I'm building a website with a custom content management system, and I want to build a slug area like wordpress. I want to retrieve the path name from my front-end depending on the page they're on, and echo that out in my backend in the slug area.
I'm using php and my front-end is dynamic, which means I have one page, and depending on what the user clicks on, I will include that file.
What I want the code to look like for the slug in the backend:
<?php
//front end path/ echo $slug;
?>
My front-end path looks something like this: blahblah/index.php/slug-name
I have a slug stored in the database that I will echo out, but my problem is I don't know how to retrieve the front end path and echo it out in the backend. I realize I can type the front-end path manually, but I think doing it dynamically would be better incase I move my website to a different location in the future.
I've tried using pathinfo or $_SERVER but that echos out my backend path rather than my front end.
Hopefully I was clear, if not, ask me to clarify something. Thanks again.
You need the rewrite module for apache or nginx.
That allows you to do like this:
PrettyPath(This will be seen to all visitors): http://blah.com/blah/bl/ah/test
=> RealPath(This can be used for develop): http://blah.com/blah/index.php?slug=bl/ah/test
You can do beautiful job like this for using rewrite module. (Rewrite Example)
$front_end_path = 'your/site/path';
$full_url = $front_end_path . $slug;

Categories