2011-03-10 59 views
2

我正在使用google maps cakePHP helper dereuromark在我看來顯示地圖。該地圖也有標記,並且每個標記都有自己的關聯偵聽器,可以進行ajax調用。我認爲代碼太多了嗎? CakePHP/MVC設計模式

地圖渲染完美,一切正常。但是,我不確定這些代碼是否與我的觀點分離?我是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(); 

?> 

如果你還可以指出任何設計上的缺陷,那就太棒了。由於

+1

應該被移到http://codereview.stackexchange.com – jcubic 2011-03-10 21:02:31

+0

它看起來好像沒什麼問題,但作爲jcubic說,它不屬於這裏。然後再次,它看起來像你會是codereview上唯一的cakephp提交。孤獨的地方。 – Leo 2011-03-11 11:04:44

回答

1

看起來不錯,只要你不這樣做你是很好的意見的任何模型調用或以多業務邏輯。你可以將問候語粘貼在一個元素中,只需調用$ this-> element('greeting');在頂部,而不是如果