2013-12-18 6 views
1

yii에 간단한받은 편지함을 구현하고 싶습니다. 그것은 데이터베이스 테이블에서 메시지를 읽고 그것을 보여줍니다.yii에 알림이있는 간단한받은 편지함을 구현하십시오.

하지만 다른 스타일의 읽지 않은 메시지와 읽지 않은 메시지를 어떻게 표시해야하는지, 새 메시지에 대한 알림을 구현할 수있는 방법을 모르겠습니다.

나는 많은 검색을했지만 확장 기능을 발견했기 때문에 사용하고 싶지 않습니다.

내가 어떤 초기 아이디어는 사서함 확장 코드의 일부 나에게 도움이 될

다른 방법으로 읽지 않은 메시지를 표시하는 방법을 찾기 위해 너무 중요하다 : 모든 스크립트의

public function actionInbox($ajax=null) 
{ 
    $this->module->registerConfig($this->getAction()->getId()); 
    $cs =& $this->module->getClientScript(); 
    $cs->registerScriptFile($this->module->getAssetsUrl().'/js/mailbox.js',CClientScript::POS_END); 
    //$js = '$("#mailbox-list").yiiMailboxList('.$this->module->getOptions().');console.log(1)'; 

    //$cs->registerScript('mailbox-js',$js,CClientScript::POS_READY); 


    if(isset($_POST['convs'])) 
    { 
     $this->buttonAction('inbox'); 
    } 
    $dataProvider = new CActiveDataProvider(Mailbox::model()->inbox($this->module->getUserId())); 
    if(isset($ajax)) 
     $this->renderPartial('_mailbox',array('dataProvider'=>$dataProvider)); 
    else{ 
     if(!isset($_GET['Mailbox_sort'])) 
      $_GET['Mailbox_sort'] = 'modified.desc'; 

     $this->render('mailbox',array('dataProvider'=>$dataProvider)); 
    } 
} 
+0

어떻게 보입니까? 데이터베이스는 어떻게 생겼습니까? 만약 당신이 데이터베이스를 읽었을 때 읽었을 때를 알고 있다면,보기에서 단순히 if ($ model-> read) {// 색상 변경} else {// 색깔 변경 안함} 또는 그런 식으로? – Jeroen

+0

내 데이터베이스는 메시지를 읽었을 때 보낸 사람 ID와 수신자 ID, 제목, 메시지 텍스트 및 읽음/읽지 않음 필드를 저장하는이 테이블의 messages.in 테이블을 가지고 있습니다. 읽지 않은 메시지를 다른 방법으로 표시하려면 어떻게해야합니까? 그리고 읽지 않은 메시지가 컨트롤러에서 읽은 메시지가되는 방법은 무엇입니까? 나는 아직 어떤 전망도 가지고 있지 않다. – user3019375

+0

대답을 추가했다. 원래의 질문과 "읽지 않은 메시지가 컨트롤러에서 읽은 메시지가되는 방식"에 대한 질문. 그러나 나는 컨트롤러에서 그렇게하지 않는다. 컨트롤러 (데이터베이스 의미)에서 이렇게하려면 데이터베이스에서 메시지를 가져 오는 동안 읽기를 1로 간단히 업데이트하면됩니다. – Jeroen

답변

0

우선 사물이 시야에 있어야합니다. 당신 문제를 들어 나는 단순히 그래서 지금은 모든 메시지를 읽을 클래스를 추가합니다이

<?php foreach($mailbox->messages as $message): 
    $class = ''; //order unread if you want to give both a different class name 
    if($message->read): //if this is true 
      $class = 'read'; 
    endif; ?> 
    <div id='<?= $message->id ?>'class='message $class'> <!-- insert whatever info from the message --></div> 
<?php endforeach; ?> 

과 같이 할 것이다보기에서 컨트롤러

$mailbox = Mailbox::model()->inbox($this->module->getUserId()); //I assume this returns the mailbox from that user? 

$this->renderPartial('_mailbox',compact('mailbox ')); //compact is the same as array('mailbox'=>$mailbox) so use whatever you prefer. 

에서

과 같이 할 것 읽었습니다. CSS에서는 스타일을 간단하게 변경할 수 있습니다. 이것이 충분한 정보가되기를 바랍니다. 나는 foreach()를 사용한다 : endforeach; 및 if() : endif; 뷰 파일에서 foreach() {}를 사용할 수는 있지만 foreach를 선호합니다. HTML과 더 잘 결합되어 있기 때문입니다.

두 번째 질문에 대해서는 EDIT가 어떻게 읽히게 되나요? Jquery와 함께 할 수 있습니다. 예.

$(".message").on("click", function() { 
    var id = $(this).attr('id'); 
    $.ajax { 
     type:"POST", 
     url: "controller/action/"+id; //the controller action that fetches the message, the Id is the action variable (ex: public function actionGetMessage($id) {}) 
     completed: function(data) { 
      //data = the message information, you might do type: 'JSON' instead. Use it however you want it. 
      if(!$(this).hasClass("read")) 
       $(this).addClass("read"); //give it the class read if it does not have it already 
     } 
    } 
}); 

이것은 단순히 클래스 읽기를 제공하고 클래스 읽기와 함께 다른 항목처럼 보입니다.