O'Reilly logo

Yii Project Blueprints by Charles R. Portwood II

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sharing new content

At this point, if we had shares in our database, we'd be able to see them. So let's work on sharing new content! From within our controller, the action to handle sharing is simply going to be loading a new Share model and populating it. Have a look at the following code:

public function actionCreate() { $share = new Share; if (isset($_POST['Share'])) { $share->attributes = array( 'text' => $_POST['Share']['text'], 'reply_id' => isset($_POST['Share']['reply_id']) ? $_POST['Share']['reply_id'] : NULL, 'author_id' => Yii::app()->user->id ); // Share the content if ($share->save()) { $this->renderPartial('share', array('data' => $share)); Yii::app()->end(); } } throw new CHttpException(500, 'There was an error sharing your content'); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required