0

I'm relearning PHP and codeigniter but i can't help but notice how ugly my url looks.

So i have a pages controller: Say lets load homepage.

It would look like this:

public function home(){ $this->load->view('template/header'); $this->load->view('template/navbar'); $this->load->view('pages/home'); $this->load->view('template/footer'); } 

I guess thats decent as my url will probably look like this: http://localhost/ProjectName/index.php/pages/home

But whenever i click on a link that involves more data processing for example lets say my home has a list of users and i click on one to view their profile. I ofcourse have to pass something to identify which profile i am to load so my link would look like this:

http://localhost/OnlineStories/index.php/pages/view_userprofile/1

In my controller id have:

public function view_userprofile(){ $userid = $this->uri->segment(3); //process data then load view } 

I'm not asking for any advanced stuff but i would like to ask simple things to improve my url like correct standard for naming my controller functions.

For example: on previous instances of loading my homepage my function name was view_home now its simply just home so its cleaner.

Maybe i could rename my view_userprofile to simply user_profile.

Anyway is there any better method to passing values from view to controller other than uri segment? its what ive been using so i never gave it much thought. I've seen some use get() but idk if its better than uri segment?

Or should i stick with the uri segment and keep my url as controller/method/parameter?

I haven't really explored post-project polishing in codeigniter so idk if theres a way to polish/change the url(just the name).

1

1 Answer 1

3

Talk about URL in CodeIgniter, you never mention about application/config/routes.php file. Have you seen it ..?

In routes.php file you can create your URL name and mapping it to the controller/function that you have

like this:

$route['user/update'] = 'user_controller/update_data_function' 

so, you can call URL http://your.site/index.php/user/update to execute your update_data_function() in your User_controller.php

Sign up to request clarification or add additional context in comments.

1 Comment

I've known about it but i never touched it. I did not want to mess up my project since it's still on-going. Can you give me a basic run down on what routes can do to the url? just edit your answer and i'll accept it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.