Yii Framework Forum: 2 Questions for forms - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

2 Questions for forms Rate Topic: -----

#1 User is offline   Cihan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 02-November 10

Posted 02 November 2010 - 01:52 PM

Hello community

I have two questions to forms in yii.

First Question: Whats the best practice to have a Form in each page side on the sidebar (e.g. Registration Form), this form should be shown in all controller sites etc. and it should validated etc with ajax. How can i solve this problem in best way in yii and with CFormModel and CActiveRecord?

Second Question: Unlike in Zend in yii it hasnt a Form Decorator. So whats the best practice to use a CFormModel or CActiveModel in two (or more) views (in different controllers) without to make for all always a _form.php view? How can I solve this problem to make the DRY princip? I dont want to make in each controller same form html code for the same form.

I hope very for helping to solve this two problems.

Thank you.

Cihan
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 03 November 2010 - 02:07 AM

For reuse part of views you can create widgets.

Those are simply class in components that extends CWidget.

You have to implement the function run, and you can render views that lies in component/views, see the documentation about this.

For a widget displayed in all pages, you can include this widget in views/layout/main.php
0

#3 User is offline   Cihan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 02-November 10

Posted 03 November 2010 - 03:03 AM

Hello

Thank you for your idea. I will use it!

Maybe you have also a idea about my other question: how can i handle this form in this widget? It submited value must be go to a controller? and how can i do this with ajax solution? This widget-form will be shown in all pages so it should work in all controller action pages etc.

Thank you for helping.

cihan
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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