mundiyani
(Sammundiyani)
April 8, 2011, 6:50am
1
Hi, guys.
I’m working with CJuiTabs which will create tabs in layout.
How can I use renderPartial a file in another controller’s view folder to include a view into each tab?
I’d tried follwing code:
$this->widget('zii.widgets.jui.CJuiTabs', array(
'tabs'=>array(
'Organisation' =>$this->renderPartial("_form", array('model' => $model), $this),
'Contact Person' =>$this->renderPartial("contactPerson/_form", array('model' => $model), $this),
'Address' =>$this->renderPartial("address/_form", array('model' => $model), $this),
),
'options'=>array(
'collapsible'=>true,
),
));
Now I am getting the following error:
AbcController cannot find the requested view "contactPerson/_form".
and AbcController cannot find the requested view "Address/_form".
My view path is: /protected/views/contactPerson and /protected/views/address
Thanks in advance.
zaccaria
(Matteo Falsitta)
April 8, 2011, 7:26am
2
Is not a good practice to use view from different controller.
If you want to re-use a view (or maybe just a part of) create a widget.
Add a class in components:
public class myWidget extends CWidget
{
public function run()
{
$this->render('myWidgetView');
}
}
The view should be placed in protected/components/view.
With this schema you can move any eventually shared controller’s code in the function run.
tyohan
(Tyohan)
April 14, 2011, 2:27am
4
Try renderFile
Yii::app()->controller->renderFile(Yii::app()->basePath.'/<your-view-location-path>',$params);
lygmqkl
(Lygmqkl)
April 14, 2011, 5:32am
5
renderPartial("/contactPerson/_form",
pimshtein
(Pimshtein)
October 16, 2013, 1:54pm
6
zaccaria:
Is not a good practice to use view from different controller.
If you want to re-use a view (or maybe just a part of) create a widget.
Add a class in components:
public class myWidget extends CWidget
{
public function run()
{
$this->render('myWidgetView');
}
}
The view should be placed in protected/components/view.
With this schema you can move any eventually shared controller’s code in the function run.
zaccaria, не могли бы ответить на вопрос, связанный с этой темой?
Есть необходимость в разных представлениях подключать набор разных виджетов. То есть компоновать этот набор из нескольких стандартных. Есть идея использовать renderPartial, но вы пишете что это плохая практика и лучше использовать переопределение виджетов. Можете объяснить почему или дать ссылку, чтобы почитать об этом?
zaccaria
(Matteo Falsitta)
October 17, 2013, 6:22am
7
I speak russian quite well, but I write it very slow, so I prefer to answer in english (also other users in the forum can read it).
Widget are more powerfull, the can easiliy customized by adding property and can manage input, like for example a login widget you show in each page.
Take a look at the doc here and this example of usage
pimshtein
(Pimshtein)
October 17, 2013, 11:57am
8
zaccaria:
I speak russian quite well, but I write it very slow, so I prefer to answer in english (also other users in the forum can read it).
Widget are more powerfull, the can easiliy customized by adding property and can manage input, like for example a login widget you show in each page.
Take a look at the doc here and this example of usage
Thank you very much!
I asked about this at Alexander Makarov (it is one of the core developers Yii). He said that you can use as widgets and renderPartial. Without a difference.
logos010
(Logos010)
April 26, 2014, 7:56am
9
This works for me:
$this->renderPartial('application.modules.news.views.admin.view_file', array());
You have to identify as the tree folder like this: protected/modules/news/views/view_file.php
Regards,
in View file call widget like
<?php
$this->Widget('recruitment.components.caseDetails',array(
'caseId' => $case_id,
));
?>
file path : protected/modules/recruitment/components/CaseDetails.php
class CaseDetails extends CWidget {
$this->render(’_showCaseDetails’,array(‘model’ => $case),false,true);
}
File path : protected/modules/recruitment/components/_showCaseDetails.php
#this will call view file of my module.
Yii::app()->controller->renderPartial(‘application.modules.recruitment.views.recruitment._view’, array(‘model’ => $model) );
phpdevacc
(Php Dev Acc)
September 18, 2015, 6:53am
11
logos010:
This works for me:
$this->renderPartial('application.modules.news.views.admin.view_file', array());
You have to identify as the tree folder like this: protected/modules/news/views/view_file.php
Regards,
This works for me like charm!!!