开发者

Is there too much code in my view? CakePHP / MVC design pattern

I am using google maps cakePHP helper by dereuromark to show a map in my view. The map also has markers, and each marker has its own associated listener that makes an ajax call.

The map is being rendered perfectly and everything works as expected. However, I am not sure if all this code be separated from my view? I am new to MVC architecture...

<h1>Render map</h1>
<?php

// returns true if user logged in
if (!$session->check('Auth.User.id')){
    echo $this->Html->link('Log in',array('controller'=>'users', 'action' => 'login'));
} else 
{   
    echo "Hello " . $session->read('Auth.User.username') . "... ";
    echo $this->Html->link('Log out',array('controller'=>'users', 'action' => 'logout'));
}
echo $this->GoogleMapV3->map(array('map' => array('lat' => '44.230065', 'lng' => '-76.5000', 'zoom' => 14), 'div'=>array('id'=>'my_map3', 'height' => '400px', 'width' => '786px')));

foreach ($posts as $post) {
    $options = array(
        'lat' => $post['Post']['lat'],
        'lng' => $post['Post']['lng'],
    );

    $marker = $this->GoogleMapV3->addMarker($options);
    $script = "$.ajax({
                          url: \"show_post.php?q=\"+{$post['Post']['id']},
                          success: function(html){
           开发者_Go百科                 $(\"#results\").html(html);
                          }
                        });";
    $this->GoogleMapV3->addCustomEvent($marker,$script);

}

echo $this->GoogleMapV3->script();

?>

If you could also point out any design flaws that would be great. Thanks


looks fine, as long as you dont do any model calls or to much business logic in the views you are good. you could stick the greeting in an element and just call $this->element('greeting'); at the top instead of the if

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜