Welcome Guest, Not a member yet? Register   Sign In
Lovely User URLS (http://domain.net/~Username)
#21

[eluser]Iverson[/eluser]
[quote author="Phil Sturgeon" date="1232716880"]I dare you to try that one with a client Michael;. They often want the first URI segment to be the username to be like MySpace, etc and so you will eventually find yourself coding this feature wether you want to or not.[/quote]

Couldn't have said it better myself
#22

[eluser]xwero[/eluser]
If the OP wants to use a tilde it can be routed
Code:
$route['~[\w\d]+(.+)'] = '$1';
$route['~[\w\d]+'] = 'users/profile';
#23

[eluser]Michael;[/eluser]
[quote author="Iverson" date="1238352324"][quote author="Phil Sturgeon" date="1232716880"]I dare you to try that one with a client Michael;. They often want the first URI segment to be the username to be like MySpace, etc and so you will eventually find yourself coding this feature wether you want to or not.[/quote]

Couldn't have said it better myself[/quote]

And yet, here we are a month and a dozen projects later and still not had a problem with this one. Why is this horse still being beaten?
#24

[eluser]Iverson[/eluser]
[quote author="Michael;" date="1238363137"]
And yet, here we are a month and a dozen projects later and still not had a problem with this one. Why is this horse still being beaten?[/quote]

A) Just because one person hasn't encountered this situation doesn't mean you speak for the majority.

B) Most of the most popular threads around here are older threads that people have searched for

C) We're simply saying that this is a big need-to-know because to offer someone a feature like this can potentially gain or lose a client. Don't be such a girl about it. And to answer your question, it's still being beaten because it's not dead yet. :coolmad:
#25

[eluser]Iverson[/eluser]
[quote author="Dyllon" date="1232421660"]I had to do this a while ago, I didn't want to use URL suffixes so I extended the CI Router as follows

application/libraries/My_Router.php
Code:
class MY_Router extends CI_Router {

    function MY_Router()
    {
        parent::CI_Router();
    }

    function _validate_request($segments)
    {
        // Does the requested controller NOT exist?
        if (!file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            $segments = array("users","profile",$segments[0]);
            
        }
    }
    return parent::_validate_request($segments);
}
[/quote]

In other news, I don't see how this actually worked. You can't have a return outside a function in a class.... :bug:

For anyone looking to cut and paste, you'll have to move return parent::_validate_request($segments); inside of _validate_request()
#26

[eluser]Phil Sturgeon[/eluser]
I remembered why I didn't use the router method for this!

I use this router method to send people off to a snazzy 404 page instead. I could of course add in a username checker into the router class but that is not a nice way to do things.

And yea Michael, you said it yourself "I do not do very much with “social” type sites.". So it's not an issue for you to worry about is it.
#27

[eluser]breastfed[/eluser]
Hello

i just tried that Stuff - but it doesn't work on my Project.

I have the following code:
Code:
<?php
class MY_Router extends CI_Router {

    function MY_Router()
    {
        parent::CI_Router();
    }

    function _validate_request($segments)
    {
        // Does the requested controller NOT exist?
        if (!file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            $segments = array("profile","user",'breastfed');
            
        }
    return parent::_validate_request($segments);

    }
}
?>

Stored in application/libaries/My_Route.php

The $segment was changed to my Layout so .com/profile/use/breastfed/ is working but not with .com/breastfed/

What might be wrong?
#28

[eluser]Référencement Google[/eluser]
Stored in application/libaries/My_Route.php ? Shouldn't it be application/libaries/My_Router.php (router, not route)
#29

[eluser]breastfed[/eluser]
Sorry it is My_Router.php - but still not working.
#30

[eluser]calumogg[/eluser]
Hi everyone I have tried using the code posted but cant get it working. Here is the code I am using (I have only changed the $segments array and moved
Code:
return parent::_validate_request($segments);
)

Code:
<?php

class MY_Router extends CI_Router {

    function MY_Router()
    {
        parent::CI_Router();
    }

    function _validate_request($segments)
    {
        // Does the requested controller NOT exist?
        if (!file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            $segments = array("user","about",$segments[0]);
            
        }
        
        return parent::_validate_request($segments);
        
    }
    
}

?>

Then here is my user controller:
Code:
<?php

class User extends Controller {

  function about(){

  $this->load->view('user', $segments);

  }

}

?>

And finally my view code:
Code:
<html>
<head>
<title>Users</title>

</head>
<body>

<h1>Users</h1>

<p>&lt;?php echo $segments; ?&gt;</p>

<p><br />Page rendered in {elapsed_time} seconds</p>

&lt;/body&gt;
&lt;/html&gt;

I am very new to codeigniter and havent been able to get this working it just keeps telling me $segments is undefined. Please can someone show my how to pass the username as $segments from the routing page. I am testing the script on Wamp server apache v 2.2.11 PHP 5.2.9-2
Thanks in advnace




Theme © iAndrew 2016 - Forum software by © MyBB