PHP code example of shintio / yii2-profile

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

    

shintio / yii2-profile example snippets


use shintio\profile\Profile;

// User- ActiveRecord model
$profile=new Profile(User::className());

// We can create new User;
$user=new User();
// Also we can use existing User;
//$user=User::find()->one();

$profile=new Profile($user);

$query=Profile::find(User::className());

// In where function we can use:
// Assoc array for '=' condition
$query->where(['username'=>'admin']); // username- User's attribute
// Indexed array for '%LIKE%' condition
$query->andWhere(['LIKE','firstName','Adm']); // firstName- additional profile field
$query->orWhere(['lastName'=>'Great']); // lastName- additional profile field

$profile=$query->one();
//$profiles=$query->all();

echo $profile->getField('firstName'); // Admin

$profile->setField('firstName','Moder');
echo $profile->getField('firstName'); // Moder

$profile->setField('username','moder');

echo '<pre>';
// Get profile in array of Field ojbects
var_dump($profile->getProfile());
// Get profile in assoc array
// var_dump($profile->getProfile(true));
// Same as getProfile(true)
// var_dump($profile->getProfileInArray());
echo '</pre>';

$profile->save();
// username: moder
// firstName: Moder
// lastName: Great

php composer.phar