How can I display a warning message on textfield in Yii - yii

I'm new to Yii framework and I need to display the validation error message as in login form "Username cannot be blank". Now, I have a text field where I updated the fields and the during validation I want a message to be displayed. How can I do this?
Controller
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// set the parameters for the bizRule
$params = array('GroupzSupport'=>$model);
// now check the bizrule for this user
if (!Yii::app()->user->checkAccess('updateSelf', $params) &&
!Yii::app()->user->checkAccess('admin'))
{
throw new CHttpException(403, 'You are not authorized to perform this action');
}
else
{
if(isset($_POST['GroupzSupport']))
{
$password_current=$_POST['GroupzSupport']['password_current'];
$pass=$model->validatePassword($password_current);
$model->attributes=$_POST['GroupzSupport'];
if($pass==1)
{
$model->password = $model->hashPassword($_POST['GroupzSupport']['password_new']);
if($model->save())
$this->redirect(array('/messageTemplate/admin'));
}
else {$errors="Incorrect Current password"; print '<span style="color:red"><b>';
print '</b><b>'.$errors;
print '</b></span>';}
}
$this->render('update',array(
'model'=>$model,
));
}
}
View
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'password-recovery-reset-password-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="row"><?php
echo $form->labelEx($model,'username');
echo $form->textField($model,'username',array('size'=>45,'maxlength'=>150));
echo $form->error($model,'username');
?></div>
<div class="row">
<?php echo $form->labelEx($model,'current password'); ?>
<?php echo $form->passwordField($model,'password_current',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'password_current'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'new password'); ?>
<?php echo $form->textField($model,'password_new',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'password_new'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'confirm new password'); ?>
<?php echo $form->passwordField($model,'password_repeat',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'password_repeat'); ?>
</div>
<div class="row buttons"><?php
echo CHtml::submitButton('Reset Your Password');
?></div><?php
$this->endWidget(); ?>
</div>
Now currently I'm displaying it at the top.
I want to display it right on the textfield as in login page. How can I do this?

Before redirect, add the message to the desired field.
In the model Validator:
$this->addError('field_name', "Message error.");
Or in Controller action:
$model->addError('field_name', "Message error.");

Related

use of email format in yii

I am able to send simple email to receiver.Now i have to be able to select a email format from existing different formats and this template must appear in my message box.i should also be able to change the content of the template that appears in message box before sending to receiver.How to do this?
My code for view form
<div class="form wide">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'mail-form',
'enableAjaxValidation'=>true,
'htmlOptions' => array('enctype' => 'multipart/form-data'), // ADD THIS
)); ?>
<div class="row col2">
<?php echo $form->labelEx($model,'email_from'); ?>
<?php echo $form->textField($model,'email_from',array('size'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>
<?php echo $form->error($model,'email_from'); ?>
</div>
<div class="row col2">
<?php echo $form->labelEx($model,'email_to'); ?>
<?php echo $form->textField($model,'email_to',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'email_to'); ?>
</div>
<div style="clear:both"></div>
<div class="row col2">
<?php echo $form->labelEx($model,'subject'); ?>
<?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>250)); ?>
<?php echo $form->error($model,'subject'); ?>
</div>
<div style="clear:both"></div>
<div class="row col2">
<?php echo $form->labelEx($model,'message'); ?>
<?php echo $form->textArea($model,'message',array('style'=>'width: 680px; height: 300px;')); ?>
<?php echo $form->error($model,'message'); ?>
</div>
<div style="clear:both"></div>
<div class="row buttons">
<?php
echo CHtml::submitButton($model->isNewRecord ? 'Send' : 'Send',array('class' => 'btn'));
?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Try below code:
public function actionContact() {
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$status = Yii::$app->mailer->compose()
->setTo($model->email_to)
->setFrom([$model->email_from => $model->email_from])
->setSubject($model->subject)
->setTextBody($model->message)
->send();
if ($status) {
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
} else {
Yii::$app->session->setFlash('error', 'There was an error sending email.');
}
return $this->refresh();
} else {
return $this->render('contact', [
'model' => $model,
]);
}
}
You can also create a email_template directory under views folder and create template file in which you can set email template content.
you can use js or ajax to do the same.
1: Use jQuery:
I assume that you are using jQuery. So use ajax.
.......JS Cod........
/*I assume that you have your template data in an attribute like data-template-data=""*/
$('#select_template_id').chang(function(){
template=$(this).attr('data-template-data');
$('#template_edit_box').val(template);
});

Issue to open dialog: Yii

I have used ajaxSubmitButton in my form.On click of button i am trying to open dialog When i click the button ,the dialog opens and it displays entire code written for that form . How to resolve this?
my code for button is :
<div class="btnalign" style="margin-top: 20px;margin-left:20px;">
<?=CHtml::ajaxSubmitButton('Mail to Client', Yii::app()->createUrl('reply/composeMail'),
array('type'=>'POST',
'data'=> 'js:{"data1":callData()}',
//'success' => 'function(response){afterSubmitForm(response);}'
'success'=>'js:function(string){ alert(string);$.fn.yiiGridView.update("my-grid"); }'
),
array('class' => 'btn btn-primary'));
?>
</div>
my controller code:
public function actionComposeMail()
{
if(Yii::app()->request->isAjaxRequest){
print_r($_POST['data1']);
if(isset($_POST['data1'])){
$model=new Reply;
$model->scenario = 'compose';
EQuickDlgs::render('_compose',array(
'model'=>$model,
));
}else{
echo "Please select row to Mail.";
}
}
else
{
echo "The request is invalid.";
}
}
my dialog form code is:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'reply-form',
'enableAjaxValidation'=>true,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.For multiple recipients please seperate by comma</p>
<?php echo $form->errorSummary($model); ?>
<div class="row col2">
<?php echo $form->labelEx($model,'email_from'); ?>
<?php echo $form->textField($model,'email_from',array('size'=>50,'maxlength'=>50,'readonly'=>'readonly')); ?>
<?php echo $form->error($model,'email_from'); ?>
</div>
<div class="row col2">
<?php echo $form->labelEx($model,'email_to'); ?>
<?php echo $form->textField($model,'email_to',array('size'=>60,'maxlength'=>150)); ?>
<?php echo $form->error($model,'email_to'); ?>
</div>
<div style="clear:both"></div>
<div class="row col2">
<?php echo $form->labelEx($model,'email_cc'); ?>
<?php echo $form->textField($model,'email_cc',array('size'=>60,'maxlength'=>250)); ?>
<?php echo $form->error($model,'email_cc'); ?>
</div>
<div class="row col2">
<?php echo $form->labelEx($model,'subject'); ?>
<?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>250)); ?>
<?php echo $form->error($model,'subject'); ?>
</div>
<div style="clear:both"></div>
<div class="row">
<?php echo $form->labelEx($model,'message'); ?>
<?php echo $form->textArea($model,'message',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'message'); ?>
</div>
<div style="clear:both"></div>
<div style="clear:both"></div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Send' : 'Send',array('class' => 'btn')); ?>
</div>
<?php $this->endWidget(); ?>
Image of dialog
You must use renderPartial() instead of render() and try to call Yii::app()->end() at the end in your mail form view
public function actionComposeMail()
{
if(Yii::app()->request->isAjaxRequest){
print_r($_POST['data1']);
if(isset($_POST['data1'])){
$model=new Reply;
$model->scenario = 'compose';
$this->renderPartial('_compose',array(
'model'=>$model,
));
}else{
echo "Please select row to Mail.";
}
}
else
{
echo "The request is invalid.";
}
}

Duplicate insert when ajaxvalidation is true

Im having this weird problem that causes my model to double insert into the database when ajaxvalidation is on for my form. I dont understand why this happens, but this keeps on conflicting with my custom validation and I cannot move on. Can someone enlighten me on the problem.
Model:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('category, ppmp_id', 'numerical', 'integerOnly'=>true),
array('category','required'),
array('q1, q2, q3, q4', 'numerical'),
array('category', 'myTestUniqueMethod'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('item_id, category, q1, q2, q3, q4, ppmp_id', 'safe', 'on'=>'search'),
);
}
public function myTestUniqueMethod($attribute,$params)
{
$sql = 'SELECT *
FROM ppmp_item
WHERE ppmp_id='.$this->ppmp_id.'and category='.$this->category;
$unique = Yii::app()->db->createCommand($sql)->queryRow();
if ($unique)
{
$this->addError('category', "Category already added to PPMP");
}
}
View:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'ppmp-item-form',
'enableAjaxValidation'=>true,
)); ?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'category'); ?>
<?php
$data=PhilgepsCategory::model()->findAll();
$data=CHtml::listData($data,'id','class_name');
echo $form->dropDownList($model,'category',$data,array('options' => array('1'=>array('selected'=>true))));
?>
<?php echo $form->error($model,'category'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'q1'); ?>
<?php echo $form->textField($model,'q1'); ?>
<?php echo $form->error($model,'q1'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'q2'); ?>
<?php echo $form->textField($model,'q2'); ?>
<?php echo $form->error($model,'q2'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'q3'); ?>
<?php echo $form->textField($model,'q3'); ?>
<?php echo $form->error($model,'q3'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'q4'); ?>
<?php echo $form->textField($model,'q4'); ?>
<?php echo $form->error($model,'q4'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
Controller:
public function actionCreate($ppmp,$bal)
{
$model=new PpmpItem;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['PpmpItem']))
{
$model->attributes=$_POST['PpmpItem'];
$model->ppmp_id = $ppmp;
$valid=$model->validate();
if($valid)
if($model->save())
$this->redirect(array('ppmp/view','id'=>$ppmp));
}
$this->render('create',array(
'model'=>$model,
'ppmp'=>$ppmp,
'bal'=>$bal,
));
}
The problem is that you shouldn't execute save() method when validating, because it will save when doing the ajax validation and when sending the data trough the form, so, you should do something like this:
...
...
if(isset($_POST['ajax']) && $_POST['ajax']==='ppmp-item-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
$valid=$model->validate();
if($valid)
if($model->save())
...
...
This is the same that gii uses to validate using ajax.

Yii CJuiDialog isn't being recognized

I've went through this tutorial http://www.yiiframework.com/wiki/561/ajax-login-form-with-validation-errors-inside-jquery-modal-dialog/ It appears to be functioning properly, but instead of the form being in the modal dialog, it just renders it right on the page like zii.widgets.jui.CJuiDialog isn't even there.
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'login-dialog',
'options'=>array(
'title'=>'Login',
'autoOpen'=>false,
),
));?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'user_login_form',
'enableAjaxValidation'=>false,
'enableClientValidation'=>true,
'method' => 'POST',
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>true,
'validateOnType'=>false,
),
)); ?>
<h1>
Login</h1>
<p>
Please fill out the following form with your login credentials:</p>
<p class="note">
Fields with <span class="required">*</span> are required.</p>
<div id="login-error-div" class="errorMessage" style="display: none;">
</div>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username',array("onfocus"=>"$('#login-error- div').hide();")); ?>
<?php //echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password',array("onfocus"=>"$('#login-error- div').hide();")); ?>
<?php //echo $form->error($model,'password'); ?>
<p class="hint">
Hint: You may login with <tt>demo/demo</tt>.
</p>
</div>
<div class="row rememberMe">
<?php echo $form->checkBox($model,'rememberMe'); ?>
<?php echo $form->label($model,'rememberMe'); ?>
<?php echo $form->error($model,'rememberMe'); ?>
</div>
<div class="row submit">
<?php echo CHtml::ajaxSubmitButton(
'Sign In',
array('/site/login.GetLogin'),
array(
'beforeSend' => 'function(){
$("#login").attr("disabled",true);
}',
'complete' => 'function(){
$("#user_login_form").each(function(){ this.reset();});
$("#login").attr("disabled",false);
}',
'success'=>'function(data){
var obj = jQuery.parseJSON(data);
// View login errors!
// alert(data);
if(obj.login == "success"){
$("#user_login_form").html("<h4>
Login Successful! Please Wait...</h4>
");
parent.location.href = "/";
}
else{
$("#login-error-div").show();
$("#login-error-div").html("Login failed! Try again.");$("#login-error-div").append("
");
}
}'
),
array("id"=>"login","class" => "btn btn-primary")
); ?>
</div>
<?php $this->endWidget(); ?>
</div>
<!-- form -->
<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
Its suppose to render like this above so when i click the link below it opens
echo CHtml::link('Login', array('/site/login.GetLogin'), array('onclick'=>'$("#login-dialog").dialog("open"); return false;'));
Its built in a widget, if you have a look at the tutorial. Here's the complete widget
<?php
class loginProvider extends CWidget{
public static function actions(){
return array(
'GetLogin'=>'application.components.actions.getLogin',
);
}
public function run(){
$this->renderContent();
}
protected function renderContent(){
echo '<span style="float:right;">';
if(Yii::app()->user->isGuest){
echo CHtml::link('Login', array('/site/login.GetLogin'), array('onclick'=>'$("#login-dialog").dialog("open"); return false;'));
echo '</span>';
$this->getController()- >renderPartial('application.components.views.login',array('model'=>new LoginForm));
}
else
echo CHtml::link('Logout ('.Yii::app()->user->name.')', array('site/logout'), array('visible'=>!Yii::app()->user->isGuest));
echo '</span>';
}
}

yii controller can't set post

friends!
i generated a dynamic product field and quantity filed with javascript in order customer makes ordering over one product. but why does controller can't set POST['OrderDetail']? the controller can save only one model, Order.
Please help to correct me.
I have four models: Product, Customer, Order, and Order_detail.
view/order/_form.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'order-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'customer_id'); ?>
<?php //echo $form->textField($model,'customer_id'); ?>
<?php echo $form->dropDownList($model,'customer_id',CHtml::listData(Customers::model()->findAll(),'customer_id','fullname'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error($model,'customer_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'order_status'); ?>
<?php echo $form->textField($model,'order_status'); ?>
<?php //echo $form->dropDownList($model,'order_id', array(1=>'Pending', 2=>'Processing',3=>'Completed'));?>
<?php echo $form->error($model,'order_status'); ?>
</div>
<?php /*?>
<div class="row">
<?php echo $form->labelEx($model,'lat'); ?>
<?php echo $form->textField($model,'lat'); ?>
<?php echo $form->error($model,'lat'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'lng'); ?>
<?php echo $form->textField($model,'lng'); ?>
<?php echo $form->error($model,'lng'); ?>
</div>
<?php */?>
<div class="row">
<?php echo $form->labelEx($model,'address'); ?>
<?php echo $form->textField($model,'address',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'address'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'staff_id'); ?>
<?php //echo $form->textField($model,'staff_id'); ?>
<?php echo $form->dropDownList($model,'staff_id',CHtml::listData(Staff::model()->findAll(),'staff_id','fullname'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error($model,'staff_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'received_date'); ?>
<?php echo $form->textField($model,'received_date'); ?>
<?php echo $form->error($model,'received_date'); ?>
</div>
<script type="text/javascript">
function addProduct() {
var ni = document.getElementById('divProduct');
var numi = document.getElementById('countLastInput');
var num = (document.getElementById('countLastInput').value -1)+ 2;
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = num;
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = <?php echo $form->dropDownList($orderdetail,'product_id',CHtml::listData(Products::model()->findAll(),'product_id','product_name'),
array('empty' => '--- Choose---','name'=>'productorder[]')); ?>+<?php echo $form->textField($orderdetail,'qty', array('name'=>'qtyorder[]')); ?>+'Remove';
ni.appendChild(newdiv);
}
function removePhoto(divNum) {
var d = document.getElementById('divProduct');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
var minus=document.getElementById('countLastInput').value;
document.getElementById('countLastInput').value=minus-1;
}
</script>
<div id="divProduct"> </div>
<input type="button" name="service_photo" value="Add Product" class="Allbutton" onclick="addProduct();" />
<input type="hidden" value="0" id="countLastInput" name="countLastInput" />
<?php /*?>
<div class="row">
<?php echo $form->labelEx($orderdetail,'product_id'); ?>
<?php echo $form->dropDownList($orderdetail,'product_id',CHtml::listData(Products::model()->findAll(),'product_id','product_name'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error($orderdetail,'product_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($orderdetail,'qty'); ?>
<?php echo $form->textField($orderdetail,'qty'); ?>
<?php echo $form->error($orderdetail,'qty'); ?>
</div>
<?php /*?>
<?php //$orderdetail=new OrderDetail();?>
<?php //echo $this->renderPartial("_partial_order",array('orderdetail'=>$orderdetail));?>
<?php /* ?><form action="php_multiple_textbox4.php" method="post" name="form1">
<input type="text" name="txtSiteName[]">
<input name="btnButton" type="button" value="+" onClick="JavaScript:fncCreateElement();"><br>
<span id="mySpan"></span>
<input name="btnSubmit" type="submit" value="Submit">
</form>
<?php */?>
<?php /*?>
<div class="row">
<?php echo $form->labelEx($model,'completed_date'); ?>
<?php echo $form->textField($model,'completed_date'); ?>
<?php echo $form->error($model,'completed_date'); ?>
</div>
<?php */?>
<?php /*?>
<div class="row">
<?php echo $form->labelEx($model,'created_date'); ?>
<?php echo $form->textField($model,'created_date'); ?>
<?php echo $form->error($model,'created_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'upated_date'); ?>
<?php echo $form->textField($model,'upated_date'); ?>
<?php echo $form->error($model,'upated_date'); ?>
</div>
<?php */?>
<?php /*?>
<table id="students">
<thead>
<tr>
<td>Product Name</td>
<td>Quantity</td>
<td>
<?php echo CHtml::link('<b>Add Product</b>', '', array('onClick'=>'addProduct($(this))', 'class'=>'add'));?>
</td>
</tr>
</thead>
</table>
<input type="hidden" value="0" id=lastInput name="lastInput" />
<?php */?>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
OrderController.php
<?php
class OrderController extends Controller
{
/**
* #var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';
public $orderid;
/**
* #return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* #return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','showlog'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('*'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('*'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
/**
* Displays a particular model.
* #param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionShowLog(){
//Yii::log("hi, h r u?" ,"trace","application.controllers.OrderController");
var_dump(Yii::getLogger()->getLogs());
//Yii::trace("The actionCreate() method is being requested","application.controllers.OrderController");
}
public function actionCreate()
{
$model=new Order;
$orderdetail=new OrderDetail();
$product=new Products();
$date=date('y-m-d');
// Uncomment the following line if AJAX validation is needed
//$this->performAjaxValidation(array($model,$orderdetail));
if(isset($_POST['Order']))
{
$model->attributes=$_POST['Order'];
$model->lat='12.53';
$model->lng='13.2';
$model->completed_date=$date;
$model->received_date=$date;
$model->created_date=$date;
$model->upated_date=$date;
if($model->save())
{
Yii::log("order save","info","application.controllers.OrderController");
if(isset($_POST['OrderDetail'])){
for($i=1;$i<count($_POST['productorder']);$i++){
//$orderdetail->attributes=$_POST['OrderDetail'];
$orderdetail->product_id=$_POST['productorder'][$i];
$orderdetail->qty=$_POST['qtyorder'][$i];
$orderdetail->order_id= $model->order_id;
$orderdetail->order_item_status=1;
$orderdetail->created_date=$date;
$orderdetail->updated_date=$date;
$orderdetail->save();
}
$this->redirect(array('view','id'=>$model->order_id));
//$qty=$orderdetail->qty=$_POST['qty'];
//$productid=$orderdetail->product_id=$_POST['txtproduct'];
/*
for($i=1;$i<=count($qty);$i++){
$orderdetail->order_id= $model->order_id;
$orderdetail->order_item_status=1;
$orderdetail->created_date=$date;
$orderdetail->updated_date=$date;
$orderdetail->product_id=1;
//$orderdetail->qty=$qty[$i];
//$orderdetail->save();
var_dump($_POST['qty']);
}
$this->redirect(array('view','id'=>$model->order_id));
*/
}else{
Yii::log("Failed ordedetails","warning","application.controllers.OrderController");
}
//$OrderDetailController=new OrderDetail();
//$this->redirect(array('OrderDetail/create'));
}
}
$this->render('create',array(
'model'=>$model,
'orderdetail'=>$orderdetail,
'product'=>$product,
));
}
/*
public function actionCreate()
{
Yii::import('ext.multimodelform.MultiModelForm');
$model = new Order;
$orderdetail=new OrderDetail();
$product=new Products();
$validatedMembers = array(); //ensure an empty array
if(isset($_POST['Order']))
{
$model->attributes=$_POST['Order'];
if( //validate detail before saving the master
MultiModelForm::validate($model,$validatedMembers,$deleteItems) &&
$model->save()
)
{
//the value for the foreign key 'groupid'
$masterValues = array ('order_id'=>$model->order_id);
if (MultiModelForm::save($model,$validatedMembers,$deleteMembers,$masterValues))
$this->redirect(array('view','id'=>$model->order_id));
}
}
$this->render('create',array(
'model'=>$model,
//submit the member and validatedItems to the widget in the edit form
'orderdetail'=>$orderdetail,
'product'=>$product,
'validatedMembers' => $validatedMembers,
));
}
*/
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* #param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$date=date('y-m-d');
$model=$this->loadModel($id);
//$orderdetail=new OrderDetail();
$product=new Products();
$orderdetail=OrderDetail::model()->findByAttributes(array('order_id'=>$_GET['id']));
//$product->findByAttributes(array('order_id'=>$_GET['id']));
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Order']))
{
$model->attributes=$_POST['Order'];
$model->lat='12.53';
$model->lng='13.2';
$model->completed_date=$date;
$model->received_date=$date;
$model->created_date=$date;
$model->upated_date=$date;
if($model->save())
if(isset($_POST['OrderDetail'])){
$orderdetail->attributes=$_POST['OrderDetail'];
$orderdetail->order_id= $model->order_id;
$orderdetail->order_item_status=1;
$orderdetail->created_date=$date;
$orderdetail->updated_date=$date;
if($orderdetail->save())
$this->redirect(array('view','id'=>$model->order_id));
}
}
$this->render('update',array(
'model'=>$model,
'orderdetail'=>$orderdetail,
'product'=>$product,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* #param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Order');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new Order('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Order']))
$model->attributes=$_GET['Order'];
$this->render('admin',array(
'model'=>$model,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* #param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model=Order::model()->findByPk((int)$id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
//$model=Order::model()->with(Products::model(),OrderDetail::model())->findByPk((int)$id);
// if($model===null)
// throw new CHttpException(404,'Page not found.');
//return $model;
}
/**
* Performs the AJAX validation.
* #param CModel the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='order-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
Thanks in advance.
Try to enable CWebLogRoute to see if you have any security issues.
Yii wiki: How to log and debug variables using CWebLogRoute