Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use Controller Argument or uri->segment?

Should use Controller Argument

function view($post_id) {
    ...
}

or uri->segment

function view() {
    ...
    $post_id = $this->uri->segment(3);
    ...
}

Just for simple blog post ID. Is there a difference?

like image 291
Kubol Avatar asked Jan 31 '13 12:01

Kubol


People also ask

What is this -> Uri -> segment?

$this->uri->segment(n) Segment function allow you to retrieve a specific segment form URI string where n is a segment number. Segments are numbered from left to right. For example,if your URI like. By the above example URI segment function give result by n parameter.

What is the use of URI segment in codeigniter?

The URI Class provides methods that help you retrieve information from your URI strings. If you use URI routing, you can also retrieve information about the re-routed segments. This class is initialized automatically by the system so there is no need to do it manually.

How do I get Uri segment?

Get URI Segments in PHP Use the following code to get URL segments of the current URL. It returns all the segments of the current URL as an array. $uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));


1 Answers

I would use the controller argument.

Then if you ever had to move the code and put it in a sub-directory it would still work, where as the segment method would not.

like image 109
Rooneyl Avatar answered Oct 15 '22 06:10

Rooneyl