Hi,

I have a posts table and a postvideos table. Posts can have a main
video but can also have many videos. In my view I want to display a
video icon next to the post title when a post has a main or many
videos.

so at the moment I have a function at the controller that checks
whether a post has a main or many videos and returns a video image
icon, which I display in my view with requestAction. However I have a
strong feeling that this is a wrong way of doing things and it breaks
MVC. What is the recommended approach for something like this?

Controller:

function hasvideo($id) {
        App::import('Helper', 'Html');
        $html = new HtmlHelper();
        $post = $this->Post->findById($id);
        $videos = count($post['Postvideo']); if($post['Post']
['main_video'] && $post['Post']['media'] == 1) $hasmainvideo = 1; else
$hasmainvideo = 0;
        if($videos > 0 || $hasmainvideo == 1) return $html-
>image('themed/kretaworldbasket/video.png', array('title' => 'Post has
video', 'width' => 16, 'height' => 8, 'style' => 'margin-left:
5px;'));
}

View:
<?php echo $this->requestAction('/posts/hasvideo/'.$editorpick['Post']
['id']); ?>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to