CodeIgniter Forums
Change url help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Change url help (/thread-29991.html)

Pages: 1 2


Change url help - El Forum - 04-28-2010

[eluser]TechCadre[/eluser]
I recently picked up a client and the client wants the url changed and I need help with doing this.

If my site was called

http://www.site.com/about_us/

but now i want it to say

http://www.site.com/customers/

Any help?


Change url help - El Forum - 04-28-2010

[eluser]steelaz[/eluser]
Nevermind, it's late... and I'm drinking....


Change url help - El Forum - 04-28-2010

[eluser]WanWizard[/eluser]
Assuming that this site would be a standard CodeIgniter site, there should be a controller called 'about_us' in the application controllers directory.
Renaming it, and modifying the class and constructor name in it should be enough to make your client happy...


Change url help - El Forum - 04-28-2010

[eluser]TechCadre[/eluser]
This is what is under the about_us.php in controllers

Code:
<?php
class About_us extends Controller {

    function About_us()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $data['section'] = "AboutUs";
        $data['title'] = "About Us";
        $this->load->view('inc/begin', $data);
        $this->load->view('about', $data);
        $this->load->view('inc/end', $data);
    }
}
?>

What should I change?


Change url help - El Forum - 04-28-2010

[eluser]steelaz[/eluser]
Try

Code:
<?php
class Customers extends Controller {

    function Customers()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $data['section'] = "AboutUs";
        $data['title'] = "Customers";
        $this->load->view('inc/begin', $data);
        $this->load->view('about', $data);
        $this->load->view('inc/end', $data);
    }
}
?>

Not sure about $data['section'] = "AboutUs"; it may be used internally somewhere.


Change url help - El Forum - 05-04-2010

[eluser]TechCadre[/eluser]
So far this has not worked... anything I could do?


Change url help - El Forum - 05-04-2010

[eluser]theprodigy[/eluser]
you may need to change the link in the views. If it points to About_us, you need to change it to point to Customers (as well as changing the name and constructor of the class). It's also worth a look at the config/routes.php file to see what the default controller is set to.


Change url help - El Forum - 05-04-2010

[eluser]erik.brannstrom[/eluser]
Renaming is probably the best alternative for a small application, though theprodigy mentions the config/routes.php file. How about just adding $route['customers'] = "about_us"; to that file? It's just another option, which also should do the trick.


Change url help - El Forum - 05-04-2010

[eluser]TechCadre[/eluser]
[quote author="theprodigy" date="1273025231"]you may need to change the link in the views. If it points to About_us, you need to change it to point to Customers (as well as changing the name and constructor of the class). It's also worth a look at the config/routes.php file to see what the default controller is set to.[/quote]

I tried the config/routes.php thing but it did nothing.

As I am new to this can you explain to me what you mean by "changing name and constructor of the class"?


Change url help - El Forum - 05-04-2010

[eluser]theprodigy[/eluser]
[quote author="TechCadre" date="1273027266"][quote author="theprodigy" date="1273025231"]you may need to change the link in the views. If it points to About_us, you need to change it to point to Customers (as well as changing the name and constructor of the class). It's also worth a look at the config/routes.php file to see what the default controller is set to.[/quote]

I tried the config/routes.php thing but it did nothing.

As I am new to this can you explain to me what you mean by "changing name and constructor of the class"?[/quote]

What I meant was what was explained up above (by steelaz). Your controller needs to change from
Code:
<?php
class About_us extends Controller {

    function About_us()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $data['section'] = "AboutUs";
        $data['title'] = "About Us";
        $this->load->view('inc/begin', $data);
        $this->load->view('about', $data);
        $this->load->view('inc/end', $data);
    }
}
?>
to
Code:
<?php
class Customers extends Controller {

    function Customers()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $data['section'] = "AboutUs";
        $data['title'] = "Customers";
        $this->load->view('inc/begin', $data);
        $this->load->view('about', $data);
        $this->load->view('inc/end', $data);
    }
}
?>

Notice your class name and constructor are changed from About_us to Customers.

Also, the first part I was talking about was the links that point you to the page in question. If they are linking to (using your example) http://www.site.com/about_us/ then they need to change to http://www.site.com/customers/.

The links may be in the form of
Code:
echo anchor('about_us');
//or
<a href="&lt;?php echo site_url('about_us'); ?&gt;">Link Text</a> //I believe I have that right, I may be wrong (I don't use this style)
which would need to be changed to
Code:
echo anchor('customers');
//or
<a href="&lt;?php echo site_url('customers'); ?&gt;">Link Text</a> //I believe I have that right, I may be wrong (I don't use this style)

If you go with this change, there should be no reason to alter config/routes.php unless the default_controller is set to about_us