Welcome Guest, Not a member yet? Register   Sign In
Comparison operator in CI
#1

[eluser]überfuzz[/eluser]
I'm trying to use a comparison operator instead of a if-statement. But I'm getting an error, I think it's a php-error. This is the code:
Code:
$page = (!isset($this->uri->segment(1)) ? 'home' : $this->uri->segment(1);
The error-message:
Quote:Fatal error: Can't use method return value in write context in /home/minister/public_html/application/views/all/menu.php on line 7
Is it a CI error, I seem to recall that I've been using this way of assigning values before. But now..?
#2

[eluser]frenzal[/eluser]
it's a function, when a segment doesn't exist it returns false.
#3

[eluser]cahva[/eluser]
Its not CI issue. You cant check if function is set. If statement would give you the same error.

$this->uri->segment(1) will return false if its empty so use that to compare:
Code:
$page = $this->uri->segment(1) ? $this->uri->segment(1) : 'home';
#4

[eluser]überfuzz[/eluser]
[quote author="cahva" date="1254097931"]Its not CI issue. You cant check if function is set. If statement would give you the same error.

$this->uri->segment(1) will return false if its empty so use that to compare:
Code:
$page = $this->uri->segment(1) ? $this->uri->segment(1) : 'home';
[/quote]

If admin would be so kind and move this thread to the noob-error section. :red:




Theme © iAndrew 2016 - Forum software by © MyBB