CodeIgniter Forums
want to create a url like http://www.example.com/uername - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: want to create a url like http://www.example.com/uername (/showthread.php?tid=52660)

Pages: 1 2


want to create a url like http://www.example.com/uername - El Forum - 06-21-2012

[eluser]CodeIgniteMe[/eluser]
You also need a controller "user" where the function "profile" belongs
Code:
// User class
class User extends CI_Controller{
// profile function
function profile($id){
// display id value
echo $id;
}
}



want to create a url like http://www.example.com/uername - El Forum - 06-29-2012

[eluser]Rayhan[/eluser]
Here what I have done to my ruote.php

$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("dbname", $con);

$result = mysql_query("SELECT * FROM table_name");

while($row = mysql_fetch_array($result))
{
$sname = $row['user_name'];
$a = $sname;
$b = "user/name/".$row['aid'];
$route[$a] = $b;
}




want to create a url like http://www.example.com/uername - El Forum - 06-29-2012

[eluser]weblyan[/eluser]
routes.php is a settings file and should not contain any code other than assigning variabels.
Besides, if you write code like that then you are not using the framework correctly.
http://ellislab.com/codeigniter/user-guide/database/results.html

Anyway, for the routing, I haven't really tried it but there is a way to set a default controller in the index.php

Code:
/*
* --------------------------------------------------------------------
* DEFAULT CONTROLLER
* --------------------------------------------------------------------
*

Then you can probably use $this->uri->segment(1); the get the username.