Randomly getting: "Cannot instantiate abstract class CActiveRecord"


Fatal error: Cannot instantiate abstract class CActiveRecord in [PATH]\yii-1.1.8.r3324\framework\db\ar\CActiveRecord.php on line 371

This is a weird error, not sure how to consistently recreate it. I think it’s due to caching, I removed all schema caching and still get this at random with my Yii app.

Using Yii 1.1.8 also ran in to the issue with the latest from svn.

Any ideas?

What does line 371 contain?

Didn’t you forget to override CActiveRecord::model() in one of your model classes?

I didn’t, all of the models were generated by gii and had the static model function.

Can’t seem to get it to break anymore, guess I’ll never know… Weird!

I appreciate the help though ;)

As it was written on line 371, let’s try simply with:




// somewhere in code... totally random place

$model = new MyModel(); // try with parameter null also...idk <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />



Second, in framework code right before line 371 add die(var_dump($className));

If there are no results, your AR class is definitely prefixed with abstract :)

Hi i am new to yii,

Am creating a login form without using gii tool,

But thats generating an error <Cannot instantiate abstract class CActiveRecord">.I followed your step i.e to add die(var_dump($className));

and it displayed as <string(13) "CActiveRecord" >

so i want to know what actually is the error,Please help me as soon as possible and also give me the solution.

Thank you,

This is confusing, OP said that they used gii and got error. @nafisa now says WITHOUT gii. So is it with or without.

BTW @nafisa, the Login Form generated in the skeleton app doesn’t use gii either. It also doesn’t use ‘CActiveRecord’

Please show your model class declaration and your action code.

//This is form file

<?php

$this->pageTitle=Yii::app()->name . ’ - SchoolLogin’;

$this->breadcrumbs=array(

'Login',

);

?>

<?php

$this->menu=array(

array('label'=&gt;'Sign up', 'url'=&gt;array('schoolregister')),

);

?>

<h1>Login</h1>

<p>Please fill out the following form with your login credentials:</p>

<div class="form">

<?php $form=$this->beginWidget(‘CActiveForm’, array(

'id'=&gt;'login-form',


'enableClientValidation'=&gt;true,


'clientOptions'=&gt;array(


	'validateOnSubmit'=&gt;true,


),

)); ?>

&lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'username'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'username'); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'username'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'password'); ?&gt;


	&lt;?php echo &#036;form-&gt;passwordField(&#036;model,'password'); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'password'); ?&gt;


&lt;/div&gt;











&lt;div class=&quot;row buttons&quot;&gt;


	&lt;?php echo CHtml::submitButton('Login'); ?&gt;


&lt;/div&gt;

<?php $this->endWidget(); ?>

</div>

//model file

<?php

abstract class login extends CActiveRecord

{

public &#036;username;


public &#036;password;





private &#036;_identity;





public function tableName()


{


	return 'tbl_login';


}








public function rules()


{


	


	return array(


		array('username, password,email,contact_no', 'required'),


		array('username, password', 'length', 'max'=&gt;255),


		array('username','match' ,'pattern'=&gt;'/^[A-Za-z_]+&#036;/u','message'=&gt;'Enter only letters&#33;'),


		array('email, password', 'length', 'max'=&gt;255),


		


		array('id, name, email, password', 'safe', 'on'=&gt;'search'),


		array('contact_no', 'length', 'max'=&gt;10),


		array('contact_no','numerical', 'integerOnly'=&gt;true),


		array('username', 'length', 'min'=&gt;3, 'max'=&gt;12),


		array('email', 'email', 'message'=&gt;'Please insert valid Email'),


		array('email', 'email','message'=&gt;&quot;The email isn't correct&quot;),


		array('email', 'unique','message'=&gt;'Email already exists&#33;'),


	    array('password', 'authenticate'),


	


		


	);


}








public function relations()


{


	


	return array(


	);


}





public function attributeLabels()


{





		  return array(


		  'id'=&gt;'ID',


		  'username'=&gt;'Username',


		  'password'=&gt;'Password',


		  'email'=&gt;'Email',


		  'contact_no'=&gt;'Contact NO',


	    


    );


	


}





public function search()


{


	





	&#036;criteria=new CDbCriteria;





	&#036;criteria-&gt;compare('id',&#036;this-&gt;id);


	&#036;criteria-&gt;compare('username',&#036;this-&gt;username,true);


	


	&#036;criteria-&gt;compare('password',&#036;this-&gt;password,true);





	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


}


public function authenticate(&#036;attribute,&#036;params)


{


    if(&#33;&#036;this-&gt;hasErrors())


    {


	&#036;this-&gt;_identity=new UserIdentity(&#036;this-&gt;username,&#036;this-&gt;password);





	&#036;this-&gt;_identity-&gt;authenticate();


	


    }


    }





/**


 * Logs in the user using the given username and password in the model.


 * @return boolean whether login is successful


 */


public function login()


{


	if(&#036;this-&gt;_identity===null)


	{


		&#036;this-&gt;_identity=new UserIdentity(&#036;this-&gt;username,&#036;this-&gt;password);


		&#036;this-&gt;_identity-&gt;authenticate();


		return true;


	}


	


	else


		return false;


}

}

//controller

public function actionSchoollogin()

{


	


&#036;model=new Login;


	if(isset(&#036;_POST['ajax']) &amp;&amp; &#036;_POST['ajax']==='login-form')


	{


		echo CActiveForm::validate(&#036;model);


		Yii::app()-&gt;end();


	}





	


	if(isset(&#036;_POST['Login']))


	{


		&#036;model-&gt;attributes=&#036;_POST['Login'];


		


		


			if(&#036;model-&gt;validate() &amp;&amp; &#036;model-&gt;login())	


		&#036;this-&gt;redirect(array('schoolform'));


	}


	


&#036;this-&gt;render('schoollogin',array('model'=&gt;&#036;model));


}

//useridentity

<?php

class UserIdentity extends CUserIdentity

{

public function authenticate()


{


	&#036;user = Login::model()-&gt;findByAttributes(array('username'=&gt;&#036;this-&gt;username));





    if (&#036;user===null) 


	{ 


	&#036;this-&gt;errorCode=self::ERROR_USERNAME_INVALID;


    } 


	else if 


	(&#036;user-&gt;password &#33;== (&#036;this-&gt;password) ) 


	{ 


	&#036;this-&gt;errorCode=self::ERROR_PASSWORD_INVALID;


	} 

else

	{ 


	    &#036;this-&gt;errorCode=self::ERROR_NONE;


	}


    return &#33;&#036;this-&gt;errorCode;





}

}

I have done without gii,created my own form,model,controller then edited useridentity so that it gets login using db value.

Now its showing as <string(13) "CActiveRecord">

after including die(var_dump($className));

Please help me soon

http://www.yiiframework.com/forum/index.php/topic/24148-randomly-getting-cannot-instantiate-abstract-class-cactiverecord/page__view__findpost__p__117309

Also, do not declare a class as abstract if you want to instantiate it.

I have not declared it as abstract in my class.

But then too am getting that error.

I have done without gii,created my own form,model,controller then edited useridentity so that it gets login using db value.

HI,

i have to create a form of two pages,i have created two view,two model file and one db table for this,in the first page after entering the data and clicking on next page button it goes to next page(i.e data is to continued)

after submission of data in second page,the data of first page is stored in separate id (ex.id 1)of db table and the data of second page is stored in someother id(ex.id 2) of db table.

But i want it to be stored in the same id of db table because both the page datas are of same persons.

please can anyone help me as i am new to yii.I have read different articles but didnt understand it properly.

Thank You,