PHP code example of rockeinstein / eloquent-zf2

1. Go to this page and download the library: Download rockeinstein/eloquent-zf2 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rockeinstein / eloquent-zf2 example snippets


    
    namespace Album\Model;

    // skipping some code here

    use Illuminate\Database\Eloquent\Model as EloquentZF2Model;

    class Album extends EloquentZF2Model implements InputFilterAwareInterface
    {

$inputFilter->add($factory->createInput(array(
              'name'     => 'email    ',
                'EloquentZF2\Validator\noRecordExists',
                        'options' => array(
                            'table' => 'users',
                            'field' => 'login',
                            'exclude' => array(
                                'field' => 'login',
                                'value' => '[email protected]',
                                ),
                            ),
                        ),
                    ),
                )
            )
        );

/* SomeController.php */

// use CallbackCheckAdapter as AuthAdapter
use EloquentZF2\Authentication\Adapter\CallbackCheckAdapter as AuthAdapter;

// ... controller code skipped ...

public function loginAction() {

    // ... skipping validation and form code ...

    // define custom callback function (bcrypt)
    $callback = function($a, $b) {
        $bcrypt = new \Zend\Crypt\Password\Bcrypt(array('cost' => '14'));
        return $bcrypt->verify($b, $a);
    };

    // init auth adapter
    $authAdapter = new AuthAdapter('default', 'users', 'login', 'password', $callback);

    // set auth credentials (assuming it was posted by form)
    $authAdapter
        ->setIdentity($request->getPost('login'))
        ->setCredential($request->getPost('password'));

    // authenticate
    $authResult = $authAdapter->authenticate();


/* SomeController.php */

// use CallbackCheckAdapter as AuthAdapter
use EloquentZF2\Authentication\Adapter\CredentialTreatmentAdapter as AuthAdapter;

// ... controller code skipped ...

public function loginAction() {

    // ... skipping validation and form code ...
    $callback = 'MD5(?)';

    // init auth adapter
    $authAdapter = new AuthAdapter('default', 'users', 'login', 'password', $callback);

    // set auth credentials (assuming it was posted by from)
    $authAdapter
        ->setIdentity($request->getPost('login'))
        ->setCredential($request->getPost('password'));

    // authenticate
    $authResult = $authAdapter->authenticate();
}