Passing variables from controller to views

I'm using kohana 3.3 together with kostache. Ok how do you pass a variable from controller to class views and use it on a mustache file?..

Here's my code.

Controller:

public function action_update()
{
    $layout = Kostache_Layout::factory();

    $content = new View_Pages_Album_Update();

    $album = ORM::factory('Album_Information', $this->request->post('id'));

    $content->albumName = $album->Album_Name;

    $content->albumArtist = $album->Artist;

    $this->response->body($layout->render($content));
}

Views

class View_Pages_Album_Update {

    public $title = 'Update Music';

    public function album_edit()
    {
        return array(
                    array('albumName' => $this->albumName),
                    array('albumArtist' => $this->albumArtist),
        );
    }
}

Template

<label>Album Name:</label>

<input type="text" name="inputAlbumName" value="{{albumName}}" /><br />

<label>Artist:</label>
<input type="text" name="inputArtist" value="{{albumArtist}}" /><br />

When I run my code nothing is passed to the template file. So how do you pass it from controller => views => template?

Answers


You are setting values on the Kostache_Layout object. I believe you must set those on the View_Pages_Album_Update instead:

Controller:

public function action_update()
{
    $layout = Kostache_Layout::factory();
    $content = new View_Pages_Album_Update();

    $album = ORM::factory('Album_Information', $this->request->param('id'));

    $content->albumName = $album->Album_Name;
    $content->albumArtist = $album->Artist;

    $this->response->body($layout->render($content));
}

I don't think you need a album_edit() method for the template you showed, but if you think you do, then use this.

View:

class View_Pages_Album_Update {

public $title = 'Update Music';

public function album_edit()
{
    return array(
                array('albumName' => $this->albumName), // missing $this
                array('albumArtist' => $this->albumArtist), // missing $this
    );
}

}


Need Your Help

Starting Eclipse w/ Specific Workspace

eclipse zend-studio eclipse-pdt

Is there a way to start an instance of eclipse, passing it some sort of parameter telling it to use a specific workspace?