Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8744713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:53:08+00:00 2026-06-13T11:53:08+00:00

I have implemented a crypt behavior class that can be attached to a AR

  • 0

I have implemented a crypt behavior class that can be attached to a AR model so that, attached attributes will be stored as encrypted and retrieved as decrypted string.

class User extends CActiveRecord 
{
    public function behaviors()
    {
        return array(
            'crypt' => array(
            // this assumes that the behavior is in the folder: protected/behaviors/
            'class' => 'application.behaviors.CryptBehavior',
            // this sets that the attributes to be encrypted/decrypted are encryptedfieldname of the model
            'attributes' => array('password'),
            'useAESMySql' => true
           )
        );
    }
}

This is working fine. I am also having my custom class Myuser which extends User model to write my custom functions so that if i make some change in my user table and regenerate model, i wont loose my own functions.

If i move my behavior function to the class MyUser, the behavior is not getting attached and not working as expected.

class MyUser extends User 
{
    public function behaviors()
    {
        return array(
            'crypt' => array(
            // this assumes that the behavior is in the folder: protected/behaviors/
            'class' => 'application.behaviors.CryptBehavior',
            // this sets that the attributes to be encrypted/decrypted are encryptedfieldname of the model
            'attributes' => array('password'),
            'useAESMySql' => true
           )
        );
    }

    public function customfn1()
    {
         //some code goes here...
    }
}

Any help would be appreciated.
Reference Link: Crypt Behavior

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:53:09+00:00Added an answer on June 13, 2026 at 11:53 am

    Here is the working solution. I need to test all the scenarios. Thanks to @bool.dev for your function.

    class MyUser extends User 
    {
        public static function model($className=__CLASS__)
        {
           return parent::model($className);
        }
    
        public function behaviors()
        {
            return array(
                'crypt' => array(
                // this assumes that the behavior is in the folder: protected/behaviors/
                'class' => 'application.behaviors.CryptBehavior',
               // this sets that the attributes to be encrypted/decrypted are encryptedfieldname of the model
                'attributes' => array('password'),
               'useAESMySql' => true
              )
           );
        }
    
       public static function getUserByID($id)
       {
          //validation of $id goes here..
    
          return MyUser::model()->findByPk($id);
       }
    }
    

    in my controller

    $userModel = MyUser::getUserByID(1);
    

    in my view

    $userModel->password; //gives me the decrypted password; for easy understanding, i used password field here....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented Facebook into my app but now I find that whenever I
I have implemented a UISearchDisplayController that allows users to search a table. Currently the
I have implemented a simple entity ejb with a @version annotation. I expect that
I have implemented two methods of how I think a Singleton class should be
I have implemented language localization to an Android application. My questions are: I can't
I have implemented a simple linked list class and I would now like to
I have implemented a simple appmod that handle WebSockets and echo back the messages.
I have a class that encrypts, decrypts, hashes and signs. In the future it
We have implemented a drag and drop feature that shows a nice simple representation
I have implemented INotifyPropertyChanged to the following class public class FactoryItems : INotifyPropertyChanged {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.