0

我在 yii 中使用第三方插件,它提供聊天功能,它有自己的数据库和 php 文件来提供功能,

现在我想在视图中使用它,但是简单的包含语句不起作用,我需要将它转换为 yii 还是可以按原样使用它?

<?php

session_start();

// Load MySQL DB settings
include_once('config.inc.php');

$_SESSION['username'] = 'Currently logged in users's username from database';
$_SESSION['user_id'] = 'Currently logged in user's id';

?>

//That's it! To print online users, you need to do it like this:

<?php
$users = mysql_query("SELECT id,username FROM ".$sql_table_users." WHERE chat_status='online' AND id!='".$_SESSION['user_id']."'");
if(mysql_num_rows($users) > 0){
    while($user = mysql_fetch_assoc($users)){
        print '<a href="#" alt="'.$user['id'].'|'.$user['username'].'" class="chat_user">'.$user['username'].'</a><br />';
    }
}
?>

这是为我提供的接口插件。插件位置是 /assets/plugin。

我不能对另一个数据库使用直接的 php 查询命令,我想将它与我的数据库分开,加上插件附带的 js 文件调用带有错误 URL 参数的脚本,那么将它合并到我的 yii 应用程序中的最佳方法是什么. 谢谢

4

1 回答 1

1

You should create a Yii extension that'll wrap your plugin. Then in your view you'll have to call a widget that'll display your chat.

I think this is the best way to do it because using this all your call to the plugin will be performed with the yii strucutre and philosophy. Only your extension will be structured using the chat philosophy.

Source about creating widgets

于 2013-02-28T10:51:13.917 回答