yii - A special application state issue -
i developing facebook social networking website using yii framework. logged in user can see profile of user got while searching or other means. in facebook happens like
facebook.com/marthajoseph/photos here user viewing profile of "marthajoseph". same thing want accomplish in yii. did this
myapplication.com/index.php?r=u/default/index?uid=110 here "u" model users. here viewing profile of user user id "110". issue each time switch user's photos, profile, posts etc have append uid query string url leads instability.
how can accomplish facebook thing?
i suggest rewriting url using yii url management mentioned ernie above
first of all, utilize path format url. done firstly un-commenting urlmanager lines in protected/config/main.php (around line 34 default). allow utilize "pretty urls", example, instead of url looking this:
www.example.com/index.php?r=user/profile?uid=110 you can have this:
www.example.com/user/110 so, example, if wanted route url has construction profile/<a users id> our user controllers view action (actionview), like:
'urlmanager'=>array( 'urlformat' => 'path', 'showscriptname' => false, 'rules' => array( 'user/profile/<id:.+>' => 'user/view', ... so on left side of array have "what url like", , on right have "where pointing". can access id value in view or in controller using $_get, example:
echo "you viewing user id ".$_get['id']; you utilize value query photos or profile content or whatever associated user. in terms of having users name in url (how facebook it, eg: facebook.com/myusername), allow user come in vanity url somewhere along line , store in database. alter rule like:
'user/profile/<user_vanity_url:.+>' => 'user/view', and access value same above using $_get. 1 piece of advice if go route maintain in mind should preventing users making beingness able view content not allowed view, example, viewing photos of not friend. assume have sort of table storing these relations?
in regards having append id or whatever value passing through url, can append in view or wherever html beingness created, illustration if want display link users photos profile page like:
<a href="<?php echo yii::app()->request->baseurl; ?>/photos/<?php echo $_get['id']; ?>"></a> one other thing regarding url rules in urlmanager, rules interpreted top bottom, , first matched rule used.
hopefully helps on right path. check out next posts if still stuck:
http://yiitutorials.net/easy/easy-url-rewriting-with-yii yii basic url rewrite yii
No comments:
Post a Comment