在单个模型中对方法进行分组的正确方法是什么?

I'm sorry for the title, maybe I couldn't describe it well. But here's what I want:

Now if I create a model m.php and put it inside the models folder with the following code:

class m extends CI_Model {

  public function username() {
    print "john doe";
  }

  public function password() {
    print "ABC123";
  }

}

Now, I can simply do the following in the controller :

$this->load->model("m");
$this->m->username(); // prints john doe
$this->m->password(); // prints ABC123

Now what I need to do is to make it in a way on which I can call the methds above as following:

$this->m->genralinfo->username(); // prints john doe

$this->m->privacy->password(); // prints "ABC123"

How can I achieve this ? I want to do this in order to group the methods that are specific to something alltogether, this helps me to structure my code better.

**I am aware that it is possible to create a new model for every group of methods but all I'd like to keep everything that is related to the user inside a single model **

Is this even possible using a single model ?

I think you want like this

class m extends CI_Model
{
    public $genralinfo;
    function __construct()
    {
        parent::__construct();
        $this->genralinfo=new Genralinfo();
    }

}
class Genralinfo
//class Genralinfo extends CI_Model//you may extend CI_MODEL too
{
    public function username() {
        print "john doe";
    }

    public function password() {
        print "ABC123";
    }

}

Create a function 'general-info' and and 'privacy' which get parameters. call it in the controller.

$m->generalinfo('username');

in the model

public function generalinfo($v='') {
    switch($v){
     case 'username':
        $ret=$this->username; //you would have to fill the object first
        break;
     case 'name':
        $ret=$this->name; //same here
        break;
     default:
        $ret=Array();
        $ret['username']=$ret=$this->username;
        $ret['name']=$ret=$this->name;
   }
    return $ret;
} 

And take care of the output in the view. This example would give you either a string with a specific info you requested. Or an array of all general data. You would have to care for these different cases. Check the return the in the controller for example.

But this way you could also make an ajax call, and convert the return into JSON and push it to a modal or whatever.

Got it. I put this inside the model

public $info;
public function __construct() 
{ 
    parent::__construct();
    $this->info = (object) array('foo' => 'bar', 'property' => 'value'); 
} 

and then simply :

echo $class->obj->foo;//outputs bar