On my home page I’m displaying a random item. For example:
My controller looks like:
class SiteController extends Controller
{
public function filters()
{
$cacheDurationInSeconds = 604800; // seconds in a week
return array(
array(
'COutputCache + index',
'requestTypes' => array('GET'),
'duration'=> $cacheDurationInSeconds,
'dependency'=>array(
'class'=>'system.caching.dependencies.CDbCacheDependency',
'sql'=>'SELECT AVG(modified) FROM post',
),
),
);
}
public function actionIndex()
{
$randomPost = Post::model()->find(array('order' => new CDbExpression('RAND()')));
$this->render('index', array( 'randomPost' => $randomPost));
}
...
In my index.php view:
<h3>Random Post:</h3>
<?php $this->renderDynamic('renderPartial', '/post/_view', array('data' => $randomPost), true); ?>
And the partial view:
<div class="view">
<div class="post-index-item">
<div class="title"><?php echo CHtml::link(CHtml::encode($data->title), array('post/view', 'slug'=>$data->slug)); ?></div>
<div class="date">Date: <?php echo CHtml::encode($data->date); ?></div>
</div>
</div>
If I comment out the filter method in the SiteController everything works fine (of course the caching is not implemented though), but with the filter method in place I get the following error:
Error 500
include(SluggableBehavior.php): failed to open stream: No such file or directory
(Yes the post model does use the SluggableBehavior extension.)
Why is this happening and how can I fix it?