Yii Framework Forum: Ch#6 , Page#118 - Yii Framework Forum

Jump to content

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

Ch#6 , Page#118 Trying to get property of non-object

#1 User is offline   adnansalah84 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 19-November 11

Posted 13 March 2012 - 11:10 AM

Hello Yii,

I am working in my localhost environment:
XAMPP
PHP version 5.3.8
PHPmyadmin (MySQL) version 5.0.8

My webroot directory is:
C:\XAMPP\htdocs\

And my base directory for the MyProject site is:
C:\XAMPP\htdocs\YII\MyProject

In page#118:

public function actionCreate()
{
$model=new Issue;
$model->project_id = $this->_project->id;

and i got error message. it says:

Quote

PHP notice

Trying to get property of non-object

C:\XAMPP\htdocs\YII\MyProject\protected\controllers\IssueController.php(67)

55 $this->render('view',array(
56 'model'=>$this->loadModel($id),
57 ));
58 }
59
60 /**
61 * Creates a new model.
62 * If creation is successful, the browser will be redirected to the 'view' page.
63 */
64 public function actionCreate()
65 {
66 $model=new Issue;
67 $model->project_id= $this->_project->id;
68
69 // Uncomment the following line if AJAX validation is needed
70 // $this->performAjaxValidation($model);
71
72 if(isset($_POST['Issue']))
73 {
74 $model->attributes=$_POST['Issue'];
75 if($model->save())
76 $this->redirect(array('view','id'=>$model->id));
77 }
78
79 $this->render('create',array(

Stack Trace
#0
+
C:\XAMPP\htdocs\YII\framework\web\actions\CInlineAction.php(50): IssueController->actionCreate()
#1
........................................
........................................


In issueController.php

........................................
........................................
public function actionCreate()
	{
		$model=new Issue;
                $model->project_id= $this->_project->id;

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['Issue']))
		{
			$model->attributes=$_POST['Issue'];
			if($model->save())
				$this->redirect(array('view','id'=>$model->id));
		}

		$this->render('create',array(
			'model'=>$model,
		));
	}

........................................
........................................

Does anyone have any ideas or suggestions and how to solve the problem?

Thanks

Best Wishes,
Adnan
0

#2 User is offline   Cálcio 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 18-January 11
  • Location:Niterói - RJ - Brazil

Posted 14 March 2012 - 08:00 PM

In my controller this actcion is as follow

public function actionAdmin()
	{
		$model=new Issue('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['Issue']))
			$model->attributes=$_GET['Issue'];
		
		$model->project_id = $this->_project->id;
		
		$this->render('admin',array(
			'model'=>$model,
		));
	}


Try it.
0

#3 User is offline   adnansalah84 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 19-November 11

Posted 15 March 2012 - 09:55 AM

it is working well but the book did not say that!!! i want create function....not admin function.
0

#4 User is offline   Cálcio 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 18-January 11
  • Location:Niterói - RJ - Brazil

Posted 15 March 2012 - 12:36 PM

I think that code that I copy you is default. I remember, I only change small things.
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