Hi, I'm trying to validate active filefield fields that were created in Yii so dynamic.
I build using a forech for this inputs, the question is that when trying to validate when the user selects an image, indicate whether the file you chose is above the allowed weight, and also if it is a correct file format.
But i don't know that I'm doing wrong.
I tried this:
My model
public $image;
public function tableName() {
return 'vrf_image';
}
/**
* #return array validation rules for model attributes.
*/
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id_form', 'numerical', 'integerOnly'=>true),
// Pruebas para subir imagen
// Inicio
array(
'image',
'file',
'types'=>'jpg, gif, png',
'allowEmpty'=>true,
'on'=>'update',
'on'=>'insert',
'wrongType'=>'Solo imagenes',
'mimeTypes' => 'image/gif, image/jpeg, image/png',
'wrongMimeType' => 'Invalid mime type',
'maxSize'=>1024*1024*2,
'tooLarge'=>'File has to be smaller than 2MB',
),
array(
'image',
'length',
'max'=>50,
'on'=>'insert,update'
),
array(
'id, image, id_form, id_ques',
'safe',
'on'=>'search'
),
// Fin
);
}
My views
<div class="container-fluid">
<div class="row paddings_bottom">
<?php
$hoho = VrfImage::model()->findAll("id_form = $search->id");
$formImage=$this->beginWidget('CActiveForm', array(
'id'=>'verification-form-image',
'action' => Yii::app()->createUrl("backendVerification/default/CreateImage?id=".$modUser->id),
'htmlOptions' => array('enctype' => 'multipart/form-data'),
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>true,
'validateOnType'=>true,
),
));
?>
<div class="col-md-12 col-lg-12">
<table class="table table-bordered" style="margin-bottom: 0;">
<?php
$oo = 0; $ban = 0;
foreach ($numQues as $ii => $NQ){
if($ii==0){
echo '<div class="borTopFormVrf"><span class="White">Company Documentation</span></div>';
}
if($ii <6){
if($oo<2){
if($oo==0){
echo '<tr>';
}
?>
<td class="col-md-6 col-lg-6 nopadd" style="border: 1px solid #000;">
<?php
foreach ($hoho as $key => $value) {
if($hoho[$key]->id_ques == $NQ){
echo '<img src="'.getThemeUri().'/../../VerificationResource/images/'.$hoho[$key]->image.'" style="max-width:100%;">';
$ban = 1;
}
}
if($ban!=1){ echo '<img src="#" style="max-width:100%; visibility: hidden;" id="img_prev'.$ii.'" alt="your image"/>'; }
else{ $ban=0; }
?>
<?php echo $form->HiddenField($modImage,"[".$ii."]id_ques",array('value'=>$NQ)); ?>
<?php echo $formImage->fileField($modImage,'['.$ii.']image', array('class'=>'form-control Borf-c', 'onChange'=>'readURL(this,'.$ii.')')); ?>
<?php echo $formImage->error($modImage,'['.$ii.']image'); ?>
<div class="text-center">
<?php echo $nameQues[$ii]; ?>
</div>
</td>
<?php if($oo==1){ echo '</tr>'; $oo = -1; }
$oo++;
}}
}
?>
</table>
</div>
<div class="col-md-12 col-lg-12">
<div class="col-md-12 col-lg-12 divTopFormBVrf">
<?php
if(isset($search->id_verifier)){
if($search->id_verifier == userID()){
echo CHtml::submitButton('Save', array('class' => 'btn btn-success btn_create_address btn_create_address_size'));
}
}
?>
</div>
</div>
<?php $this->endWidget(); ?>
</div>
In my controller
public function actionCreateImage($id) {
$form = VrfForm::model()->find("id_user = $id");
$path_picture = realpath(Yii::app()->getBasePath()."/../VerificationResource/images")."/"; //ruta final de la imagen
if(isset($_POST['VrfImage'])) {
foreach ($_POST['VrfImage'] as $key => $value) {
$modImage = new VrfImage;
$modImage->attributes = $value;
//print_r($modImage->validate());
if($modImage->validate()){
echo 'Correcto';
////////////////////////////////////////////////////////////////////
$rnd = rand(0,9999); // generar números aleatorios entre 0-9999
$uploadedFile=CUploadedFile::getInstance($modImage,'['.$key.']image');
$fileName = "{$rnd}-{$uploadedFile}"; // número aleatorio + nombre de archivo, o se puede usar: $fileName=$uploadedFile->getName();
if(!empty($uploadedFile)) { // Compruebe si el archivo se ha subido o no.
$uploadedFile->saveAs($path_picture.$fileName);
$modImage->image = $fileName;
$modImage->id_ques = $value['id_ques'];
$modImage->id_form = $form->id;
if($modImage->save()) {
//echo ' REVISA!!! <br>';
}
else{
echo $modImage->error();
}
}
////////////////////////////////////////////////////////////////////
}
else{
echo 'Falla';
//$this->redirect($this->createUrl('default/Form'));
}
}
}
//$this->redirect(Yii::app()->user->returnUrl.'backendVerification/default/Form?id='.$id);
}
But don't It does not work.!!!
Is bad my "clientOptions" in the form?
Is bad my rules in the model?
Help T.T
Well, I knew not to use Yii to achieve validate my fields. It will not be the best way, but I ended up with this for the validation I needed.
<div class="container-fluid">
<div class="row paddings_bottom">
<?php
$hoho = VrfImage::model()->findAll("id_form = $search->id");
$formImage=$this->beginWidget('CActiveForm', array(
'id'=>'verification-form-image',
'action' => Yii::app()->createUrl("backendVerification/default/CreateImage?id=".$modUser->id),
'htmlOptions' => array('enctype' => 'multipart/form-data'),
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>true,
'validateOnType'=>true,
),
));
?>
<div class="col-md-12 col-lg-12">
<table class="table table-bordered" style="margin-bottom: 0;">
<?php
$numQues = [11,22,33,44,55,66,77,88,99,111,222,333];
$nameQues = ['Business license','Company code','Tax register','Export license','Joint venture approved certificate','Land certificate','ISO9001:2008','ISO14001;2004','UL certificate','CE certificate','Quality manual','Quality organization'];
$oo = 0; $ban = 0;
foreach ($numQues as $ii => $NQ){
if($ii==0){
echo '<div class="borTopFormVrf"><span class="White">Company Documentation</span></div>';
}
if($ii <6){
if($oo<2){
if($oo==0){
echo '<tr>';
}
?>
<td class="col-md-6 col-lg-6 nopadd" style="border: 1px solid #000;">
<?php
foreach ($hoho as $key => $value) {
if($hoho[$key]->id_ques == $NQ){
echo '<img src="'.getThemeUri().'/../../VerificationResource/images/'.$hoho[$key]->image.'" style="max-width:100%;">';
$ban = 1;
}
}
if($ban!=1){
echo '<img src="#" style="visibility: hidden;" id="img_prev'.$ii.'" alt="your image"/>';
}
else{ $ban=0; }
?>
<?php echo $form->HiddenField($modImage,"[".$ii."]id_ques",array('value'=>$NQ)); ?>
<div class="col-md-12 col-lg-12" style="border-bottom: solid 1px #000;">
<div class="col-md-7 col-lg-7">
<?php echo $formImage->fileField($modImage,'['.$ii.']image', array( 'onChange'=>'readURL(this,'.$ii.')')); ?>
</div>
<div class="col-md-5 col-lg-5">
<?php
if($ban!=1){
echo '<label id="lbl'.$ii.'" style="visibility: hidden;" onclick="kkk('.$ii.')">X</label>';
}
?>
</div>
</div>
<?php echo $formImage->error($modImage,'['.$ii.']image'); ?>
<div class="text-center">
<?php echo $nameQues[$ii]; ?>
</div>
</td>
<?php if($oo==1){ echo '</tr>'; $oo = -1; }
$oo++;
}}
}
?>
</table>
</div>
<div class="col-md-12 col-lg-12 MT15">
<div class="col-md-2 col-lg-2">
<?php
if(isset($search->id_verifier)){
if($search->id_verifier == userID()){
echo CHtml::submitButton('Save', array('class' => 'btn btn-success btn_formVrf btn_create_address_size GreenVrf'));
}
}
?>
</div>
</div>
<?php $this->endWidget(); ?>
</div>
And later this with function js:
function readURL(input,num) {
if (input.files && input.files[0]) {
if(input.files[0].type=='image/jpeg' || input.files[0].type=='image/gif' || input.files[0].type=='image/png'){
if(input.files[0].size>1000000){
$('#VrfImage_'+num+'_image').val('');
alert("El archivo supera el peso permitido (1MB)");
return false;
}
else{
var reader = new FileReader();
reader.onload = function (e) {
$('#img_prev'+num).css('visibility','visible');
$('#img_prev'+num).attr('src', e.target.result).width(250).height(250);
$('#lbl'+num).css('visibility','visible');
};
reader.readAsDataURL(input.files[0]);
}
}
else{
$('#VrfImage_'+num+'_image').val('');
alert("El archivo no es una imagen valida\n(debe ser JPG, JPEG, GIF o PNG y pesar maximo 1MB.)");
return false;
}
}
}
function kkk(num){
$('#img_prev'+num).css('visibility','hidden');
$('#img_prev'+num).css('height','27px');
$('#VrfImage_'+num+'_image').val('');
$('#lbl'+num).css('visibility','hidden');
}
Related
I am trying to display messages in the error section from sender and receiver, both returning view mes_res from MessageController, but it is displaying an error message.
#controller method:
public function respone_msg($myid){
$dd = DB::table('messeges')->where(['is_read'=>0,'sender_id' =>$myid , 'receiver_id' => Session::get('id')])->get();
$myCount = count($dd);
var_dump($myCount);
$sendmsesgesreal = DB::table('messeges')->where(['sender_id' => Session::get('id') , 'receiver_id' => $myid])->orWhere(['receiver_id' => Session::get('id') ])->get();
//return view('users.mes_res')->with(['msg_data' => $sendmsesgesreal, 'user_id' => $myid, 'conv_id' => $sendmsesgesreal[0]->conversation_id]);
return view('users.mes_res')->with(['msg_data' => $sendmsesgesreal, 'user_id' => $myid, 'conv_id' => $sendmsesgesreal[0]->conversation_id])->header('Cache-Control', 'no-cache, no-store, must-revalidate');
}
view mes_reg:
<div class="messages-headline">
<i class="icon-feather-trash-2"></i> Delete Conversation
</div>
<!-- Message Content Inner -->
<div class="message-content-inner">
<?php
foreach ($msg_data as $msg) {
//
if($msg->sender_id==Session::get('id') && $msg->receiver_id==$user_id) //conv_id
{
$getuserdat1 = DB::table('profile_users')->where('user_id',$msg->sender_id)->get();
// print_r($msg);
if (count($getuserdat1)>0)
{
$fullname=$getuserdat1[0]->fname.' '.$getuserdat1[0]->lname;
if ($getuserdat1[0]->profile_images)
{
$img11 = url('')."/public/uploads/".$getuserdat1[0]->profile_images;
}
else
{
$img11 = url('')."/public/users/images/user-avatar-placeholder.png";
}
}
else
{
$img11 = url('')."/public/users/images/user-avatar-placeholder.png";
}
echo '<input type="hidden" name="receiver_id" id="receiver_id" value="'.$msg->sender_id.'">';
//print_r($img11);
?>
<div class="message-time-sign">
<span>{{ \Carbon\Carbon::parse($msg->CreatedBydate)->diffForhumans() }}</span>
</div>
<div class="message-bubble me">
<div class="message-bubble-inner">
<div class="message-avatar"><img src="{{$img11}}" alt="" /></div>
<div class="message-text"><p>{{$msg->messeges}}</p></div>
</div>
<div class="clearfix"></div>
</div>
<?php }
elseif($msg->sender_id==$user_id)
//else
{
//print_r($msg);
// $receiverdata = DB::table('messeges')
// ->where('sender_id',$msg->sender_id)->get();
// print_r($receiverdata);
//print_r($msg);
$getuserdat11 = DB::table('profile_users')->where('user_id',$msg->sender_id)->get();
if(count($getuserdat11)>0)
{
if ($getuserdat11[0]->profile_images)
{
$img111 = url('')."/public/uploads/".$getuserdat11[0]->profile_images;
}
else
{
$img111 = url('')."/public/users/images/user-avatar-placeholder.png";
}
}
else
{
$img111 = url('')."/public/users/images/user-avatar-placeholder.png";
}
echo '<input type="hidden" name="receiver_id" id="receiver_id" value="'.$msg->sender_id.'">';
//print_r($img111);
?>
<div class="message-time-sign">
<span>{{ \Carbon\Carbon::parse($msg->CreatedBydate)->diffForhumans() }}</span>
</div>
<div class="message-bubble">
<div class="message-bubble-inner">
<div class="message-avatar"><img src="{{$img111}}" alt="" /></div>
<div class="message-text"><p>{{$msg->messeges}}</p></div>
</div>
<div class="clearfix"></div>
</div>
<?php }
?>
</div>
How to do pagination in Yii without any grid view and listview
I was stack in their for two days
these is my controller
public function actionIndex()
{
$criteria = new CDbCriteria;
// $criteria ->order = 'date';
$pages = new CPagination(OfferEvents::model()->count());
$pages ->pageSize = 2;
$pages -> applyLimit($criteria);
$post= OfferEvents::model()->findAll($criteria);
$this -> render('index', array('post' => $post, 'pages' => $pages));
}
and my view
<?php foreach($models as $model): ?>
<?php for($x = 0; $x < $arrlength; $x++) { ?>
<?php if($catiddet == 1){?>
<div class="col-sm-4">
<div class="list-box fadeInDown ">
<div class="img-box-1">
<img src="<?php echo $offerListArray[$x]['offerimg']; ?>" style="width:360px;height:202px;" />
<a href="#" class="view-btn" d='modal-launcher' data-toggle="modal"
data-target="#detailsOffeEve" onClick="showdetails(<?php echo $offerListArray[$x]['id']; ?>)">View Event</a>
</div>
<div class="text-box">
<?php
$date2=$offerListArray[$x]['enddate'] ;
$diff = (strtotime($date2)- strtotime($now))/24/3600;
?>
<div class="round-box clear"><span><h1><?php echo $diff ?><small>Days</small></h1></span></div>
<p style="height:19px;overflow: hidden;"> <b ><?php echo $offerListArray[$x]['offertitle']; ?> </b></p>
<p style="height: 80px;overflow: hidden;"><?php echo $offerListArray[$x]['description']; ?> </p>
</div>
</div>
</div>
<?php } else{?>
<div class="col-sm-4" >
<div class="list-box">
<div class="img-box-1">
<?php $filepathnw=$offerListArray[$x]['offerimg'];
//if (file_exists($filepathnw)) { $filepathSrc=Yii::app()->baseUrl.'/'.$filepathnw; } else
//{ $filepathSrc='http://www.childnet.com/pimages/1351720/thumbnail4.jpg'; }
?>
<img src="<?php echo $filepathnw; ?>" />
<a href="#" class="view-btn" d='modal-launcher' data-toggle="modal"
data-target="#detailsOffeEve" onClick="showdetails(<?php echo $offerListArray[$x]['id']; ?>)">View Offer</a>
</div>
<div class="text-box" style="padding:2px !important;">
<?php
$date2=$offerListArray[$x]['enddate'] ;
$diff = (strtotime($date2)- strtotime($now))/24/3600;
?>
<span><h1><?php echo $diff ?><small>Days</small></h1></span>
<span><h1><?php echo $offerListArray[$x]['discountper']; ?>%<small>DISCOUNT</small></h1></span>
<span><h1>$<?php echo $offerListArray[$x]['discountperamt']; ?><small>You Save</small></h1></span>
<div class="text-box" style="padding:15px;">
<p style="height:19px;overflow: hidden;">
<b ><?php echo $offerListArray[$x]['offertitle']; ?> </b></p>
<p style="height: 80px;overflow: hidden;"><?php echo $offerListArray[$x]['description']; ?> </p>
</div> </div>
</div>
</div>
<?php } ?>
<?php } ?>
<?php endforeach; ?>
// display pagination
<?php $this->widget('CLinkPager', array(
'pages' => $pages,
)) ?>
out put comes fine..but the data repeats...
select * FROM offer_events WHERE enddate >= '$now' AND (title like '%$locationdet%' OR description like '%$locationdet%') AND type = '$catiddet' ORDER BY id DESC LIMIT 6 ");
$datalat = $dbCommand->queryAll(); $numlatData=count($datalat);
// echo "<pre>"; print_r($datalat); echo "</pre>";
$latlongdats='';
if($numlatData!=0){
foreach($datalat as $expertn)
{
$ids=$expertn['id'];
$offertitle=$expertn['title'];
if($expertn['image']!=""){ $imgUrl=$expertn['image']; } else { $imgUrl='image-not-available.png'; }
$infowinimgpath='theme/images/OfferEvents/thumb/'.$imgUrl;
if (file_exists($infowinimgpath)) { $infowinimgpathSrc=Yii::app()->baseUrl.'/'.$infowinimgpath; } else
{ $infowinimgpathSrc=Yii::app()->baseUrl.'/theme/images/OfferEvents/thumb/image-not-available.png'; }
$offerimg=$infowinimgpathSrc;
$latinow=$expertn['latitude'];
$longinow=$expertn['longitude'];
$latlongdats.="['".$ids."', ".$latinow.",".$longinow.",'".$offertitle."','".$offerimg."','".$expertn['startdate']."'],";
$offertList = array(
"id" => $ids,
"offertitle"=> $offertitle,
"offerimg" => $offerimg,
"description" => $expertn['description'],
"startdate" => $expertn['startdate'],
"enddate" => $expertn['enddate'],
"discountper" => $expertn['discountper'],
"discountperamt" => $expertn['discountperamt']
);
array_push($offerListArray,$offertList);
}
$zoomlevel=3;
$latlongdatsfinal=rtrim($latlongdats, ",");
} else { $latlongdatsfinal="['','',''],"; $ErrorMsgmap="No Result Found."; }
}
and could you please explain me how this happend???
You can use CActiveDataProvider to perform your pagination needs
public function actionIndex()
{
$criteria = new CDbCriteria;
// $criteria ->order = 'date';
$post= new CActiveDataProvider('OfferEvents', array(
'criteria' => $criteria,
'pagination'=>array('pageSize' => 2),
));
$this -> render('index', array('post' => $post));
}
In your view, instead of using foreach loop, use ListView / GridView and pass the CActiveDataProvider instance ($post) in your case
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$post,
'itemView'=>'_post', // refers to the partial view named '_post'
));
the "_post.php" subview file would contain
$data->property // whatever properties you have set for 'OfferEvents'
This is my code in actionCheckout():
public function actionCheckout() {
$proInfo = Yii::app()->session['cart'];
if (Yii::app()->user->isGuest) {
$model = new Payment;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Payment'])) {
$model->attributes = $_POST['Payment'];
$model->thoigian = date('Y-m-d H:i:s');
if ($model->save()) {
foreach ($proInfo as $key => $value) {
$order = new Order;
$order->id_sp = $key;
$order->soluong = $value;
$product = Product::model()->findByPK($key);
if (empty($product->khuyenmai)) {
$price = $product->gia_sp;
} else {
$price = ceil($product->gia_sp * (100 - $product->khuyenmai) / 100 / 1000) * 1000;
}
$order->thanhtien = $price * $value;
$order->id_payment = $model->id_hoadon;
$order->save();
}
unset(Yii::app()->session['cart']);
$this->redirect(Yii::app()->request->baseUrl . '/cart/success/' . $model->id_hoadon);
}
}
$this->render('checkout', array(
'cart' => $proInfo,
'model' => $model,
));
} else {
$model = new Payment;
$user = User::model()->findByPk(Yii::app()->user->id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Payment'])) {
$model->attributes = $_POST['Payment'];
$model->id_user = Yii::app()->user->id;
$model->hoten = $user->hoten;
$model->email = $user->email;
$model->dienthoai = $user->dienthoai;
$model->diachi = $user->dia_chi;
$model->thoigian = date('Y-m-d H:i:s');
$model->xuly = "Chưa xử lý";
if ($model->save()) {
foreach ($proInfo as $key => $value) {
$order = new Order;
$order->id_sp = $key;
$order->soluong = $value;
$product = Product::model()->findByPK($key);
if (empty($product->khuyenmai)) {
$price = $product->gia_sp;
} else {
$price = ceil($product->gia_sp * (100 - $product->khuyenmai) / 100 / 1000) * 1000;
}
$order->thanhtien = $price * $value;
$order->id_payment = $model->id_hoadon;
$order->save();
}
unset(Yii::app()->session['cart']);
$this->redirect(Yii::app()->request->baseUrl . '/cart/success/' . $model->id_hoadon);
}
}
$this->render('checkout', array(
'user' => $user,
'cart' => $proInfo,
'model' => $model,
));
}
}
And this is my "checkout.php" file in views:
<link rel="stylesheet" type="text/css" href="<?= Yii::app()->request->baseUrl ?>/css/cart.css"/>
<?php
$this->breadcrumbs = array(
'Giỏ hàng' => array('cart/index'),
'Thanh toán'
);
$this->pageTitle = "Thanh Toán";
$items = 0;
$total = 0;
$i = 0;
?>
<h1>Thanh toán</h1>
<?php
if (empty($cart)) {
echo "<p>Bạn chưa có sản phẩm nào trong giỏ hàng</p>";
} else {
$form = $this->beginWidget('CActiveForm', array(
'id' => 'payment-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => false,
));
?>
<div class="payment">
<?php
if (!Yii::app()->user->isGuest) {
?>
<div class="paymentCustomer">
<h3>Thông tin thanh toán</h3>
<div style="padding: 10px; clear:both; float:left">Họ tên:<?= Yii::app()->user->name ?></div>
<div style="padding: 10px; clear:both; float:left">Email:<?= $user->email ?></div>
<div style="padding: 10px; clear:both; float:left">Địa chỉ:<?= $user->dia_chi ?></div>
<div style="padding: 10px; clear:both; float:left">Điện thoại:<?= $user->dienthoai ?></div>
</div>
<?php
} else {
?>
<div class="paymentCustomer">
<h3>Thông tin thanh toán</h3>
<div class="inputUser"><div>Họ tên <span>*</span></div><?php echo $form->textField($model, 'hoten', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'hoten'); ?>
<div class="inputUser"><div>Email <span>*</span></div><?php echo $form->textField($model, 'email', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'email'); ?>
<div class="inputUser"><div>Địa chỉ <span>*</span></div><?php echo $form->textField($model, 'diachi', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'diachi'); ?>
<div class="inputUser"><div>Điện thoại <span>*</span></div><?php echo $form->textField($model, 'dienthoai', array('class' => "inputText loginText")); ?></div>
<?php echo $form->error($model, 'dienthoai'); ?>
</div>
<?php
}
?>
<div class="paymentCustomer">
<h3>Hình thức thanh toán</h3>
<p class="paymentYour">
<?php
echo $form->radioButtonList($model, 'phuongthuc', array(
'Tại Cửa hàng' => 'Thanh toán tại cửa hàng',
'Khi Nhận hàng' => 'Thanh toán khi nhận được hàng',
'Tài khoản Ngân hàng' => 'Thanh toán qua tài khoản Ngân hàng'
), array("class" => "myCheck"));
?>
<?php echo $form->error($model, 'phuongthuc'); ?>
</p>
<h3 style="margin: 50px 0 5px 0;">Mã khuyến mãi</h3>
<?php echo $form->textField($model, 'coupon', array('class' => "inputText loginText")); ?>
<?php echo $form->error($model, 'coupon'); ?>
</div>
</div>
<div class="cartInfo">
<div class="headCart">
<div class="cartField1">Mã sản phẩm</div>
<div class="cartField2">Tên sản phẩm</div>
<div class="cartField3">Đơn giá</div>
<div class="cartField3">Số lượng</div>
<div class="cartField3">Thành tiền</div>
</div>
<?php
foreach ($cart as $key => $value) {
$product = Product::model()->findByPK($key);
if (empty($product->khuyenmai)) {
$price = $product->gia_sp;
} else {
$price = ceil($product->gia_sp * (100 - $product->khuyenmai) / 100 / 1000) * 1000;
}
?>
<div class="bodyCart">
<div class="cartField1" data-label="Mã sản phẩm"><?= $product->ma_sp ?></div>
<div class="cartField2" data-label="Tên sản phẩm"><span><?= $product->ten_sp ?></span></div>
<div class="cartField3" data-label="Đơn giá"><?= $price . "đ" ?></div>
<div class="cartField3" data-label="Số lượng"><?= $value ?></div>
<div class="cartField3" data-label="Thành tiền"><?= $price * $value . "đ" ?></div>
</div>
<?php
$items +=$value;
$total +=$price * $value;
}
?>
<div class="footCart">
<div class="cartField1">Tổng cộng</div>
<div class="cartField2"></div>
<div class="cartField3"><?= $items ?></div>
<div class="cartField3"><?= $total . "đ" ?></div>
</div>
</div>
<div>
<a href="<?= Yii::app()->request->urlReferrer ?>">
<input type="button" class="cartLeftButton button" value="Quay trở lại"/>
</a>
<?php echo CHtml::submitButton('Xác nhận và gửi đơn hàng', array("class" => "cartRightButton button")); ?>
</div>
<?php
$this->endWidget();
}
?>
But when submit that form it not direct to success page. I have try to insert die("abc") to each line in Controller and find out that it not run from the line
if($model->save()){....
How can I fix that now?
I'm having this problem where a view is not being run through the layout on the server, but in a local instance it works just fine without any changes. There are actually two views that have this problem, 'index' view and 'update' and 'create' view. Both of these views are partially rendering another view, 'index' is partially rendering '_view' and 'update' and 'create' are partially rendering '_form'. In the controller I'm specifying what layout should be used to render the views and made sure that the layout is not being overwritten from the action that handles each view. The code in question is as follows:
index.php
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
_view.php
<div class="well">
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('naslov')); ?>:</b>
<?php echo CHtml::encode($data->naslov); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('category_id')); ?>:</b>
<?php
$cat = Category::model()->findByPk($data->category_id);
$parent = $cat->parent()->find();
$c = $parent->title." / ".$cat->title;
echo CHtml::encode($c); ?>
<br />
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('image_path')); ?>:</b>
<?php echo CHtml::encode($data->image_path); ?>
<br />
</div>
update.php and create.php
<?php $this->renderPartial('_form', array('model'=>$model)); ?>
_form.php
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'news-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
),
)); ?>
// form code
<?php $this->endWidget(); ?>
and in the controller that extends a base controller i define which layout is to be used
public $layout='//layouts/column2';
I've looked through the application.log file trying to find anything that might cause this but didn't find anything.
EDITED:
Here is the controller Create action:
public function actionCreate() {
$model = new News;
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
$model->body = $_POST['News']['body'];
$model->author = Yii::app()->user->id;
$model->meta_description = $_POST['News']['meta_description'];
$path = $this->upload_path;
$image_temp = CUploadedFile::getInstance($model, 'image_path');
$new_image_ext = pathinfo($image_temp, PATHINFO_EXTENSION);
$new_image_subpath = uniqid(rand(), true) . '.' . $new_image_ext;
$new_image_subpath = substr($new_image_subpath, 0, 1) . '/' . substr($new_image_subpath, 1, 1) . '/' . $new_image_subpath;
$new_image_path = $path . $new_image_subpath;
$model->image_path = $new_image_subpath;
if (!file_exists(dirname($new_image_path))) {
mkdir(dirname($new_image_path), 0777, true);
}
}
if ($model->save()) {
$image_temp->saveAs($new_image_path, false);
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('create', array(
'model' => $model,
));
}
And the Update action:
public function actionUpdate($id) {
$model = $this->loadModel($id);
$this->pageTitle = "Vesti - Izmena vesti: " . $model->naslov . "";
if (isset($_POST['News'])) {
$model->attributes = $_POST['News'];
$model->body = $_POST['News']['body'];
$model->modified_on = date("d-m-y H:m:s");
$model->meta_description = $_POST['News']['meta_description'];
$model->attributes = $_POST['News'];
if ($_FILES['News']['name']['image_path'] != "") {
$uploadedFile = CUploadedFile::getInstance($model, 'image_path');
$path = $this->upload_path;
$image_temp = CUploadedFile::getInstance($model, 'image_path');
$new_image_ext = pathinfo($image_temp, PATHINFO_EXTENSION);
$new_image_subpath = uniqid(rand(), true) . '.' . $new_image_ext;
$new_image_subpath = substr($new_image_subpath, 0, 1) . '/' . substr($new_image_subpath, 1, 1) . '/' . $new_image_subpath;
$new_image_path = $path . $new_image_subpath;
$model->image_path = $new_image_subpath;
if (!file_exists(dirname($new_image_path))) {
mkdir(dirname($new_image_path), 0777, true);
}
} else {
unset($model->image_path);
}
if ($model->save()) {
if ($_FILES['News']['name']['image_path'] != "") {
$image_temp->saveAs($new_image_path, false);
}
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('update', array(
'model' => $model,
));
}
And the _form view:
<script type="text/javascript">
function showSEOServices() {
$("#seo_options").slideToggle();
}
function slugPopulate(s, d, a) {
if(a==1) {
var d = $("#News_category_id").val();
} else {
var s = $("#News_naslov").val();
}
$.ajax({
type: "GET",
url: 'index.php?r=news/slug',
data: "s=" + s + "&d=" + d,
success: function(data) {
$("#News_url_slug").val(data);
}
});
}
</script>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'news-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
),
)); ?>
<p class="note">Polja sa <span class="required">*</span> su obavezna.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'naslov'); ?>
<?php echo $form->textField($model,'naslov',array('size'=>60,'maxlength'=>255, 'onChange' => "slugPopulate(this.value, '', 1);")); ?>
<?php echo $form->error($model,'naslov'); ?>
</div>
<div class="row">
Top sekcija:<br>
<?php echo $form->checkBox($model,'top_section'); ?>
</div>
<div class="row">
Normalna sekcija:<br>
<?php echo $form->checkBox($model,'normal_section'); ?>
</div>
<div class="row">
Donja sekcija:<br>
<?php echo $form->checkBox($model,'bottom_section'); ?>
</div>
<div class="row">
Boja članka u listingu:<br>
<?php if($model->isNewRecord!='1'){ ?>
<input type="color" name="News[news_color]" id="News_news_color" value="<?php echo $model->news_color; ?>">
<?php } else { ?>
<input type="color" name="News[news_color]" id="News_news_color" value="">
<?php } ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'body'); ?>
<?php $this->widget('ext.editMe.widgets.ExtEditMe', array(
'model'=>$model,
'attribute'=>'body',
)); ?>
<?php echo $form->error($model,'body'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'category_id'); ?>
<?php echo $form->dropDownList($model, 'category_id', $model->getCategoryOptions(),array('onChange' => "slugPopulate('', this.value, 2);")); ?>
<?php echo $form->error($model,'category_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'image_path'); ?>
<?php echo CHtml::activeFileField($model, 'image_path'); ?>
<?php echo $form->error($model,'image_path'); ?>
</div>
<!-- FOTOGRAFIJA -->
<?php if($model->isNewRecord!='1'){ ?>
<div class="row">
<?php echo CHtml::image('/resources/uploads/news/'.$model->image_path,"image",array("width"=>200, "class" => "img-thumbnail")); ?>
</div>
<?php } ?>
<!-- FOTOGRAFIJA END -->
<!-- SEO opcije -->
<button type="button" onClick="showSEOServices()" class="btn btn-labeled btn-default">
<span class="btn-label"><i class="fa fa-map-marker"></i> </span>Prikaži opcije za SEO
</button>
<div id="seo_options" class="alert alert-info" style="display:none;">
<div class="row">
<?php echo $form->labelEx($model,'url_slug'); ?>
<?php echo $form->textField($model,'url_slug',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'url_slug'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'meta_title'); ?>
<?php echo $form->textField($model,'meta_title',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'meta_title'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'meta_description'); ?>
<?php echo $form->textArea($model,'meta_description',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'meta_description'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'meta_keywords'); ?>
<?php echo $form->textField($model,'meta_keywords',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'meta_keywords'); ?>
</div>
</div>
<!-- SEO opcije kraj -->
<div class="row">
<?php echo $form->labelEx($model,'status'); ?>
<?php echo $form->dropDownList($model, 'status', $model->getStatusOptions()); ?>
<?php echo $form->error($model,'status'); ?>
</div>
<div class="row buttons">
<button class="btn btn-success ladda-button" data-style="expand-right"><span class="ladda-label">Sačuvaj</span></button>
<?php //echo CHtml::submitButton($model->isNewRecord ? 'Kreiraj' : 'Sačuvaj', array("class" => "btn btn-success ladda-button", "data-style" => "expand-right")); ?>
</div>
<?php $this->endWidget(); ?>
I passed more than 4 hours seeking where is the error. but nothing found
My view inscriresalle.php :
<div class="widget-box">
<div class="widget-title">
<span class="icon">
<i class="icon-align-justify"></i>
</span>
<h5><?php echo empty($participant_salle->id) ? 'Nouveau Agent OCP:' : 'Modification de: ' . $participant_salle->nom.' '.$participant_salle->prenom; ?></h5>
</div>
<div class="widget-content nopadding">
<div class="form-horizontal" name="basic_validate" id="basic_validate" novalidate="novalidate">
<?php echo form_open(); ?>
<div <?php if(form_error('matricule')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Matricule :</label>
<div class="controls">
<?php echo form_input('matricule', set_value('matricule', $this->input->get('matricule'))); ?>
<span class="help-inline"><?php echo form_error('matricule'); ?></span>
</div>
</div>
<div <?php if(form_error('nom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Nom :</label>
<div class="controls">
<?php echo form_input('nom', set_value('nom', $this->input->get('nom'))); ?>
<span class="help-inline"><?php echo form_error('nom'); ?></span>
</div>
</div>
<div <?php if(form_error('prenom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Prénom :</label>
<div class="controls">
<?php echo form_input('prenom', set_value('prenom', $this->input->get('prenom'))); ?>
<span class="help-inline"><?php echo form_error('prenom'); ?></span>
</div>
</div>
<div <?php if(form_error('beneficiaire')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Bénéficiaire :</label>
<div class="controls">
<label><?php echo form_radio('beneficiaire', 'Agent', $this->input->get('beneficiaire') == 'Agent') ?> Agent </label>
<label><?php echo form_radio('beneficiaire', 'Conjoint', $this->input->get('beneficiaire') == 'Conjoint') ?> Conjoint </label>
<label><?php echo form_radio('beneficiaire', 'Enfant', $this->input->get('beneficiaire') == 'Enfant') ?> Enfant </label>
<span class="help-inline"><?php echo form_error('beneficiaire'); ?></span>
</div>
</div>
<div <?php if(form_error('sexe')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Sexe :</label>
<div class="controls">
<label><?php echo form_radio('sexe', 'M', $this->input->get('sexe') == 'M') ?> Masculin </label>
<label><?php echo form_radio('sexe', 'F', $this->input->get('sexe') == 'F') ?> Féminin </label>
<span class="help-inline"><?php echo form_error('sexe'); ?></span>
</div>
</div>
<div <?php if(form_error('date_naissance')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Date de Naissance :</label>
<div class="controls">
<input type="text" name="date_naissance" id="date1" value="<?php echo set_value('date_naissance', $this->input->get('dateNaissance')); ?>" />
<span class="help-inline"><?php echo form_error('date_naissance'); ?></span>
</div>
</div>
<div <?php if(form_error('telephone')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Téléphone :</label>
<div class="controls">
<?php echo form_input('telephone', set_value('telephone', $participant_salle->telephone)); ?>
<span class="help-inline"><?php echo form_error('telephone'); ?></span>
</div>
</div>
<div <?php if(form_error('date_inscription_salle')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Date inscription :</label>
<div class="controls">
<input type="text" name="date_inscription_salle" id="date2" value="<?php echo set_value('date_inscription_salle', $participant_salle->date_inscription_salle); ?>" />
<span class="help-inline"><?php echo form_error('date_inscription_salle'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_debut_periode')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Début période :</label>
<div class="controls">
<input type="text" name="salle_debut_periode" id="date3" value="<?php echo set_value('salle_debut_periode', $participant_salle->salle_debut_periode); ?>" />
<span class="help-inline"><?php echo form_error('salle_debut_periode'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_fin_periode')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Fin période :</label>
<div class="controls">
<input type="text" name="salle_fin_periode" id="date4" value="<?php echo set_value('salle_fin_periode', $participant_salle->salle_fin_periode); ?>" />
<span class="help-inline"><?php echo form_error('salle_fin_periode'); ?></span>
<span class="help-block">
</div>
</div>
<script type="text/javascript">// <![CDATA[
var qp = new Array();
var tarif = new Array();
var datestart = document.getElementById('date3');
var dateend = document.getElementById('date4');
$(document).ready(
// a chaque changement de discipline on obtien l'id du tableau discipline.
function(){
$('#country').change(function(){ //any select change on the dropdown with id country trigger this code
$("#cities > option").remove(); //first of all clear select items
var salle_nom = $('#country').val(); // here we are taking country id of the selected one.
$.ajax({
type: "POST",
url: "http://localhost/public_html/admin/dropdown_salle/get_cities/"+salle_nom, //here we are calling our user controller and get_cities method with the country_id
dataType : "json",
success: function(disciplines) //we're calling the response json array 'cities'
{
var discipline = new Array();
for (i=0; i<disciplines.length; ++i) {
// remplisage des 3 tableaux :discipline, tarif, et qp_agent
discipline[i] = disciplines[i].discipline+' pour '+disciplines[i].categorie_tarif;
qp[i] = disciplines[i].qp_agent;
tarif[i] = disciplines[i].tarif;
}
$.each(discipline,function(id,value) //here we're doing a foeach loop round each value with id as the key and value as the value
{
var opt = $('<option />'); // here we're creating a new select option with for each value
opt.val(id);
opt.text(value);
$('#cities').append(opt); //here we will append these new select options to a dropdown with the id 'cities'
});
}
});
});
function qp(qp, id) {
return qp[id];
}
function tarif(tarif, id) {
return tarif[id];
}
$('#cities').change(function () {
var a = $(this).find('option:selected').attr('value');
//here i retrieve the qp and tarif value corresponds to my 'discipline' choosen.
var qpValue = qp(qp, a);
var tarifValue = tarif(tarif, a);
var start = datestart.value;
var end = dateend.value;
var date1 = new Date(start);
var date2 = new Date(end);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
var diffMonths = Math.round(diffDays / 30);
alert('Vous avez Selectionnez '+diffMonths+' mois');
var finalresult = Math.round(diffMonths*qpValue*tarifValue);
document.getElementById("salle_montant_paye").value = finalresult;
});
});
// ]]>
</script>
<?php $countries['#'] = 'Aucun choix'; ?>
<?php
foreach ($countries as $k => $v) {
unset ($countries[$k]);
$new_key1 = $v;
$countries[$new_key1] = $v;
}
?>
<div <?php if(form_error('salle_nom')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
<label class="control-label">Nom de la Salle :</label>
<div class="controls">
<?php echo form_dropdown('salle_nom', $countries , $this->input->post('salle_nom') ? $this->input->post('salle_nom') : $participant_salle->salle_nom , 'id="country"'); ?>
<span class="help-inline"><?php echo form_error('salle_nom'); ?></span>
</div>
</div>
<?php $cities['#'] = 'Aucun choix'; ?>
<div <?php if(form_error('salle_discipline')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?> >
<label class="control-label">Discipline et type:</label>
<div class="controls">
<?php echo form_dropdown('salle_discipline', $cities , $this->input->post('salle_discipline') ? $this->input->post('salle_discipline') : $participant_salle->salle_discipline , 'id="cities"'); ?>
<span class="help-inline"><?php echo form_error('salle_discipline'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_montant_paye')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Montant à payé :</label>
<div class="controls">
<input type="text" name="salle_montant_paye" id="salle_montant_paye" value="<?php set_value('salle_montant_paye', $participant_salle->salle_montant_paye) ?> "></input>
<span class="help-inline"><?php echo form_error('salle_montant_paye'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_versement_espec')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Versement espéce :</label>
<div class="controls">
<?php echo form_input('salle_versement_espec', set_value('salle_versement_espec', $participant_salle->salle_versement_espec)); ?>
<span class="help-inline"><?php echo form_error('salle_versement_espec'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_versement_cheq')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Versement chèque :</label>
<div class="controls">
<?php echo form_input('salle_versement_cheq', set_value('salle_versement_cheq', $participant_salle->salle_versement_cheq)); ?>
<span class="help-inline"><?php echo form_error('salle_versement_cheq'); ?></span>
</div>
</div>
<div <?php if(form_error('salle_numero_cheq')) { echo 'class="control-group error"'; } else {echo 'class="control-group"';} ?>>
<label class="control-label">Numéro de chèque :</label>
<div class="controls">
<?php echo form_input('salle_numero_cheq', set_value('salle_numero_cheq', $participant_salle->salle_numero_cheq)); ?>
<span class="help-inline"><?php echo form_error('salle_numero_cheq'); ?></span>
</div>
</div>
<div class="form-actions">
<?php echo form_submit('submit', 'Enregistrer', 'class="btn btn-success"'); ?>
</div>
<?php echo form_close();?>
</div>
</div>
</div>
</br>
My controller agent.php :
public function inscriresalle ($id = NULL) {
// Fetch a participant or set a new one
if ($id) {
$this->data['participant_salle'] = $this->participantsalle_m->get($id);
count($this->data['participant_salle']) || $this->data['errors'][] = 'Agent non trouvé';
}
else {
$this->data['participant_salle'] = $this->participantsalle_m->get_new();
}
$this->load->model('salle_m');
$this->data['countries'] = $this->salle_m->get_countries();
// Set up the form
$rules = $this->participantsalle_m->rules_participantsalle;
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE) {
$data = $this->participantsalle_m->array_from_post(array('matricule', 'nom', 'prenom', 'beneficiaire', 'sexe', 'telephone', 'date_naissance', 'date_inscription_salle', 'salle_debut_periode', 'salle_fin_periode', 'salle_montant_paye', 'salle_versement_espec', 'salle_versement_cheq', 'salle_numero_cheq'));
$this->participantsalle_m->save($data, $id);
redirect('admin/agent/profile/3608');
}
// Load the view
$this->data['subview'] = 'admin/agent/inscriresalle';
$this->load->view('admin/_layout_main', $this->data);
}
My model participantsalle_m.php :
<?php
class Participantsalle_M extends MY_Model
{
protected $_table_name = 'participants_salle';
protected $_order_by = 'id';
public $rules_participantsalle = array(
'matricule' => array(
'field' => 'matricule',
'label' => 'Matricule',
'rules' => 'trim|required|xss_clean'
),
'nom' => array(
'field' => 'nom',
'label' => 'Nom',
'rules' => 'trim|required|xss_clean'
),
'prenom' => array(
'field' => 'prenom',
'label' => 'Prénom',
'rules' => 'trim|required|xss_clean'
),
'beneficiaire' => array(
'field' => 'beneficiaire',
'label' => 'Bénéficiaire',
'rules' => 'trim|required|xss_clean'
),
'sexe' => array(
'field' => 'sexe',
'label' => 'Sexe',
'rules' => 'trim|required|xss_clean'
),
'telephone' => array(
'field' => 'telephone',
'label' => 'Téléphone',
'rules' => 'trim|xss_clean'
),
'date_naissance' => array(
'field' => 'date_naissance',
'label' => 'Date de naissance',
'rules' => 'trim|required|xss_clean'
),
'date_inscription_salle' => array(
'field' => 'date_inscription_salle',
'label' => 'Date inscription a la salle',
'rules' => 'trim|required|xss_clean'
),
'salle_debut_periode' => array(
'field' => 'salle_debut_periode',
'label' => 'Début période',
'rules' => 'trim|required|xss_clean'
),
'salle_fin_periode' => array(
'field' => 'salle_fin_periode',
'label' => 'Fin période',
'rules' => 'trim|required|xss_clean'
),
'salle_nom' => array(
'field' => 'salle_nom',
'label' => 'Nom de la salle',
'rules' => 'trim|required|xss_clean'
),
'salle_discipline' => array(
'field' => 'salle_discipline',
'label' => 'Discipline de la salle',
'rules' => 'trim|required|xss_clean'
),
'salle_montant_paye' => array(
'field' => 'salle_montant_paye',
'label' => 'Montant à payé',
'rules' => 'trim|required|xss_clean'
),
'salle_versement_espec' => array(
'field' => 'salle_versement_espec',
'label' => 'Versement éspece',
'rules' => 'trim|required|xss_clean'
),
'salle_versement_cheq' => array(
'field' => 'salle_versement_cheq',
'label' => 'Versement chèque',
'rules' => 'trim|required|xss_clean'
),
'salle_numero_cheq' => array(
'field' => 'salle_numero_cheq',
'label' => 'Numéro de chèque',
'rules' => 'trim|required|xss_clean'
),
);
public function get_new()
{
$participant_salle = new stdClass();
$participant_salle->matricule = '';
$participant_salle->nom = '';
$participant_salle->prenom = '';
$participant_salle->beneficiaire = '';
$participant_salle->sexe = '';
$participant_salle->telephone = '';
$participant_salle->date_naissance = '';
$participant_salle->date_inscription_salle = '';
$participant_salle->salle_debut_periode = '';
$participant_salle->salle_fin_periode = '';
$participant_salle->salle_nom = '';
$participant_salle->salle_discipline = '';
$participant_salle->salle_montant_paye = '';
$participant_salle->salle_versement_espec = '';
$participant_salle->salle_versement_cheq = '';
$participant_salle->salle_numero_cheq = '';
return $participant_salle;
}
function __construct ()
{
parent::__construct();
}
}
Everything seems to be good but i realy don't find error, why data don't saved on database.
My database structure is :
id
- nom
- prenom
- beneficiaire
- sexe
- telephone
- date_naissance
- date_inscription_salle
- salle_debut_periode
- salle_fin_periode
- salle_nom
- salle_discipline
- salle_montant_paye
- salle_versement_espec
- salle_versement_cheq
- salle_numero_cheq
Maybe it's not my day for coding, i don't see the probleme, Any help please?
the function save() on MY_Model :
public function save($data, $id = NULL){
// Set timestamps
if ($this->_timestamps == TRUE) {
$now = date('Y-m-d H:i:s');
$id || $data['created'] = $now;
$data['modified'] = $now;
}
// Insert
if ($id === NULL) {
!isset($data[$this->_primary_key]) || $data[$this->_primary_key] = NULL;
$this->db->set($data);
$this->db->insert($this->_table_name);
$id = $this->db->insert_id();
print_r($id);
}
// Update
else {
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->set($data);
$this->db->where($this->_primary_key, $id);
$this->db->update($this->_table_name);
}
return $id;
This line breaks it for me.
count($this->data['participant_salle']) || $this->data['errors'][] = 'Agent non trouvé';
try
if (empty($this->data['participant_salle'])){
$this->data['errors'][] = 'Agent non trouvé';
}