开发者

Zend Framework - Your resource plugin

Has created the resource plugin to work with the class Realplexor, using it to exchange messages between multiple clients, it is well suited for a chat. Prescribed for this plugin settings application.ini. The controller for the test write the following code:

$realplexorObject = Zend_Registry::get('realplexor');
print_r ($realpl开发者_C百科exorObject);
die ();

He gives the following:

Dklab_Realplexor Object
(
    [_timeout:Dklab_Realplexor:private] => 5
    [_host:Dklab_Realplexor:private] => rpl.newchat.com
    [_port:Dklab_Realplexor:private] => 10010
    [_identifier:Dklab_Realplexor:private] => identifier
    [_login:Dklab_Realplexor:private] => 
    [_password:Dklab_Realplexor:private] => 
    [_namespace] => Chat_
)

ie Dklab_Realplexor object is created and stored in Zend_Registry, but that would work with him I want to write for him a model with specific methods for my project that should use class methods Dklab_Realplexor, how exactly does this do?

I tried to write a model like this:

class Application_Model_Realplexor_Message extends Dklab_Realplexor
{
    public function  __construct() {
        return Zend_Registry::get('realplexor');
    }

    public function post ($text, $fromUser = 0, $fromOperator = 0) {
        $this->send("Alpha", $text);
    }
}

But, if you create an object of this model in the controller, it is why it is not initialized:

$realplexorMessageModel = new Application_Model_Realplexor_Message();
print_R ($realplexorMessageModel);
die ();

issues:

Application_Model_Realplexor_Message Object
(
    [_timeout:Dklab_Realplexor:private] => 5
    [_host:Dklab_Realplexor:private] => 
    [_port:Dklab_Realplexor:private] => 
    [_identifier:Dklab_Realplexor:private] => 
    [_login:Dklab_Realplexor:private] => 
    [_password:Dklab_Realplexor:private] => 
)

I would like to make this plug-in resource and model for him on the same principle as a model made for existing ZF plug-in resources for the database.


Maybe you can try this:

class Application_Model_Realplexor_Message
{
    protected $realplexor;

    public function  __construct() {
        $this->realplexor = Zend_Registry::get('realplexor');
    }

    public function post ($text, $fromUser = 0, $fromOperator = 0) {
        $this->realplexor->send("Alpha", $text);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜