• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stop controller at this point, run other method

#1
Lightbulb 
In index of my Main.php controller I have something like this:

PHP Code:
$check $this->Logier->check_address($url);

if( 
$check === )
{
$this->show_page($url);
}
elseif( 
$check === )
{
$this->show_post($url);
}
else
{
show_404();
}

Can't I do something like...

$check = $this->Logier->check_address($url);

[size=small][font=Monaco, Consolas, Courier, monospace]if( $check === 1 )[/font][/size]
[size=small][font=Monaco, Consolas, Courier, monospace]{
[/font][/size][size=small]$this->show_page($url);
break();[/size]
[size=small][font=Monaco, Consolas, Courier, monospace]}[/font][/size]
[size=small][font=Monaco, Consolas, Courier, monospace]if( $check === 2 )[/font][/size]
[size=small][font=Monaco, Consolas, Courier, monospace]{[/font][/size]
[size=small][font=Monaco, Consolas, Courier, monospace]$this->show_post($url);
[/font][/size]break();
[size=small][font=Monaco, Consolas, Courier, monospace]}[/font][/size]
show_404();

I mean, to break at this point I want in just executing this actual method.
So it executes show_post, then output and so on.

Let'
s assume $check === 1
It executes then show_page
($urlmethod.
And 
nothing else in this index method. (So it doesn't check next if and doens't execute last command show_404();) 
Reply

#2
That's pretty much exactly the same as what you had, because you used if/else if/else. Break won't do anything for you, since you're not in a loop. If it makes you happy, use exit or die instead.
Reply

#3
In some cases, switch is a better alternative:
PHP Code:
$check $this->Logier->check_address($url);
switch (
$check) {
 case 

 
   $this->show_page($url);
 
   break;
 case 
:
 
   $this->show_post($url);
 
   break;
 default:
 
   show_404();
 
   die();

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.