Pagination in yii without in gridview or list view - php

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'

Related

yii2 setting max id in controller action as default

I have a view which list multiple photo galleries.
so from the menu when I try to access the gallery view the action is
site/gallery
Now in my controller action I am trying like this to show the latest photo-gallery added as first.
This is my code in controller:
public function actionGallery($id = null)
{
//$this->layout = "#app/themes/frontend/main";
$activities = Activities::find()
->where(['status' => 1])
->orderBy(['id' => SORT_DESC])
->all();
$model = Activities::find()->where(['id' => $id])->one();
if ($id == null) {
$gallery = Gallery::find()
->where(
[
'status' => 'active',
'activity_name' => max(['id'])
]
)->all();
} else {
$gallery = Gallery::find()
->where(
['status' => 'active', 'activity_name' => $id]
)->all();
}
return $this->render(
'gallery',
[
'gallery' => $gallery,
'activities' => $activities,
'model' => $model
]
);
}
I also tried like:
$gallery = Gallery::find()->where(
[
'status' => 'active',
'activity_name' => max(['activity_name'])
]
)->all();
the code for view:
<?php
$this->title = 'gallery';
?>
<div class="container">
<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style='background-color:#fafafa'>
<h3>Activities</h3>
<?php
foreach ($activities as $activity) {
?>
<!-- <a href="<?php // Yii::getAlias('#web');?>/site/gallery?activity_name=<?php //$Categories['id'];?>"> -->
<a href="<?php Yii::getAlias('#web');?>/site/gallery/?id=<?php echo $activity['id']; ?>">
<br><h5 class="text-center"><?php echo $activity['activity_name']; ?></h5>
</a>
<?php
}
?>
</div>
<div class="col-lg-10 col-md-10 col-sm-12 col-xs-12">
<header class="section-header">
<div>
<h3 class="text-center">
<?php echo $model['activity_name'] ?>
</h3>
<h5 class="text-center">
<?php echo $model['activity_description'] ?>
</h5>
<br>
</div>
</header>
<div id="grid-container" class="cbp-l-grid-projects">
<ul>
<?php foreach ($gallery as $galleries) {?>
<div class="cbp-item" style="width:320px;">
<a href="<?php echo Yii::getAlias('#web'); ?>/web/gallery/<?php echo $galleries['id']; ?>/<?php echo $galleries['image']; ?>" data-lightbox="portfolio" data-title="<?php echo $galleries['title']; ?>" title="Preview" class="cbp-lightbox">
<picture>
<source srcset ="<?php echo Yii::getAlias('#web'); ?>/web/gallery/<?php echo $galleries['id']; ?>/<?php echo basename($galleries['image_thumb'], '.jpg') . '.webp'; ?>" type="image/webp">
<source srcset ="<?php echo Yii::getAlias('#web'); ?>/web/gallery/<?php echo $galleries['id']; ?>/<?php echo $galleries['image_thumb']; ?>" type="image/jpeg">
<img src="<?php echo Yii::getAlias('#web'); ?>/web/gallery/<?php echo $galleries['id']; ?>/<?php echo $galleries['image_thumb']; ?>" style ="width:100%;" class="img-fluid" alt="">
</picture>
</a>
</div>
<?php
}
?>
</ul>
</div>
</div>
</div>
I think I have resolved it using the below code.
public function actionGallery($id=null) {
//$this->layout = "#app/themes/frontend/main";
$activities = Activities::find()->where(['status' => 1])->orderBy(['id'=>SORT_DESC])->all();
$model = Activities::find()->where(['id' => $id])->one();
$latestActivity = Activities::find()->max('id');
if($id==null){
$gallery = Gallery::find()->where(['status' => 'active','activity_name'=>$latestActivity])->all();
}else{
$gallery = Gallery::find()->where(['status' => 'active','activity_name'=>$id])->all();
}
return $this->render('gallery', ['gallery' => $gallery,'activities'=>$activities,'model'=>$model]);
}

How to show data from database in dscending order in codeigniter?

Normally when I get the data from my database I there are arranged in the order of their id.However, I have created a column called 'sales' which is also an integer
and I would like my data to be arranged in ascending order according to the sales.Here is my code:
My Model
public function get_bestseller($id = FALSE) {
if ($id === FALSE)
{
$query = $this->db->get('submit');
return $query->result_array();
}
$query = $this->db->get_where('submit', array('id' => $id));
$this->db->order_by('sales', 'DESC');
return $query->result_array();
}
My View
<div class="tab-pane fade" id="faq-cat-2">
<div class="panel-group" id="accordion-cat-2">
<?php foreach ($bestseller as $bestseller_item): ?>
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img class="lazy" src="<?php echo base_url() ?>Images/last.gif"
data-original="<?php echo base_url() ?>uploads/<?php echo $bestseller_item['imgname']; ?>"
style="width: 350px; height: 150px">
<div class="caption">
<?php if ($bestseller_item['Price'] == 0): ?>
<h4 class="pull-right"><p class="text-success">Free</p></h4>
<?php else: ?>
<h4 class="pull-right">$<?php echo $bestseller_item['Price']; ?></h4>
<?php endif; ?>
<h4>
<a href="<?php echo site_url('submit/view/' . $bestseller_item['id']); ?>"
target="_blank"><?php echo $bestseller_item['Title']; ?></a>
</h4>
<p><?php echo $bestseller_item['textarea']; ?></p>
</div>
<p class="text-right"><b
class="author">By: <?php echo $bestseller_item['Author']; ?></b>
</p>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
My Controller
public function index()
{
$data['bestseller'] = $this->Submit_Database->get_bestseller();
$this->load->view('templates/header');
$this->load->view('pages/home', $data);
$this->load->view('templates/footer');
}
$query = $this->db->order_by('sales', 'DESC')->get_where('submit', array('id' => $id));
You are adding the order by clause after the query has already ran.

Yii form not validating

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?

Getting results from giant query in codeigniter

I've been stuck for about a week now on trying to get some query results in my reply to comments module in codeigniter. I am most certainly able to insert the replies to comments and have them linked to the proper comment.
I am not able to return the results of the replies however. I have based my query structure on the comments results which I'm able to display.
Here is the code:
inserting the replies and trying to pull the results on the controller:
public function insert_airwaves_comments_replies($profile_id)
{
//echo $profile_id;
$this->load->model('account_model');
$this->load->library('session');
$this->load->helper('date');
$user = $this->account_model->user();
$session_id = $this->session->userdata['id'];
$data['user'] = $user;
$this->load->model('community_model');
$this->load->library('form_validation');
$submit = $this->input->post('sub_comment_reply');
$this->load->library('session');
$airwave = $this->community_model->get_airwave_comments($profile_id);
$data['airwave'] = $airwave;
if(isset($submit))
{
foreach($airwave as $airwave_id)
//if($this->form_validation->run() == FALSE)
// {
// $data['main_content'] = 'account/profile';
// $this->load->view('includes/templates/main_page_template', $data);
// }
// else
//{
$save_data = array(
'airwave_id' => $airwave_id['id'],
'from_id' => $session_id,
'comment' => $this->input->post('airwaves_comments_replies'),
'status' => 'active',
'datetime' => date('Y-m-d H:i:s',now())
);
$query = $this->community_model->save_airwaves_comments_replies($profile_id,$save_data);
$airwave_reply = $this->community_model->get_airwaves_comments_replies($profile_id);
$data['airwave_reply'] = $airwave_reply;
redirect('/account/profile/'.$profile_id);
}
//}
}
getting the results from the model:
public function get_airwaves_comments_replies($profile_id)
{
$session = $this->session->userdata('is_logged_in');
$user_id= $this->session->userdata('id');
if($profile_id == $user_id)
{
$comments_query = "SELECT
awr.id AS id,
awr.airwave_id AS airwave_id,
awr.from_id AS from_id,
awr.comment AS comment,
awr.status AS status,
awr.thumbsup_reply AS thumbsup_reply,
awr.datetime AS datetime,
u.first_name AS first_name
FROM
airwaves_comments_replies awr,
users u
WHERE
u.id=awr.from_id
AND awr.from_id =".$profile_id."
order by
awr.datetime
desc" ;
}
else
{
$comments_query = "SELECT awr.id AS id,
awr.airwave_id AS airwave_id,
awr.from_id AS from_id,
awr.comment AS comment,
awr.status AS status,
awr.thumbsup_reply AS thumbsup_reply,
awr.datetime AS datetime,
u.first_name AS first_name FROM airwaves_comments_replies awr,users u WHERE u.id = awr.from_id AND awr.from_id =".$profile_id." order by awr.datetime desc" ;
}
$query = $this->db->query($comments_query);
if($query->num_rows() >= 1)
{
$data = $query->result_array();
// return whole resultset. It contains zero, one or more records
return $data;
}
else return false;
}
displaying the results in my view:
if ($airwave_reply)
{
foreach ($airwave_reply as $airwave_reply_comment_row)
{ ?>
?>
<?php echo $airwave_reply_comment_row['from_id']; echo "<br />";
echo $airwave_reply_comment_row['first_name'];?>
<div class="response_structure_future">
<a name="response_<?php echo $airwave_reply_comment_row['id']; ?>"></a>
<div class="response_polaroid_future">
<a href="">
<img src='/styles/images/prof_thumbnail_2.jpg'/>
</a>
</div>
<div class="response_body_future">
<div class="response_arrow_future"></div>
<div class="response_tail_future"></div>
<div class="response_data_future">
<div class="response_name_future">
<a href="">
<?php echo $airwave_reply_comment_row['first_name'];?>says...
</a>
</div>
comment here
<div class="respond_info_future">
at <?php echo date('M d, Y',strtotime($airwave_reply_comment_row['datetime'])); ?>
<?php //if($auth->id == $replier->id || $auth->id == $result['ToUserID']) ?>
<a onclick="confirmation('');"> • delete</a>
<?php ?>
<div id="thumb_holder">
<div id="thumb_report">
<a href="mailto:info#cysticlife.org">
report
</a>
</div>
<div class= "thumb_counter" id="thumb_counter<?php// echo $reply['id']; ?>">
+<?php //echo $reply['thumbsUp_reply']; ?>
</div>
<div id="thumb_thumb">
<?php $comment_reply_id = $reply['id'];?>
<a class="myButtonLink" href="Profile.php?id=<?php //echo $prof->id; ?>" id="<?php //echo $comment_reply_id; ?>">Vote Up!</a>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
?>
<a name='reply_form_<?php echo $airwave_comment_row['id']; ?>' style="clear:both"></a>
<div id='reply_to_<?php echo $airwave_comment_row['id']; ?>' class="respond_structure_future" <?php if(isset($_GET['reply_to']) && $_GET['reply_to'] == $airwave_comment_row['id']) { echo 'style="display:block;"';}else{ echo 'style="display:none;"';} ?>>
<div class="response_polaroid_future">
<a href="http://www.cysticlife.org/Profile.php?id=<?php// echo $auth->id; ?>">
<img src="/styles/images/prof_thumbnail_2.jpg" />
</a>
</div>
<?php
echo validation_errors();
echo form_open('community/insert_airwaves_comments_replies/'.$this->uri->segment(3));
?>
<div class="respond_body_future">
<div class="response_arrow_future"></div>
<div class="response_tail_future"></div>
<div class="respond_data_future">
<?php
$data = array('name' => 'airwaves_comments_replies', 'id' => 'reply_to'. $airwave_comment_row['id'].'_textarea', 'class' => 'respond');
echo form_textarea($data, set_value('airwaves_comments_replies'));
$data = array('type' => 'hidden', 'name' => 'comment', 'value' => $airwave_comment_row['id']);
echo form_input($data);
?>
<div class="respond_nevermind">
nevermind
</div>
<?php
echo form_submit('sub_comment_reply', 'Reply');
?>
</div>
</div>
</form>
</div>
please let me know what else you may need to help and thanks in advance.
What is your result right now?
With the code you are showing, your controller inserts the comment replies in a foreach-loop but redirects the user to
redirect('/account/profile/'.$profile_id)
I don't see any code where you call the view to show the comments, so i think we can't help you any further without some more explanation and code.

Yii has many through ajax validation

public function actionEquipmentLoanRequestCreate()
{
if(isset($_POST['EquipmentRequest']))
{
$ids = $_POST['EquipmentRequest']['equipID'];
$equipment = Equipment::model()->findAllByPk($ids);
$requests = self::instantiateEquipmentRequests($equipment);
//echo "<pre>";
//die(count($requests)." ".CActiveForm::validate($requests));
$booking = new EquipmentBooking;
if(isset($_POST['EquipmentRequest']) && $_POST['EquipmentBooking'])
{
$booking->attributes = $_POST['EquipmentBooking'];
$requestPostedVars = $_POST['EquipmentRequest'];
//have posted collection of equipment
//need to take count
//request below not really useful???
$equipmentRequests = array();
foreach($requestPostedVars as $request)
{
if(isset($request))
{
$equipmentRequest = new EquipmentRequest('loanRequest');
$equipmentRequest->attributes = $request;
array_push($equipmentRequests,$equipmentRequest);
}
}
$models = $equipmentRequests;
$models[]=$booking;
$this->performAjaxValidation($models);
$booking->equipment = $equipmentRequests;
if ($booking->save()){
self::assignBookingIds($equipmentRequests,$booking);
$this->redirect('index');
}
}
//displays view to create loan request
$this->render('equipment-loan-request',array('requests' => $requests,'booking' => $booking));
} else {
Yii::app()->user->setFlash('error', "You need to select equipment first!");
$this->redirect(array('simulation/equipment'), true);
}
}
public function instantiateEquipmentRequests($equipment)
{
$equipmentRequests = array();
foreach($equipment as $item)
{
$request = new EquipmentRequest('loanRequest');
$request->equipment = $item;
$request->qty = 1;
array_push($equipmentRequests,$request);
}
return $equipmentRequests;
}
form view ignore excess button replacing later -- ive directly tried calling the requests as opposed to just the bookings or both below as well to no avail.
<?php $form=$this->beginWidget('CActiveFormExtended', array(
'id' => 'equipment-booking-form',
'enableAjaxValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange'=>true,
),
)); ?>
<div class="content-bg">
<?php
echo $form->errorSummary($requests);
if(isset($requests) && count($requests) > 0) {
foreach($requests as $i => $request) {
$this->renderPartial('_requestedEquipment', array("index" => $i, "request" => $request, "form"=> $form));
}
}?>
</div>
<br />
<hr class="brown"/>
<h2>Request Details</h2>
<div class="content-bg">
<h3>Step 1</h3>
<?php echo $form->label($booking,'organisation'); ?>
<?php echo $form->dropDownList($booking, 'organisation', $booking::$organisations,array('id' => 'organisation', 'class' => "selectfield",'empty' => 'Select')); ?>
</div>
<br />
<div class="content-bg">
<h3>Step 2</h3>
<?php echo $form->label($booking,'name'); ?>
<?php echo $form->textField($booking,'name',array('size'=>60,'maxlength'=>255)); ?>
    <?php echo $form->error($booking,'name'); ?>
<?php echo $form->label($booking,'email'); ?>
<?php echo $form->textField($booking,'email',array('size'=>60,'maxlength'=>255)); ?>
    <?php echo $form->error($booking,'email'); ?>
<?php echo $form->label($booking,'phone'); ?>
<?php echo $form->textField($booking,'phone',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($booking,'phone'); ?>
</div>
<br />
<div class="content-bg">
<h3>Step 3</h3>
<?php echo $form->label($booking,'address'); ?>
<?php echo $form->textField($booking,'address',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($booking,'address'); ?>
<?php echo $form->label($booking,'suburb'); ?>
<?php echo $form->textField($booking,'suburb',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($booking,'suburb'); ?>
<?php echo $form->label($booking,'postcode'); ?>
<?php echo $form->textField($booking,'postcode',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($booking,'postcode'); ?>
</div>
<br />
<div class="content-bg">
<h3>Step 4</h3>
<div class="five columns alpha">
<?php echo $form->label($booking,'pickupDate'); ?>
<?php echo $form->dropDownDayList($booking, 'pickupDate',array('class' => 'date-day pickup_select','id' => 'pickup')); ?>
<?php echo $form->dropDownYearList($booking,1, 'pickupDate',array('class' => 'date-monthyear pickup_select','id' => 'pickup-month')); ?>
<?php echo $form->hiddenField($booking, 'pickupDate',array('id' => 'pickupData')); ?>
<?php echo $form->error($booking,'pickupDate'); ?>
</div>
<div class="five columns alpha">
<?php echo $form->label($booking,'returnDate'); ?>
<?php echo $form->dropDownDayList($booking, 'returnDate',array('class' => 'date-day return_select','id' => 'return')); ?>
<?php echo $form->dropDownYearList($booking,1, 'returnDate',array('class' => 'date-monthyear return_select','id' => 'return-month')); ?>
<?php echo $form->hiddenField($booking, 'returnDate',array('id' => 'returnData')); ?>
<?php echo $form->error($booking,'returnDate'); ?>
</div>
<br class="clear"/>
</div>
<br />
<div class="content-bg">
<h2>Terms & Conditions</h2>
<p>By submitting this loan enquiry you agree to and acknowledge our Equipment Loan Terms and Conditions.</p>
</div>
<?php echo CHtml::submitButton('Submit'); ?>
<br />
<input class="orange-btn right" type="submit" value="Submit Loan Request">
<?php $this->endWidget(); ?>
</div>
EquipmentRequest partial
<div class="selected-equipment" id="request_<?php echo $request->equipment->equipName; ?>">
<div class="equipment-selected"><?php echo $request->equipment->equipName; ?></div>
<div class="equipment-qty"><?php echo $form->textField($request, "[$index]qty", array('value' => 1,'class' => 'requestQuantity')); ?></div>
<?php echo $form->error($request,"[$index]qty"); ?>
<div class="equipment-update"><span>Remove</span></div>
<?php echo $form->hiddenField($request, "[$index]equipID",array('value' => $request->equipment->equipID)); ?>
   <?php echo $form->error($request,"[$index]equipID"); ?>
<br class="clear">
</div>
EDIT
Please note I have rectified the above issue. Was mainly caused by an incorrect usage of performAjaxValidate, which I have now set to call both the booking and the collection of equipmentRequests.
This is now letting me get 2 validation error message objects back, 1 for both models. however only the booking model is being passed to the error summary div.
#bool.dev appreciate your assistance so far, any ideas with the above, have tried merging the collection of equipment request objects and booking object to the one argument call in errorSummary
I've edited the above to show updated controller actions and views
When you want errorSummary() for more than one model, use:
$form->errorSummary(array($model1,$model2,$model3));

Categories