使用zend框架在Web服务中传递参数

时间:2012-03-23 19:53:39

标签: php web-services zend-framework zend-soap

我使用Zend Framework创建了一个身份验证的Web服务 这是我的服务器:

<?php

require_once APPLICATION_PATH . '/controllers/services/Authentification.php';

class ServController extends Zend_Controller_Action
{
    private $_WSDL_URI = 'http://127.0.0.1/EverTags1/webAuthentification/public/Serv/?wsdl';

    public function init()
    {
    }

    public function indexAction()
    {
        $this->_helper->viewRenderer->setNoRender();    
        if(isset($_GET['wsdl'])) {
            $this->hadleWSDL(); //return the WSDL
        } else {
            $this->handleSOAP(); //handle SOAP request
                }               
    }

    private function hadleWSDL()
    {
        $autodiscover = new Zend_Soap_AutoDiscover();//Zend_Soap_AutoDiscover which will create the WSDL file
        $autodiscover->setClass('Authentification');// class that we use as webservice
        $autodiscover->handle();
    }

    public function handleSOAP()
    {
    $soap = new Zend_Soap_Server($this->_WSDL_URI); 
        $soap->setClass('Authentification');
        $soap->handle();    
    }
}

客户端:

<?php

class ClientController extends Zend_Controller_Action
{
    private $_WSDL_URI = 'http://127.0.0.1/EverTags1/webAuthentification/public/Serv/?wsdl';

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
       $client = new Zend_Soap_Client($this->_WSDL_URI);

        $this->view->UserInformation = $client->authentification('marwa','password');
    }


}

我用作webservice的类

<?php

ini_set("soap.wsdl_cache_enabled", "0");
//require_once realpath(APPLICATION_PATH . '/../library/').'/UserClass.php';

class Authentification {
    /**
     *
     * @param string $username
     * @param string $password
     * @return string
     */
 public function authentification($username,$password) {

        $dbAdapter = Zend_Db_Table::getDefaultAdapter();
        $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);

        $authAdapter->setTableName('standard_users')
                    ->setIdentityColumn('username')
                    ->setCredentialColumn('password');


        $authAdapter->setIdentity($username);
        $authAdapter->setCredential($password);
        //authentification
        $auth = Zend_Auth::getInstance();
        $result = $auth->authenticate($authAdapter);
        if ($result->isValid()) {
         //Authentification Réussie : on stocke les informations de l'utilisateur sauf le mot de passe !

           $user = $authAdapter->getResultRowObject();
           $UserName = $auth->getIdentity();

        }
        else  $UserName = 'Authentication failed (Unknown user or incorrect password)! Please Retry !';

  return $UserName;          
 }


}
?>

我的问题是我写的时候

 $authAdapter->setIdentity($username);
            $authAdapter->setCredential($password);

并且我在函数'authentification'的原型中传递参数,Web服务不起作用

但是当我直接设置参数时

$authAdapter->setIdentity('username');
                $authAdapter->setCredential('password');

它有效。

我无法理解为什么参数不会从函数'authentification'的原型转移到setIdentity和setCredential。

如果你能帮助我,我将不胜感激。

0 个答案:

没有答案