2015-02-10 35 views
0

配置私人邮件扩展时出现问题。 这里是保护的的构造/配置/ main.phpYii私人邮件扩展“Method User :: getFullName not defined”

'message'=>array(
'userModel'=>'User', 
      'getNameMethod' => 'getFullName', 
      'getSuggestMethod' => 'getSuggest', 
      'receiverRelation'=> array(
       CActiveRecord::BELONGS_TO, 'User', 'on'=>'User.id = receiver_id' 
      ), 
      'senderRelation'=> array(
       CActiveRecord::BELONGS_TO, 'User', 'on'=>'User.id = sender.id' 
      ), 
     ), 

这是保护的代码/模块/消息/ MessageModule.php

<?php 

class MessageModule extends CWebModule 
{ 
    public $defaultController = 'inbox'; 

    public $userModel = 'User'; 
    public $userModelRelation = null; 
    public $getNameMethod; 
    public $getSuggestMethod; 

    public $senderRelation; 
    public $receiverRelation; 

    public $dateFormat = 'Y-m-d H:i:s'; 

    public $inboxUrl = array("/message/inbox"); 

    public $viewPath = '/message/default'; 

    public function init() 
    { 
     if (!class_exists($this->userModel)) { 
      throw new Exception(MessageModule::t("Class {userModel} not defined", array('{userModel}' => $this->userModel))); 
     } 

     foreach (array('getNameMethod', 'getSuggestMethod') as $methodName) { 
      if (!$this->$methodName) { 
       throw new Exception(MessageModule::t("Property MessageModule::{methodName} not defined", array('{methodName}' => $methodName))); 
      } 

      if (!method_exists($this->userModel, $this->$methodName)) { 
       throw new Exception(MessageModule::t("Method {userModel}::{methodName} not defined", array('{userModel}' => $this->userModel, '{methodName}' => $this->$methodName))); 
      } 
     } 

     // this method is called when the module is being created 
     // you may place code here to customize the module or the application 

     // import the module-level models and components 
     $this->setImport(array(
      'message.models.*', 
      'message.components.*', 
     )); 
    } 

    public function beforeControllerAction($controller, $action) 
    { 
     if (Yii::app()->user->isGuest) { 
      if (Yii::app()->user->loginUrl) { 
       $controller->redirect($controller->createUrl(reset(Yii::app()->user->loginUrl))); 
      } else { 
       $controller->redirect($controller->createUrl('/')); 
      } 
     } else if (parent::beforeControllerAction($controller, $action)) { 
      // this method is called before any module controller action is performed 
      // you may place customized code here 
      return true; 
     } else { 
      return false; 
     } 
    } 

    public static function t($str='',$params=array(),$dic='message') { 
     return Yii::t("MessageModule.".$dic, $str, $params); 
    } 

    public function getCountUnreadedMessages($userId) { 
     return Message::model()->getCountUnreaded($userId); 
    } 

} 

然而,当我尝试运行它,我发现上的问题“Method User :: getFullName not defined”

请帮忙... 谢谢...

+0

可能有些文件不包含在自动加载, – tinybyte 2015-02-10 14:05:05

+0

将'getFullName'方法添加到''用户'模型。 – 2015-02-10 14:12:05

回答

0

哇...问题解决了 感谢PeterM ... 我已经加入法getFullName()和getSuggest上用户模型($ Q)..

public function getFullName() 
{ 
    return $this->username; 
} 

public function getSuggest($q) 
{ 
    $c = new CDbCriteria(); 
    $c->addSearchCondition('username', $q, true); 
    return $this->findAll($c); 
} 

我错误地穿在用户控制器 感谢您的帮助...^_^

+0

我也是Yii的新手。此用户模型位于何处? – Pupil 2015-04-22 13:13:10

+0

In Module Private Message Sir .. – 2015-06-04 08:09:16