PHP code example of drey / prefs

1. Go to this page and download the library: Download drey/prefs 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/ */

    

drey / prefs example snippets


    use drey\Prefs\Factory;

    # Obtain a Prefs object
    # with file system storage and username
    $prefs = Factory::fileSystem('/path/to/directory','bob') 

    # set preference "color" for current user (bob)
    $prefs->set('color','red');
    
    # get color preference of current user
    $color = $prefs->get('color');
    
    # $color is set to 'red'

    use drey\Prefs\Factory;

    # obtain a PDO object
    $pdo = myConnect();

    # Obtain a Prefs object
    # with RDBM storage and username
    $prefs = Factory::pdo($pdo,'bob') 
 
    # set preference "color" for current user (bob)
    $prefs->set('color','red');
    
    # get color preference of current user
    $color = $prefs->get('color');
    
    # $color is set to 'red'

    $bird = $prefs->get('bird','eagle');
    
    # $bird is set to 'eagle' if key 'bird' not found

    $prefs->set('fruit','lemmon','alice');
    # ...
    $prefs->get('fruit','pear','alice')

    # one user
    $prefs->set('closing_date',$form->closing_date,'*');

    (...)

    # other users
    $closing_date = $prefs->get('closing_date',date('Y-m-d'),'*');
   
 

    # before showing the form get the last value entered
    if ($model->isNewRecord && !$model->date) {
        $model->date = $prefs->get('invoice_date',date('Y-m-d'));
    }

    # after post, update value entered
    if (post) {
        $prefs->set('invoice_date',$model->date);
    }