Newbie: Change Yii CRUD structure

Hi there,

I am building a simple site that allows you to post photos with a simple description. There are only two pages—the view of the photos as a list (I don’t need to see individual records) and the “create” page. Simple enough.

The problem is that I would like the "create" page to pop up on top of the view page as a sort of lightbox, so that when somebody submits a photo they can do so right there.

What is the sanctioned way of going about this? Right now I have created the "overlay" div inside /layouts/main.php. Then using JQuery, I make the overlay visible and tell it to load "www.mysite.com/post/create".

The problem is that this then loads the entire main.php layout again within the overlay (header, logo and all). How can I override this so that it just loads the create page? I could tell it to load the create page’s view directly but then that would be missing out the Controller and the MVC structure.

Thanks for any help you can give,

Joshua

In your Post controller and create action you can add:


$this->layout = null;

and main.php will not be used.

Ah, okay, that would make sense, but where exactly would I put that so that it only affects the "create" part of the Post, and not the View?

Thanks,

J

Also to point out—I have added that code into the ActionCreate function, but it still appears to pull from main.php. Here’s my code:


	public function actionCreate()

	{

		$this->layout = null;

		$model=new Post;


		// Uncomment the following line if AJAX validation is needed

		$this->performAjaxValidation($model);


		if(isset($_POST['Post']))

		{

			$model->attributes=$_POST['Post'];


			if ($model->validate()) {

				

				$uploadedImage = CUploadedFile::getInstance($model, 'image');

                $savefilename = Yii::app()->basePath . '/../images/' . $model->photo_url;

                $uploadedImage->saveAs($savefilename);


				if($model->save(false)) // False because $model->save() validates the form and we have already done this with $model->validate

					$this->redirect(array('view','id'=>$model->id));

			}

		}

		

		$this->render('create',array(

			'model'=>$model,

		));

	}

Why not just use renderpartial instead of render?

Reason is next line in code:




$this->redirect(array('view','id'=>$model->id));



because you redirect user to viewAction, which probably use layout. Maybe you can add additional params, when redirect, and according to this parameter disable or enable layout in viewAction…