Set() not working on subfolder view

Hi there.

I am new in cakePHP. I make a controller AbcContoller and for controller I create its view AbcController. Now in AbcController there are several tasks e.g.

  1. Events add
  2. Products add

And that’s why I create sub folders e.g.

  1. Events
  2. Products

I make events method in AbcController and get data form DB and when I set this data to subfolder view, it gives me this error

[Notice (8)] Undefined variable: AbcEvents [ APP\View\Abc\Events\evetns.ctp

I also add router in my routes.php
Router::connect('/Abc/Events/Listing/', array('controller' => 'Abc', 'action' => 'events'));

My controller Code:
`public function events() {
$this->login_check();

    // Render from sub folder
    $this->render('Events/events');

    $abc_events = $this->AbcEvents->find('first',
        array('order' => array('AbcEvents.id DESC')));

// echo “

”;
// print_r($abc_events);
// echo “
”;

    $this->set('AbcEvents', $abc_events);

}`

When I print data in controller it gives me correct data but not in view.

My view Code Views/Abc/events/events.ctp:
<?php echo "<pre>"; print_r($AbcEvents); echo "</pre>";

It gives me undefined variable error.

How can I get data in view of a sub folder.

Hope you understand my question.

You have asked it to render the view before you set the data. The call to render should be the last thing in your function.

1 Like

thanx alot brother … I just move Render and paste after Set

Like
$this->set(‘AbcEvents’, $abc_events);
$this->render(‘Events/events’);

and it is fixed