I am new to Yii, I am using Yii version 1.1, I have tried to search forums and web for this answer, Please bear with me if I am asking a silly question here.
My Issue : I am using a view of a module. After that view I want to show one form of different module so that if someone submits it then data will be submitted and saved to database. I think the solution is using the Widgets (Please advise if you have better idea)
Now the Question is How can I use Widget to Display the form and after the form has been submitted the values should be stored in the database.
If you can give me some example also our can share some tutorial link that would also be great.
Thank you once again, Yes this tutorial I have read, this explains how we can show something (Recent Comments) using the widget, But the examples that you have given to me earlier helped me to some extents, thank you so much for your kind help. I really appreciate that. What I feel that there is a need of tutorial here which explains the widget in more detail, specially how to post something using the widget.
Thanks for your reply, but my scenario is different, I am not talking about the CRUD which is generated by Gii, Just think about the scenario, You have a view like Post and you want to add comments, So comments section (Block or Widget) can be called by some method in the view.
I have been reading lot of stuff here and as per the Yii Blog tutorial, by renderPartial method this can be accomplished. But I have been looking into other extensions, which has used the widgets methods for posting the form data. Please check here : http://www.yiiframework.com/doc/blog/1.1/en/comment.create
Actually I tried to comment on the above mentioned tutorial so that if the author have knowledge, then he can have some more information on how to post using the widgets, I am new and not allowed to post comments there.
The tutorial "Creating and Displaying Comments" seems to be the right for you.
If you want to handle POST data from a form (based on a model) you always have to implement steps like below:
Create a view, that displays the form with a submit button to send data to this controller action.
Create a corresponding controller action that handles the submitted data:
create a model: $comment=new Comment;
assign the $_POST data to the model attributes: $comment->attributes=$_POST[‘Comment’];
Validate/Save the model: if($comment->save())…
If no $_POST data from the form are submitted (or not valid or the model is not saved) render the form again with the model and the assigned attributes (display model errors).
Similar code is generated by gii in actionCreate.
If you understand the code generated by gii, you will understand the comment tutorial and you will be able to modify the code for your needs.
A widget is not needed, it cannot replace the controller action, only maybe display a form.
But why do you want to create a widget for displaying a form and not use renderPartial?