在我看来,代码太多了吗?CakePHP/MVC设计模式

在我看来,代码太多了吗?CakePHP/MVC设计模式,php,jquery,ajax,model-view-controller,cakephp,Php,Jquery,Ajax,Model View Controller,Cakephp,我正在使用by dereuromark在我的视图中显示地图。映射也有标记,每个标记都有自己的关联侦听器,用于进行ajax调用 地图被完美地渲染,一切正常。但是,我不确定是否所有这些代码都与我的视图分离?我是MVC架构的新手 <h1>Render map</h1> <?php // returns true if user logged in if (!$session->check('Auth.User.id')){ echo $this->H

我正在使用by dereuromark在我的视图中显示地图。映射也有标记,每个标记都有自己的关联侦听器,用于进行ajax调用

地图被完美地渲染,一切正常。但是,我不确定是否所有这些代码都与我的视图分离?我是MVC架构的新手

<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){
                            $(\"#results\").html(html);
                          }
                        });";
    $this->GoogleMapV3->addCustomEvent($marker,$script);

}

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

?>
渲染贴图

看起来不错,只要您不进行任何模型调用或在视图中使用太多的业务逻辑,您就很好。您可以将问候语粘贴到元素中,只需调用$this->element('greeting');在顶部,而不是if

应该移动到它看起来不错,但正如jcubic所说,它不属于这里。然后,看起来您将是codereview上唯一提交的cakephp。孤独的地方。