Confused about function arguments

i found a PHP breadcrumb script which I would like to use in my Model and pass to the Controller. I am only confused on how to pass the arguments to the Controller. This is the function:

public function breadcrumbs($separator = ' » ', $home = 'Home') {

	$path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
	$base_url = substr($_SERVER['SERVER_PROTOCOL'], 0, strpos($_SERVER['SERVER_PROTOCOL'], '/')) . '://' . $_SERVER['HTTP_HOST'] . '/';
	$breadcrumbs = array("<a href="\"$base_url\"">$home</a>");
	$tmp = array_keys($path);
	$last = end($tmp);
	unset($tmp);

	foreach ($path as $x => $crumb) {
		$title = ucwords(str_replace(array('.php', '_'), array('', ' '), $crumb));
		if ($x == 1){
			$breadcrumbs[] = "<a href="\"$base_url$crumb\"">$title</a>";
		}elseif ($x > 1 && $x < $last){
			$tmp = " for($i = 1; $i <= $x; $i++){ $tmp .= $path[$i] . '/'; } $tmp .= "\">$title";
			$breadcrumbs[] = $tmp;
			unset($tmp);
		}else{
			$breadcrumbs[] = "$title";
		}
	}
	return implode($separator, $breadcrumbs);
}

Normally I would call the function in the Controller like this:

$breadcrumbs   = $this->model->get_breadcrumbs(.......);

But I have no idea how to pass the arguments in this case. All help would be highly appreciated. Thank you in advance

Where does get_breadcrumbs() come into it? Is that another function that you want to call, or a typo? As for passing the arguments, can you expand on what the issue is, why you wouldn’t just put them in the brackets when you call the function? I think I’m not understanding the question properly.

This will fail. The concatenations are incorrect. There is no periods to separate the variables. If you are going to use double quotes, you might as well just not concatenate the variables because you can already execute the variable and not the literal variable itself. I just dont understand why most people concatenate variables when they use double quotes. Isn’t that the purpose of using double quotes?

$variable = array("$variable");

Will execute and output exactly the same thing as

$variable = array($variable);

With the first one, you’re just wasting time and bytes of resource to do exactly the same thing as the second one.

I also don’t understand why people do this as well

$variable = "" . $variable . "";

This makes no sense whatsoever. It’s just wasting time and bytes of resource. If you aren’t going to put something before or after the variable, there is no reason to have quotes around the variable.

That was a typo. It should be

$this->model->breadcrumbs(.......);

Do you mean that I could use the same arguments in the controller as I used in the Model like

$breadcrumbs   = $this->model->breadcrumbs($separator, $breadcrumbs);

Yes, that’s what I meant. I have no experience of the MVC structure (unless I have, but don’t know that I have) so I was struggling to understand why passing parameters would be any different than passing them to a “normal” function.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.