Femme Fatale
Femme Fatale

Reputation: 880

Yii - linking to static page of a given model id

Each model id has a corresponding static page e.g id = 1 of my table has a static page in my views as 1.php. So when i click the link button (implemented in ClistView) it respective static page should be displayed.
How can i implement this functionality?

<?php
        echo CHtml::link('View Detail', array('$data->id.php'),

          // i want 1.php to be displayed for $data->id =1 and 2.php for $data->id= 2

            array('id'=>'mylink','class'=>'btnPrint btn btn-danger',
                'target'=>'_blank',
            ));
        ?>

Upvotes: 0

Views: 43

Answers (1)

JonathanStevens
JonathanStevens

Reputation: 472

<?php
echo CHtml::link(
    'View Detail',
    $this->createUrl('site/static', array('id' => $data->id)),
    array(
        'id' => 'mylink',
        'class' => 'btnPrint btn btn-danger',
        'target' => '_blank',
    )
);

And in your controller you can create an action as follows:

public function actionStatic($id)
{
    $this->render($id);
}

Upvotes: 1

Related Questions