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?
Related
I followed the tutorial here on how to create a duplicate contact form. I created the 3 files needed. This is working as expected when I go to the url information/form. However, I can't make it work when I want it to be included in another page. I added it in the information page and just call it when the page I needed it to appear is clicked/called.
First off, I removed the header and footer inclusions in the .tpl file because it's already in the parent page. Then I called $this->load->controller('information/form') in the catalog controller where I want it to appear but it's not working. I used $this->load->view('information) and it works but the functionalities are not there (which is obvious because it's only calling for the view).
My current code in catalog/controller/information/information:
public function index() {
$this->load->language('information/information');
$this->load->language('information/form');
$this->load->model('catalog/information');
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$information_id = 0;
if (isset($this->request->get['information_id'])) {
$information_id = (int)$this->request->get['information_id'];
}
$information_info = $this->model_catalog_information->getInformation($information_id);
if ($information_info) {
$this->document->setTitle($information_info['meta_title']);
$this->document->setDescription($information_info['meta_description']);
$this->document->setKeywords($information_info['meta_keyword']);
$data['breadcrumbs'][] = array(
'text' => $information_info['title'],
'href' => $this->url->link('information/information', 'information_id=' . $information_id)
);
$data['heading_title'] = $information_info['title'];
$data['button_continue'] = $this->language->get('button_continue');
$data['description'] = html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8');
$data['continue'] = $this->url->link('common/home');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$contact_data['text_location'] = $this->language->get('text_location');
$contact_data['text_store'] = $this->language->get('text_store');
$contact_data['text_contact'] = $this->language->get('text_contact');
$contact_data['text_address'] = $this->language->get('text_address');
$contact_data['text_telephone'] = $this->language->get('text_telephone');
$contact_data['text_fax'] = $this->language->get('text_fax');
$contact_data['text_open'] = $this->language->get('text_open');
$contact_data['text_comment'] = $this->language->get('text_comment');
$contact_data['text_contact_info'] = $this->language->get('text_contact_info');
$contact_data['entry_name'] = $this->language->get('entry_name');
$contact_data['error_name'] = '';
$contact_data['name'] = '';
$contact_data['entry_email'] = $this->language->get('entry_email');
$contact_data['error_email'] = '';
$contact_data['email'] = '';
$contact_data['entry_telephone'] = $this->language->get('entry_telephone');
$contact_data['error_telephone'] = '';
$contact_data['telephone'] = '';
$contact_data['entry_subject'] = $this->language->get('entry_subject');
$contact_data['error_subject'] = '';
$contact_data['subject'] = '';
$contact_data['entry_enquiry'] = $this->language->get('entry_enquiry');
$contact_data['error_enquiry'] = '';
$contact_data['enquiry'] = '';
$contact_data['captcha'] = '';
$contact_data['button_submit'] = 'SUBMIT';
$contact_data['action'] = $this->url->link('information/form');
/*THIS IS WHERE I CALL THE CUSTOM CONTACT FORM VIEW*/
$data['contact'] = $this->load->view('information/form', $contact_data); //$this->load->controller('information/form');
$this->response->setOutput($this->load->view('information/information', $data));
}
}
Is it achievable? Or do I really need to double everything?
I tell you some steps to duplicate the contact form.
First, you need to create 3 files in their Information directories.
Note: Please Give a Proper Filename like form or etc if you want.
1. catalog\controller\information\form.php
<?php
class ControllerInformationForm extends Controller {
private $error = array();
public function index() {
$this->load->language('information/form');
$this->document->setTitle($this->language->get('heading_title'));
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText($this->request->post['enquiry']);
$mail->send();
$this->response->redirect($this->url->link('information/form/success'));
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/form')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['text_location'] = $this->language->get('text_location');
$data['text_store'] = $this->language->get('text_store');
$data['text_contact'] = $this->language->get('text_contact');
$data['text_address'] = $this->language->get('text_address');
$data['text_telephone'] = $this->language->get('text_telephone');
$data['text_fax'] = $this->language->get('text_fax');
$data['text_open'] = $this->language->get('text_open');
$data['text_comment'] = $this->language->get('text_comment');
$data['entry_name'] = $this->language->get('entry_name');
$data['entry_email'] = $this->language->get('entry_email');
$data['entry_enquiry'] = $this->language->get('entry_enquiry');
$data['button_map'] = $this->language->get('button_map');
if (isset($this->error['name'])) {
$data['error_name'] = $this->error['name'];
} else {
$data['error_name'] = '';
}
if (isset($this->error['email'])) {
$data['error_email'] = $this->error['email'];
} else {
$data['error_email'] = '';
}
if (isset($this->error['enquiry'])) {
$data['error_enquiry'] = $this->error['enquiry'];
} else {
$data['error_enquiry'] = '';
}
$data['button_submit'] = $this->language->get('button_submit');
$data['action'] = $this->url->link('information/form', '', true);
$this->load->model('tool/image');
if ($this->config->get('config_image')) {
$data['image'] = $this->model_tool_image->resize($this->config->get('config_image'), $this->config->get($this->config->get('config_theme') . '_image_location_width'), $this->config->get($this->config->get('config_theme') . '_image_location_height'));
} else {
$data['image'] = false;
}
$data['store'] = $this->config->get('config_name');
$data['address'] = nl2br($this->config->get('config_address'));
$data['geocode'] = $this->config->get('config_geocode');
$data['geocode_hl'] = $this->config->get('config_language');
$data['telephone'] = $this->config->get('config_telephone');
$data['fax'] = $this->config->get('config_fax');
$data['open'] = nl2br($this->config->get('config_open'));
$data['comment'] = $this->config->get('config_comment');
$data['locations'] = array();
$this->load->model('localisation/location');
foreach((array)$this->config->get('config_location') as $location_id) {
$location_info = $this->model_localisation_location->getLocation($location_id);
if ($location_info) {
if ($location_info['image']) {
$image = $this->model_tool_image->resize($location_info['image'], $this->config->get($this->config->get('config_theme') . '_image_location_width'), $this->config->get($this->config->get('config_theme') . '_image_location_height'));
} else {
$image = false;
}
$data['locations'][] = array(
'location_id' => $location_info['location_id'],
'name' => $location_info['name'],
'address' => nl2br($location_info['address']),
'geocode' => $location_info['geocode'],
'telephone' => $location_info['telephone'],
'fax' => $location_info['fax'],
'image' => $image,
'open' => nl2br($location_info['open']),
'comment' => $location_info['comment']
);
}
}
if (isset($this->request->post['name'])) {
$data['name'] = $this->request->post['name'];
} else {
$data['name'] = $this->customer->getFirstName();
}
if (isset($this->request->post['email'])) {
$data['email'] = $this->request->post['email'];
} else {
$data['email'] = $this->customer->getEmail();
}
if (isset($this->request->post['enquiry'])) {
$data['enquiry'] = $this->request->post['enquiry'];
} else {
$data['enquiry'] = '';
}
// Captcha
if ($this->config->get($this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) {
$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha'), $this->error);
} else {
$data['captcha'] = '';
}
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('information/form', $data));
}
protected function validate() {
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
$this->error['name'] = $this->language->get('error_name');
}
if (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
$this->error['email'] = $this->language->get('error_email');
}
if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
$this->error['enquiry'] = $this->language->get('error_enquiry');
}
// Captcha
if ($this->config->get($this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) {
$captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate');
if ($captcha) {
$this->error['captcha'] = $captcha;
}
}
return !$this->error;
}
public function success() {
$this->load->language('information/form');
$this->document->setTitle($this->language->get('heading_title'));
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/form')
);
$data['heading_title'] = $this->language->get('heading_title');
$data['text_message'] = $this->language->get('text_success');
$data['button_continue'] = $this->language->get('button_continue');
$data['continue'] = $this->url->link('common/home');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('common/success', $data));
}
}
2. catalog\view\theme\default\template\information\form.tpl
<?php echo $header; ?>
<div class="container">
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><?php echo $breadcrumb['text']; ?></li>
<?php } ?>
</ul>
<div class="row"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif ($column_left || $column_right) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
<div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?>
<h1><?php echo $heading_title; ?></h1>
<h3><?php echo $text_location; ?></h3>
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<?php if ($image) { ?>
<div class="col-sm-3"><img src="<?php echo $image; ?>" alt="<?php echo $store; ?>" title="<?php echo $store; ?>" class="img-thumbnail" /></div>
<?php } ?>
<div class="col-sm-3"><strong><?php echo $store; ?></strong><br />
<address>
<?php echo $address; ?>
</address>
<?php if ($geocode) { ?>
<i class="fa fa-map-marker"></i> <?php echo $button_map; ?>
<?php } ?>
</div>
<div class="col-sm-3"><strong><?php echo $text_telephone; ?></strong><br>
<?php echo $telephone; ?><br />
<br />
<?php if ($fax) { ?>
<strong><?php echo $text_fax; ?></strong><br>
<?php echo $fax; ?>
<?php } ?>
</div>
<div class="col-sm-3">
<?php if ($open) { ?>
<strong><?php echo $text_open; ?></strong><br />
<?php echo $open; ?><br />
<br />
<?php } ?>
<?php if ($comment) { ?>
<strong><?php echo $text_comment; ?></strong><br />
<?php echo $comment; ?>
<?php } ?>
</div>
</div>
</div>
</div>
<?php if ($locations) { ?>
<h3><?php echo $text_store; ?></h3>
<div class="panel-group" id="accordion">
<?php foreach ($locations as $location) { ?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><?php echo $location['name']; ?> <i class="fa fa-caret-down"></i></h4>
</div>
<div class="panel-collapse collapse" id="collapse-location<?php echo $location['location_id']; ?>">
<div class="panel-body">
<div class="row">
<?php if ($location['image']) { ?>
<div class="col-sm-3"><img src="<?php echo $location['image']; ?>" alt="<?php echo $location['name']; ?>" title="<?php echo $location['name']; ?>" class="img-thumbnail" /></div>
<?php } ?>
<div class="col-sm-3"><strong><?php echo $location['name']; ?></strong><br />
<address>
<?php echo $location['address']; ?>
</address>
<?php if ($location['geocode']) { ?>
<i class="fa fa-map-marker"></i> <?php echo $button_map; ?>
<?php } ?>
</div>
<div class="col-sm-3"> <strong><?php echo $text_telephone; ?></strong><br>
<?php echo $location['telephone']; ?><br />
<br />
<?php if ($location['fax']) { ?>
<strong><?php echo $text_fax; ?></strong><br>
<?php echo $location['fax']; ?>
<?php } ?>
</div>
<div class="col-sm-3">
<?php if ($location['open']) { ?>
<strong><?php echo $text_open; ?></strong><br />
<?php echo $location['open']; ?><br />
<br />
<?php } ?>
<?php if ($location['comment']) { ?>
<strong><?php echo $text_comment; ?></strong><br />
<?php echo $location['comment']; ?>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" class="form-horizontal">
<fieldset>
<legend><?php echo $text_contact; ?></legend>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-name"><?php echo $entry_name; ?></label>
<div class="col-sm-10">
<input type="text" name="name" value="<?php echo $name; ?>" id="input-name" class="form-control" />
<?php if ($error_name) { ?>
<div class="text-danger"><?php echo $error_name; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-email"><?php echo $entry_email; ?></label>
<div class="col-sm-10">
<input type="text" name="email" value="<?php echo $email; ?>" id="input-email" class="form-control" />
<?php if ($error_email) { ?>
<div class="text-danger"><?php echo $error_email; ?></div>
<?php } ?>
</div>
</div>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-enquiry"><?php echo $entry_enquiry; ?></label>
<div class="col-sm-10">
<textarea name="enquiry" rows="10" id="input-enquiry" class="form-control"><?php echo $enquiry; ?></textarea>
<?php if ($error_enquiry) { ?>
<div class="text-danger"><?php echo $error_enquiry; ?></div>
<?php } ?>
</div>
</div>
<?php echo $captcha; ?>
</fieldset>
<div class="buttons">
<div class="pull-right">
<input class="btn btn-primary" type="submit" value="<?php echo $button_submit; ?>" />
</div>
</div>
</form>
<?php echo $content_bottom; ?></div>
<?php echo $column_right; ?></div>
</div>
<?php echo $footer; ?>
3. catalog\language\en-gb\information\form.php
<?php
// Heading
$_['heading_title'] = 'Contact Us';
// Text
$_['text_location'] = 'Our Location';
$_['text_store'] = 'Our Stores';
$_['text_contact'] = 'Contact Form';
$_['text_address'] = 'Address';
$_['text_telephone'] = 'Telephone';
$_['text_fax'] = 'Fax';
$_['text_open'] = 'Opening Times';
$_['text_comment'] = 'Comments';
$_['text_success'] = '<p>Your enquiry has been successfully sent to the store owner!</p>';
// Entry
$_['entry_name'] = 'Your Name';
$_['entry_email'] = 'E-Mail Address';
$_['entry_enquiry'] = 'Enquiry';
// Email
$_['email_subject'] = 'Enquiry %s';
// Errors
$_['error_name'] = 'Name must be between 3 and 32 characters!';
$_['error_email'] = 'E-Mail Address does not appear to be valid!';
$_['error_enquiry'] = 'Enquiry must be between 10 and 3000 characters!';
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'
I am in the learning stage in php.Please help me with my update form.Advanced thanks. I have a form to update any user information with a button "Save" and "Reset" button.I update any information the version number increase.But the problem is when i do not update any information and click on "Save" button the version number increases.It should not increase.I am giving my Controller and form code....
public function actionCreate()
{
$model=new CvUpload;
$model2=new CvUpload;
$UserType=new UserType;
$CvHistory=new CvHistory;
$this->performAjaxValidation($model);
if(!empty($_POST))
{
$id = $_POST['CvUpload']['user_id'];
$cv_type = $_POST['CvUpload']['cv_type'];
$criteria = new CDbCriteria();
$criteria->condition = "user_id = $id AND is_current='yes' AND cv_type='$cv_type'";
$CvUploadmodel = CvUpload::model()->find($criteria);
if(!empty($CvUploadmodel))
{
$CvUploadmodel->is_current='no';
$CvUploadmodel->status='inactive';
if($CvUploadmodel->save(false)){
$model->attributes=$_POST['CvUpload'];
$model->upload_date = new CDbExpression("NOW()");
$model->update_date = new CDbExpression("NOW()");
$model->version_id = $CvUploadmodel->version_id+1;
if($model->save(false))
{
$CvHistory->cv_id = $model->cv_id;
$CvHistory->user_id = $model->user_id;
$CvHistory->job_title_id = $model->job_title_id;
$CvHistory->cv_type = $model->cv_type;
$CvHistory->version_id = $model->version_id;
$CvHistory->file_name = $model->file_name;
$CvHistory->upload_date = $model->upload_date;
$CvHistory->update_date = $model->update_date;
$CvHistory->is_current = $model->is_current;
$CvHistory->status = $model->status;
if($CvHistory->save(false))
{
$this->redirect(array('view','id'=>$model->cv_id));
}
}
}
}
else
{
$model->attributes=$_POST['CvUpload'];
$model->upload_date = new CDbExpression("NOW()");
$model->update_date = new CDbExpression("NOW()");
$model->version_id=1;
if($model->save())
{
$CvHistory->cv_id = $model->cv_id;
$CvHistory->user_id = $model->user_id;
$CvHistory->job_title_id = $model->job_title_id;
$CvHistory->cv_type = $model->cv_type;
$CvHistory->version_id = $model->version_id;
$CvHistory->file_name = $model->file_name;
$CvHistory->upload_date = $model->upload_date;
$CvHistory->update_date = $model->update_date;
$CvHistory->is_current = $model->is_current;
$CvHistory->status = $model->status;
if($CvHistory->save(false))
{
$this->redirect(array('view','id'=>$model->cv_id));
}
}
}
}
$this->render('create',array(
'model'=>$model,
'UserType'=>$UserType,
'CvHistory'=>$CvHistory,
));
}
public function actionUpdate($id)
{
$model=$this->loadModel($id);
$CvHistory=new CvHistory;
if(isset($_POST['CvUpload']))
{
$model->attributes=$_POST['CvUpload'];
if($model->save())
{
$criteria = new CDbCriteria();
$criteria->condition = "cv_id = $model->cv_id AND is_current = 'yes'";
$CvHistory = CvHistory::model()->find($criteria);
$CvHistory->is_current = 'no';
$CvHistory->status = 'inactive';
if($CvHistory->save(false))
{
$new_CvHistory=new CvHistory;
$new_CvHistory->cv_id = $model->cv_id;
$new_CvHistory->user_id = $model->user_id;
$new_CvHistory->job_title_id = $model->job_title_id;
$new_CvHistory->cv_type = $model->cv_type;
$new_CvHistory->version_id = $CvHistory->version_id+1;
$model->version_id = $new_CvHistory->version_id ;
$new_CvHistory->file_name = $model->file_name;
$new_CvHistory->upload_date = $model->upload_date;
$new_CvHistory->update_date = new CDbExpression("NOW()");
$model->update_date = $new_CvHistory->update_date ;
$new_CvHistory->status = $model->status;
$new_CvHistory->is_current = "yes";
$new_CvHistory->save(false);
$model->save(false);
if($new_CvHistory->save(false))$this->redirect(array('view','id'=>$model->cv_id));
}
}
}
$this->render('update',array(
'model'=>$model,
'CvHistory'=>$CvHistory,
));
}
MY form button code:
<style>
#type {
background-color:#f5f5f5;
font-family: 'Arial';
font-size: 20px;
text-decoration: none;
color:#b2b2b2;
border:none;
float: right;
}
div.form label {
display: block;
font-size: 1em;
font-weight: bold;
}
.types-add{
float: right;
}
#type:hover {
border: none;
}
</style>
<?php if (Yii::app()->user->hasFlash('created')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('created'); ?>
</div>
<?php endif; ?>
<div class="form">
<?php $form=$this->beginWidget(
'booster.widgets.TbActiveForm',
array(
'id'=>'CvUpload-form',
'type' => 'horizontal',
'htmlOptions' => array(
'class' => 'well',
'enctype' => 'multipart/form-data',
)
));
?>
<fieldset>
<h1 align="center">CV Upload</h1>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php
$criteria=new CDbCriteria();
echo $form->dropDownListGroup(
$model,
'user_id',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(User::model()->findAll($criteria), 'id', 'user_id'),
'dataProvider'=>$model->searchByUserId(Yii::app()->user->getId()),
'htmlOptions' => array('prompt'=>'Select'),
)
)
); ?>
</div>
<div class="row" id="jobTitle">
<?php
$criteria = new CDbCriteria;
$criteria->condition = "status= 'active'";
echo $form->dropDownListGroup(
$model,
'job_title_id',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => CHtml::listData(JobTitle::model()->findAll($criteria), 'id', 'name'),
'htmlOptions' => array('prompt'=>'Select job title'),
)
)
); ?>
</div>
<?php echo CHtml::form($this->createUrl('uploadreport'), 'post', array('enctype'=>'multipart/form-data'));?>
<label class="col-sm-3 control-label required" for="CvUpload_file_name">
Upload File
</label>
<div class="row" id="file_upload" style="margin-left:20%; margin-bottom:2%;">
<?php
$this->widget('CMultiFileUpload',array(
'name' => 'files',
'accept' => 'doc|docx|pdf',
'max' => 1,
'htmlOptions' => array('size' => 25),
));
echo CHtml::htmlButton('Upload',array(
'onclick'=>'javascript: send();', // on submit call JS send() function
'id'=> 'post-submit-btn', // button id 'newcreate'
'class'=>'btn btn-primary',
));
?>
</div>
<?php Yii::app()->clientScript->registerCoreScript("jquery"); ?>
<script src="http://code.jquery.com/jquery-migrate-1.2.0.js"></script>
<script>
function send(){
var formData = new FormData($("#CvUpload-form")[0]);
$.ajax({
url: '<?php echo Yii::app()->createUrl("CvUpload/upload"); ?>',
type: 'POST',
data: formData,
datatype:'json',
beforeSend: function() {
},
success: function (data) {
$("#CvUpload_file_name").val(data);
},
complete: function() {
},
error: function (data) {
alert("There may a error on uploading. Try again later");
},
cache: false,
contentType: false,
processData: false
});
return false;
}
</script>
<div class="row" id="file_name">
<?php echo $form->textFieldGroup(
$model,'file_name',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
)
);
?>
</div>
<div class="row" id="statustype">
<?php
$status = array('active'=>'Active', 'inactive'=>'Inactive');
echo $form->dropDownListGroup(
$model,
'status',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => $status,
'htmlOptions' => array('prompt'=>'Select a status'),
)
)
); ?>
</div>
<div class="row" id="statustype">
<?php
$is_current = array('yes'=>'Yes', 'no'=>'No');
echo $form->dropDownListGroup(
$model,
'is_current',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => $is_current,
'htmlOptions' => array('prompt'=>'Select a status'),
)
)
); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array(
'class'=>'btn btn-primary',
'style'=>"position:relative; margin-left:25%",
'id'=> 'yt1', // button id
)); ?>
</div>
</fieldset>
<?php $this->endWidget(); ?>
</div><!-- form -->
<!--/*/*
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'cv-upload-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,'user_id'); ?>
<?php echo $form->textField($model,'user_id',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model,'user_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'upload_date');enter code here ?>
<?php echo $form->textField($model,'upload_date'); ?>
<?php echo $form->error($model,'upload_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'file_name'); ?>
<?php echo $form->textField($model,'file_name',array('size'=>60,'maxlength'=>150)); ?>
<?php echo $form->error($model,'file_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'file_location'); ?>
<?php echo $form->textField($model,'file_location',array('size'=>60,'maxlength'=>150)); ?>
<?php echo $form->error($model,'file_location'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
If you don't change form values, it doesn't mean that this data wouldn't be sended to server.
Here at least button save will sended, so this case will always true:
if(!empty($_POST))
You didn't show whole form, but I suggest that fields user_id and cv_type has values (no mater values where changed or not, if form has fields they will be submited)
$id = $_POST['CvUpload']['user_id'];
$cv_type = $_POST['CvUpload']['cv_type'];
That's why model $CvUploadmodel = CvUpload::model()->find($criteria); loads and increament version_id
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');
}
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(); ?>