i have a form which is made with the help of 2 checkboxlist and textfield.i have no database table so i use CFormModel.in my form i also use checkall for the select of all checkbox ,this is work.but when i submit my form then i found
Error 400
Your request is invalid.
when i submit the form data reach to the controller in "actioncreate" using function
if(isset($_POST['Search'])
$model->attributes=$_POST['Search'];
here i have not the table so "id" is absent.then here how to select form data and sent to the "actionview and loadmodel" for the view the data in browser.
please anyone help me. I’m still new to Yii and struggling up the learning curve.
thanks
traprajith
(Traprajith)
November 26, 2012, 7:54am
2
please post your form and controller action.
traprajith
(Traprajith)
November 26, 2012, 7:56am
3
check out the rules first, in your controller
traprajith
(Traprajith)
November 27, 2012, 5:17am
6
the id will get only after saving the model, in this u r not saving the model,
u r passing the POST value as id to view, how it works??
$this->redirect(array('view','id'=>$value));
look at the action view
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
here needs the id, in ur case the &id is getting the whole post value, so the loadmodel($id) didnt works
dit u got the points??
the id will get only after saving the model, in this u r not saving the model,
u r passing the POST value as id to view, how it works??
$this->redirect(array('view','id'=>$value));
look at the action view
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
here needs the id, in ur case the &id is getting the whole post value, so the loadmodel($id) didnt works
dit u got the points??
a lot of thanks Rajith…
i get all the points as you told me.actually i have no id because i have no table so i use CFormModel. here i use id for the checking purpose data is pass or not ,if id use here i found that data is pass to the url.
now i want to pass this data to the view and action load without id.Is any way to do that if yes give me some suggestion.How to "actioncreate" pass the data to the "actionview" and "actionload" without using id…
traprajith
(Traprajith)
November 27, 2012, 6:43am
8
yes…
if u want to view the data
remove the loadmodel
pass the post value to the view as model
public function actionView($id)
{
$this->render('view',array(
'model'=>$id,
));
}
like this
i didnt get what ur actually purpose!!
traprajith
(Traprajith)
November 27, 2012, 6:57am
9
if u just want to see the post values in the view
u just renderpartial a view as u need
then u can change this
$this->redirect(array('view','id'=>$value));
to
example
$this->renderPartial('view', array('model'=>$value,'brand'=>$brand));
then u will get $model,$brand etc at the view…
yes…
if u want to view the data
remove the loadmodel
pass the post value to the view as model
public function actionView($id)
{
$this->render('view',array(
'model'=>$id,
));
}
like this
i didnt get what ur actually purpose!!
it is also not working .i want to call u if u r free rajith sir.give me reply pls…
traprajith
(Traprajith)
November 27, 2012, 7:12am
11
what is the error?
u will get $model at the view
change the view according to ur use
traprajith
(Traprajith)
November 27, 2012, 7:17am
12
if u r using like
$this->redirect(array('view','id'=>$value));
u r passing a big array through the url…did u notice that, u may use renderpartial
what is your purpose?
u just want to post some values from a form and want see the value in the view? is it?
want to implement a search?
if u r using like
$this->redirect(array('view','id'=>$value));
u r passing a big array through the url…did u notice that, u may use renderpartial
what is your purpose?
u just want to post some values from a form and want see the value in the view? is it?
want to implement a search?
ya i want to implement search.
i notice that when i pass $this->redirect(array(‘view’,‘id’=>$value)); then all data who i select go to the url.i want to that data go to the view.
traprajith
(Traprajith)
November 27, 2012, 7:27am
14
rajkumar000000:
ya i want to implement search.
i notice that when i pass $this->redirect(array(‘view’,‘id’=>$value)); then all data who i select go to the url.i want to that data go to the view.
so use renderpartial
u can renderpartial a view
check out the codes for create and update pages, u will get the idea
traprajith
(Traprajith)
November 27, 2012, 7:35am
15
<div class="row">
<?php echo $form->labelEx($model,'brand'); ?>
<?php echo $form->checkboxList($model, 'brand',$model->getBrandOptions(), array( 'checkAll' => 'SELECT ALL')); ?>
<?php echo $form->error($model,'brand'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'OS'); ?>
<?php echo $form->checkBoxList($model,'OS',$model->getOsOptions(),array( 'checkAll' => 'SELECT ALL')); ?>
<?php echo $form->error($model,'OS'); ?>
</div>
<h3> Price </h3>
<div class="row">
<?php echo $form->labelEx($model,'range'); ?>
<?php echo $form->textField($model,'range',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model,'range'); ?>
</div><div class="row">
<?php echo $form->labelEx($model,'to'); ?>
<?php echo $form->textField($model,'to',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model,'to'); ?>
</div>
u may change all these
use CHtml text fields and checkboxList, then u can avoid the model, to implement a simple search the model is not necessary thing
just need a form
create an action in the search controller
public function actionSearch()
{
$model=new Search;
if(isset($_POST['Search']))
{
//set ur search condition here
//then render the same form or another page here with the search values
}
$this->render('ur-form-page',array('model'=>$model));
}