Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Lets understand both the statements</p> <pre><code> $user= User::model()-&gt;findByAttributes(array('email'=&gt;$this-&gt;username)); </code></pre> <p>Lets first understand <strong>findByAttributes()</strong><br> This is defined in the <strong>CActiveRecord class</strong>, which all database models should extend. In theory, you could create an instance of the class and then use that instance’s method:</p> <pre><code>$model = new Page; $model = $model-&gt;findByPk($id); </code></pre> <p>That would work, but it’s a bit verbose, redundant, and illogical. <strong>The alternative is to use a static class instance</strong>. A static class instance is a more advanced OOP concept.<br> Now <strong>User::model()</strong><br><br> If you will look into your User.php you will find a function like</p> <pre><code>public static function model($className=__CLASS__) { return parent::model($className); } </code></pre> <p>So what does <strong>User::model()</strong> does?<br><br> Here model() is a static method and here it represents <strong>model() method of User class</strong> .<br> So basically <strong>User::model()</strong> returns a <strong>User class object.</strong><br> Hence when you execute this statement</p> <pre><code>$user= User::model()-&gt;findByAttributes(array('email'=&gt;$this-&gt;username)); </code></pre> <p>Then in turn you get a <strong>User class object in the form of $user</strong>.<br><br> And this is the reason that you can access <code>encrypt()</code> method like <code>$user-&gt;encrypt()</code></p> <p><strong>Source:-</strong> Larry Ulman's Yii Book</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload