user147
user147

Reputation: 1310

CakePHP default layout, can't pass values to default.ctp

I have one page website, on homepage(Layout/default.ctp) I have 2 forms, subscribe and contact form that are being controlled over contact controller. With $this->set('some_val', 'test'); I can set value from AppController, but not from contact controller, how can I set values from contact controller to be available in default.ctp except with sessions?

public function beforeFilter() {
    parent::beforeFilter();
    //pr('beforeFilter'); // i was testing is this happening or not
    //exit();
    $tester = 'test';
    $this->set(compact('tester'));
}

and in default.ctp I just pr($this->viewVars); to make sure that I have tester value, but it is always empty.

Is this right approach how to implement several controllers in one page design?

Another question is there a place/function where I could check is current request post or not, I would like to check for each request what is it?

Thank you.

Upvotes: 0

Views: 1415

Answers (2)

Ari McBrown
Ari McBrown

Reputation: 1106

Not sure if I understand correctly, but it sounds like you might need multiple layouts:

class CarsController extends AppController
{
  public function index($page)
  {
    /* Your logic */

    if ( $page == 'other' ) {
      $this->render('view', 'layout');
    } else {
      $this->render('view-other', 'layout-other');
    }
  }
}

For more information i'd suggest looking at: http://api20.cakephp.org/class/controller#method-Controllerrender

Upvotes: 1

Colby Guyer
Colby Guyer

Reputation: 594

try an echo $tester; in your default, it should be available.

If the request is post, you would have data in $this->data.

Upvotes: 0

Related Questions