Render A View In Another View

Hi

I have a module which I want to show a view of it as a homepage. I also want to show a view of another model in the homepage. For example I want to show top ten news in the first page and show the subscribe form in the first page too. I used the renderPartial function and success to display both of them, but the subscribe form create nothing in the database. Any body can help me?

to render a view of a module you could use


$this->render('application.modules.yourmodel.views.folder1.fileview');

please post your code that contains the form, and how call this view. Also give us more details (which controller call which view)

Hi thanks for fast answer. This is my module action


public function actionToday()

	{

		$this->layout='//layouts/main';

		$model = new Hadith();

		$dataProvider= $this->loadModel($model->todayHadith());

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

				'dataProvider'=>$dataProvider,

		));

	}

which is a custom action returns a Hadith that its date is set to today date. This is the view code for that action.




<?php $model=new User(); $this->renderPartial('application.views.user.create', array('model'=>$model)); ?>

<?php if(!is_null($dataProvider)): ?>

<div class="view">


	<b><?php echo CHtml::encode($dataProvider->getAttributeLabel('title')); ?>:</b>

	<?php echo CHtml::link(CHtml::encode($dataProvider->title), array('view', 'id'=>$dataProvider->id)); ?>

	<br />


	<b><?php echo CHtml::encode($dataProvider->getAttributeLabel('date')); ?>:</b>

	<?php echo CHtml::encode($dataProvider->date); ?>

	<br />

</div>

<?php else: echo "<br />".$dataProvider; ?>

<?php endif; ?>

In the first line I create an instance of User which is a model(non-module) and then renderPartial the create view of that. This is the create action of the User model




public function actionCreate()

	{

		$model=new User;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


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

		{

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

			if($model->save())

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

		}


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

			'model'=>$model,

		));

	}



Here is the view of the create action




$this->breadcrumbs=array(

	'Users'=>array('index'),

	'Create',

);


$this->menu=array(

	array('label'=>'List User', 'url'=>array('index')),

	array('label'=>'Manage User', 'url'=>array('admin')),

);

?>


<h1>Create User</h1>


<?php echo $this->renderPartial('application.views.user._form', array('model'=>$model)); ?>



I change the renderPartial parameter from


'_form'

to


'application.views.user._form'

because it rendered the Hadith _form view instead of User _form view

So, is the problem fixed now?

Also I recommend you to put the $model=new User() on Controller/action and not in view, according to the MVC architecture :)