Yii Framework Forum: Render View in a other View - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • This topic is locked

Render View in a other View Rate Topic: -----

#1 User is offline   gartenschlauch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 13-April 09

Posted 13 April 2009 - 04:52 AM

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
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,880
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 April 2009 - 05:52 AM

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

#3 User is offline   gartenschlauch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 13-April 09

Posted 13 April 2009 - 07:07 AM

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?
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,880
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 April 2009 - 07:23 AM

What is the complete error message?
0

#5 User is offline   gartenschlauch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 13-April 09

Posted 13 April 2009 - 08:01 AM

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>
0

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,880
  • Joined: 04-October 08
  • Location:DC, USA

Posted 13 April 2009 - 08:07 AM

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.
0

#7 User is offline   gartenschlauch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 13-April 09

Posted 13 April 2009 - 08:39 AM

:-\ i'm sorry
next time i will try to turn on my brain...

thanks for your help.

gartenschlauch
0

#8 User is offline   gartenschlauch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 13-April 09

Posted 14 April 2009 - 01:33 PM

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
0

#9 User is offline   Justforfun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-January 09

Posted 27 April 2009 - 02:12 PM

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?
0

#10 User is offline   Justforfun 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-January 09

Posted 28 April 2009 - 01:25 PM

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

#11 User is offline   backgammon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-March 09

Posted 30 April 2009 - 04:19 PM

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
0

#12 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,880
  • Joined: 04-October 08
  • Location:DC, USA

Posted 30 April 2009 - 04:21 PM

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




0

#13 User is offline   backgammon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-March 09

Posted 30 April 2009 - 04:38 PM

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
0

#14 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,880
  • Joined: 04-October 08
  • Location:DC, USA

Posted 30 April 2009 - 06:59 PM

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:

0

#15 User is offline   backgammon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-March 09

Posted 30 April 2009 - 07:05 PM

that
is
awesome


everything works now

youre the man

Peace
0

#16 User is offline   backgammon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-March 09

Posted 05 May 2009 - 03:48 PM

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->renderPartial('/global_content/_show',array(
'static'=>$static,
));


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

error:

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



0

#17 User is offline   dungdeveloper 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 18-February 09
  • Location:ho chi minh city

Posted 25 June 2009 - 03:41 AM

@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 ?
0

#18 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,880
  • Joined: 04-October 08
  • Location:DC, USA

Posted 25 June 2009 - 09:12 AM

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'
0

#19 User is offline   smclark89 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 119
  • Joined: 20-June 09
  • Location:NY, USA

Posted 25 June 2009 - 09:43 AM

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?
0

#20 User is offline   backgammon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-March 09

Posted 29 June 2009 - 11:32 AM

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
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users