Render View in a other View

Hi Guys

I've a little question.

Is it possible to render in a view an other view?

What is the best way?

The problem is, that i try to include the "admin" view from an other controller in the form view…

When I do this with renderPartial() it have of course a error:

Fatal error: Call to a member function link() on a non-object

I understand why this can't work but how can i get this work?

With the runController Function I've the problem that it renders the whole layout.

Thank you for help,

sorry for my english

Greetings gartenschlauch

Yes, using renderPartial is the preferred way. If you are using version 1.0.4, the link() problem should be gone.

hi qiang, thank you for your answer.

I'm using the newest version (1.0.4) but i think this problem is still here.

I want to create an Item (localhost/index.php?r=item/create)

In the _form.php i try to render the adminSite form an other Item

$this->renderPartial("/otherItem/admin");

but when i do this tehre is this error:

Fatal error: Call to a member function link() on a non-object in

Is this a bug?

What is the complete error message?

Just in the browser or in a log file?

In the browser:

Fatal error: Call to a member function link() on a non-object in pathToSite\protected\views\otherItem\admin.php on line 10

an on line 10 is:

<th><?php echo $sort->link('parameter'); ?></th>

It's because you don't have $sort variable in the view. The variable is passed to the view in admin action, but when you use renderPartial(), you didn't pass this variable to it.

:-\ i’m sorry

next time i will try to turn on my brain…

thanks for your help.

gartenschlauch

Hi again,

I've a question again and it's about the same topic, so I hope it's okay when i use this thread again.

When i rendered the AdminView from the otherItem, can I use a linkButton to fire an event in the otherItemController?

Before it was like this:

echo CHtml::linkButton('Delete',array(


      	  'submit'=>'',


      	  'params'=>array('command'=>'delete','id'=>$model->id),


      	  'confirm'=>"Are you sure to delete #{$model->id}?")); ?>

But what do I've to change, respectively is it possible?

Do i have to catch this command in the ItemController and then redirect it to the otherItemController?

or should i use a default link?

Thank you for help again

gartenschlauch

Hello,

I would like to do something similar. I want to render collection of other controllers view results on my current controller, but it seems to not be working.

[code=I'm trying to do something like this]for (…)

{

$newForms[] = TheOtherController::renderPartial('create',array('TheOther'=>$TheOther),true);

}

$this->render('create',array('item'=>$item,'newForms'=>$newForms));

[/code]

I would like to make one entity with some collection items, sadly active record and views doesn't support such features… Can anyone suggest me what to do?

Someone?

What is the correct way to get rendered information from another Controller?, how to use that controller? Is it posible?

yes yes - a similar question:

how do i query one entry for one of my models?

working through the Blog tutorial has been cool, but I am trying to expand my ability to be flexible with this

for instance:

i have my post model, and i want one of my entries in this model on my index page - how would I go about doing this?

i am fairly certain that it has something to do with render partial, and i am thinking that i need to send some values to the view that i include, but i cant completely figure that out -

basically - i was trying to pull something like this:

i created the _show.php file in my post views but i have no idea how to get this party started

any tips?

say for example that the id for my post is '9' - i want this one to appear somewhere

any tips?

Thanks

Peace

The following code should be fine, where $model refers to your post model instance. You can get this from your controller.

ahh cool

how would i specify which post i want to display tho?

i dont want to display every entry in my Model table - just one specific entry

like for example - if the id of the post i want to display is '9'

would i do something like this?

also

when i used that snippet of code, it still comes back telling me that

post is the model name

thanks for the help

You need to define $post, either by passing a variable named 'post' when you call render() in your controller action (preferred), or in your view, using code like the following:

that

is

awesome

everything works now

youre the man

Peace

related question:

how would you do the same thing, but within a module -

basically - getting a renderPartial from a view outside a module, and include it in one of the views in the module

example:

this piece of code works in my application:

       

	$static = Global_content::model()->findByPk(2);
		$this-&gt;renderPartial(&#039;/global_content/_show&#039;,array(


			&#039;static&#039;=&gt;$static,


		));</pre>

but it does not work when i try to use it inside my module

error:

DefaultController cannot find the requested view "/global_content/_show".

@backgammon : I am having the same problem when using $this->renderPartial in a module.

@admin : please answer this question : can we use renderPartial in module ?

In a module, if you want to reference a view outside of the module (this is bad practice!), you can use dot syntax. That is, use the path alias to the view. For example, 'application.views.site.index'

Quote

basically - getting a renderPartial from a view outside a module, and include it in one of the views in the module

Why not just use a widget?

Quote

In a module, if you want to reference a view outside of the module (this is bad practice!), you can use dot syntax. That is, use the path alias to the view. For example, 'application.views.site.index'

hmm… interesting -

can you explain the bad-practiceness of this?

thanks man