views:

14

answers:

1

i want to render one of these sets of views:

  1. head
  2. body-$id1
  3. foot

OR

  1. head
  2. body-$id2
  3. foot

which set exsists.

i do it like this:

try {
    $this->render("head");
    $this->render("body-$id1");
    $this->render("foot");
} catch (Exception $e) {
    $this->render("head");
    $this->render("body-$id2");
    $this->render("foot");  
}

but it causes the head view be rendered twice if body-$id1 does not exists.

do you have a better solution?

in another saying, may i check the existance of body-$id1 before rendering it?

A: 

Well, it'll run any valid script in the "try" block, but if it fails, it'll render all the content in the "catch" block. So you probably want something more like:

$this->render("head");
try {
    $this->render("body-$id1");
} catch (Exception $e) {
    $this->render("body-$id2");
}
$this->render("foot");

I don't see an API method to check if a view exists, but you could write a controller helper that just gets the path to your view scripts and uses file_exists to check if "body-{$id1}" exists in that path.

Typeoneerror