Yii Framework Forum: Can't Load Model! - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Can't Load Model! Rate Topic: -----

#1 User is offline   kalempir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 20-July 11

Posted 26 January 2013 - 06:09 AM

I am very confused!
All things worked before, but today I found registration model is not deleteable.
I can not understand the type of error.
My code:
public function actionDelete($id)
	{
if(Yii::app()->request->isPostRequest)
		{
            $model = $this->loadModel($id);
            $model->delete();
	// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
			if(!isset($_GET['ajax']))
				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
		}
		else
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
	}

script exit normally.
Firebug doesn't show any error.
It seems model class can not load data from database, but why I can not figure out. All other actions of this model worked as I expected.
What do I do wrong in this action?
0

#2 User is offline   kalempir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 20-July 11

Posted 27 January 2013 - 08:39 AM

please, any help!
0

#3 User is offline   jodev 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 75
  • Joined: 10-January 11
  • Location:The Netherlands

Posted 27 January 2013 - 02:38 PM

Two things that I would consider checking at first glance. First of all, are you deleting via a form (POST request). If you try do access the delete action using the url it won't work as it fails the if-statement. Secondly, have you altered the loadModel() method at some point? What value does $model have right after it is being assigned to?
0

#4 User is offline   kalempir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 20-July 11

Posted 28 January 2013 - 12:48 AM

View Postjodev, on 27 January 2013 - 02:38 PM, said:

Two things that I would consider checking at first glance. First of all, are you deleting via a form (POST request). If you try do access the delete action using the url it won't work as it fails the if-statement. Secondly, have you altered the loadModel() method at some point? What value does $model have right after it is being assigned to?

Yes, deleting via POST request.
I included this code inside post checking case:
.....
if(Yii::app()->request->isPostRequest)
{
   Yii::log('Registration id: ' . $id, CLogger::LEVEL_INFO);
            
   // we only allow deletion via POST request
   $model = $this->loadModel($id);
.....

The logging file show me id which is also exists in database table.

the loadModel() function
public function loadModel($id)
	{
		$model=Registration::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}


It seems to me findByPk function is not working.
I tried to use findByPk function of Registration model, it is not working, I mean not getting datas from db. I tested it in view action of my controller, the result the same, no data, just blank web page.
The other models which extended from parent of this problematic model are working normally.
I don't know to which direction dig.
0

#5 User is offline   kalempir 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 20-July 11

Posted 28 January 2013 - 02:47 AM

This is a test action of RegistrationController
public function actionTest()
    {
        $model = Registration::model()->findByPk(162);

        Yii::log('Registration id: ' . $model->reg_id, CLogger::LEVEL_INFO);

        $this->redirect(array('patient/index'));
    }


This is a application log out:
13:43:33.779994 	trace 	system.CModule 	

Loading "log" application component
in /var/www/vhosts/semamed.org/index.php (13)

13:43:33.782048 	trace 	system.CModule 	

Loading "bootstrap" application component
in /var/www/vhosts/semamed.org/index.php (13)

13:43:33.787442 	trace 	system.CModule 	

Loading "clientScript" application component
in
/var/www/vhosts/semamed.org/protected/extensions/bootstrap/components/Bootstrap.php
(188)
in
/var/www/vhosts/semamed.org/protected/extensions/bootstrap/components/Bootstrap.php
(149)
in
/var/www/vhosts/semamed.org/protected/extensions/bootstrap/components/Bootstrap.php
(127)

13:43:33.788995 	trace 	system.CModule 	

Loading "assetManager" application component
in
/var/www/vhosts/semamed.org/protected/extensions/bootstrap/components/Bootstrap.php
(518)
in
/var/www/vhosts/semamed.org/protected/extensions/bootstrap/components/Bootstrap.php
(188)
in
/var/www/vhosts/semamed.org/protected/extensions/bootstrap/components/Bootstrap.php
(149)

13:43:33.789772 	trace 	system.CModule 	

Loading "request" application component
in
/var/www/vhosts/semamed.org/protected/extensions/bootstrap/components/Bootstrap.php
(518)
in
/var/www/vhosts/semamed.org/protected/extensions/bootstrap/components/Bootstrap.php
(188)
in
/var/www/vhosts/semamed.org/protected/extensions/bootstrap/components/Bootstrap.php
(149)

13:43:33.794059 	trace 	system.CModule 	

Loading "urlManager" application component
in /var/www/vhosts/semamed.org/index.php (13)

13:43:33.801672 	trace 	system.web.filters.CFilterChain 	

Running filter RegistrationController.filterrights()
in /var/www/vhosts/semamed.org/index.php (13)

13:43:33.802100 	trace 	system.CModule 	

Loading "user" application component
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RightsFilter.php
(24)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)
in /var/www/vhosts/semamed.org/index.php (13)

13:43:33.803889 	trace 	system.CModule 	

Loading "session" application component
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RightsFilter.php
(24)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)
in /var/www/vhosts/semamed.org/index.php (13)

13:43:33.805193 	trace 	system.CModule 	

Loading "authManager" application component
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RWebUser.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RightsFilter.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)

13:43:33.807698 	trace 	system.CModule 	

Loading "db" application component
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RWebUser.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RightsFilter.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)

13:43:33.808980 	trace 	system.db.CDbConnection 	

Opening DB connection
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RWebUser.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RightsFilter.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)

13:43:33.814773 	trace 	system.db.CDbCommand 	

Querying SQL: SELECT *
FROM `AuthAssignment`
WHERE userid=:userid. Bound with :userid='6'
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RWebUser.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RightsFilter.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)

13:43:33.814834 	profile 	system.db.CDbCommand.query 	

begin:system.db.CDbCommand.query(SELECT *
FROM `AuthAssignment`
WHERE userid=:userid. Bound with :userid='6')

13:43:33.815104 	profile 	system.db.CDbCommand.query 	

end:system.db.CDbCommand.query(SELECT *
FROM `AuthAssignment`
WHERE userid=:userid. Bound with :userid='6')

13:43:33.815555 	trace 	system.db.CDbCommand 	

Querying SQL: SELECT name,t1.type,description,t1.bizrule,t1.data,weight
					FROM AuthItem t1
					LEFT JOIN Rights t2 ON name=itemname
					ORDER BY t1.type DESC, weight ASC
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RDbAuthManager.php
(169)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RDbAuthManager.php
(65)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RWebUser.php
(43)

13:43:33.815612 	profile 	system.db.CDbCommand.query 	

begin:system.db.CDbCommand.query(SELECT
name,t1.type,description,t1.bizrule,t1.data,weight
					FROM AuthItem t1
					LEFT JOIN Rights t2 ON name=itemname
					ORDER BY t1.type DESC, weight ASC)

13:43:33.816014 	profile 	system.db.CDbCommand.query 	

end:system.db.CDbCommand.query(SELECT
name,t1.type,description,t1.bizrule,t1.data,weight
					FROM AuthItem t1
					LEFT JOIN Rights t2 ON name=itemname
					ORDER BY t1.type DESC, weight ASC)

13:43:33.817919 	trace 	system.web.auth.CDbAuthManager 	

Checking permission "Registration.*"
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RWebUser.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RightsFilter.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)

13:43:33.818337 	trace 	system.db.CDbCommand 	

Querying SQL: SELECT `parent`
FROM `AuthItemChild`
WHERE child=:name. Bound with :name='Registration.*'
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RWebUser.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RightsFilter.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)

13:43:33.818392 	profile 	system.db.CDbCommand.query 	

begin:system.db.CDbCommand.query(SELECT `parent`
FROM `AuthItemChild`
WHERE child=:name. Bound with :name='Registration.*')

13:43:33.818584 	profile 	system.db.CDbCommand.query 	

end:system.db.CDbCommand.query(SELECT `parent`
FROM `AuthItemChild`
WHERE child=:name. Bound with :name='Registration.*')

13:43:33.818730 	trace 	system.web.auth.CDbAuthManager 	

Checking permission "Registrator"
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RWebUser.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RightsFilter.php
(43)
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)

13:43:33.818945 	trace 	system.web.filters.CFilterChain 	

Running filter GridViewHandler.filter()
in
/var/www/vhosts/semamed.org/protected/modules/rights/components/RController.php
(36)
in /var/www/vhosts/semamed.org/index.php (13)


It seems RController blocking it. Why? User is super admin.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users