Question

i'm trying Zend framework, i've got two folders in E:\Archivos de programa\Zend\ZendServer\share, une is ZendServer and the other one is ZendServer2 I can't recall if i ever install this two version but i dont think this is the problem I'm using netbeans as ide ando i'm trying to make an ABM of users using BlockCipher Here is my code

<?php
use Zend\Crypt\BlockCipher;
class Application_Model_DbTable_Usuarios extends Zend_Db_Table_Abstract
{

    protected $_name = 'usuario';

    public function getUsuario($usuario)
    {
        $usuario = (string)$usuario;
        $row = $this->fetchRow('Usuario = ' . $usuario);
        if (!$row) {
            throw new Exception("Could not find row $usuario");
        }
        return $row->toArray();
    }

    public function addUsuario($usuario, $clave)
    {

       $blockCipher = Zend\Crypt\BlockCipher::factory('mcrypt',array('algo'=>'aes'));
       $blockCipher->setKey('encryption key');
       $result = $blockCipher->encrypt($clave);
       echo "Encrypted text: $result \n";
       exit;
       $data = array(
            'Usuario' => $usuario,
            'Clave' => $blockCipher,
        );
        $this->insert($data);

    }

    public function updateUsuario($usuario, $clave)
    {
        $blockCipher =  BlockCipher::factory($clave, array(
                                'algo' => 'blowfish',
                                'mode' => 'cfb',
                                'hash' => 'sha512'
                        ));
        $data = array(
            'Clave' => $blockCipher,
        );
        $this->update($data, 'Usuario = ' . (string)$usuario);

    }

    public function deleteUsuario($usuario)
    {
        $this->delete('Usuario = ' . (string)$usuario);
    }

}

and in my php.ini i've got include_path=".;E:\Archivos de programa\Zend\ZendServer\share\ZendFramework2\library"

And i get this error

Fatal error: Class 'Zend\Crypt\BlockCipher' not found in E:\Documents and Settings\dvieira\Mis documentos\NetBeansProjects\justforgeeks\application\models\DbTable\Usuarios.php on line 21

I dont understand why. Can you help me please? Thanks in advance

Was it helpful?

Solution

You are using namespaces in your application, therefore you need to make sure that your autoloader can handle this. If it's a ZF1 app then not. Can you try using require to include the class file instead? You can ass well amend the autoloader to work with namespaces

Secondly when using namespaces, if you create an alias for a class

use Zend\Crypt\BlockCipher;

you then instantiate it

$blockCipher = BlockCipher::factory('mcrypt',array('algo'=>'aes'));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top