I need help, i have 50 filefield when i save with looping filefield at 26 to 50 do not save file , but filefield 1 to 25 save to datbase. In localhost xampp it run correcly but the trouble when i hosting to webserver. anybody knows what the problem ?. this is my code in controller and form
//form
<table>
<tr>
<td>
<?php echo $form->labelEx($model,'mutu1'); ?>
<?php echo CHtml::dropDownList(
'NilaiStandarMutu[mutu1]',$model->mutu1,
array(
''=>'Pilihan',
'Ada'=>'Ada',
'Tidak Ada'=>'Tidak Ada',
)
);
?>
<?php echo $form->error($model,'mutu1'); ?>
</td>
<td style="padding-top:18px;padding-left:100px;padding-right:0px">
<?php //echo $form->labelEx($model,'file_mutu1'); ?>
<?php echo $form->fileField($model,'file_mutu1',array('size'=>10)); ?>
<?php echo $form->error($model,'file_mutu1'); ?>
</td>
<?
if(!$model->isNewRecord)
{
?>
<td width=10%>
<? if($model->file_mutu1 <> "") {
echo CHtml::link('<i class="icon icon-search"></i> View File ',Yii::app()->baseUrl . "/FileUpload/".$model->file_mutu1, array('target'=>'_blank'));
} else
{
echo CHtml::link('<i class="icon icon-remove"></i> Tidak ada File ','#');
}
?>
</td>
<? } ?>
</tr>
<tr>
<td>
<?php echo $form->labelEx($model,'mutu2'); ?>
<?php echo CHtml::dropDownList(
'NilaiStandarMutu[mutu2]',$model->mutu2,
array(
''=>'Pilihan',
'Berjalan'=>'Berjalan',
'Tidak Berjalan'=>'Tidak Berjalan',
)
);
?>
<?php echo $form->error($model,'mutu2'); ?>
</td>
<td style="padding-top:18px;padding-left:100px">
<?php //echo $form->labelEx($model,'file_mutu1'); ?>
<?php echo $form->fileField($model,'file_mutu2',array('size'=>10)); ?>
<?php echo $form->error($model,'file_mutu2'); ?>
</td>
<?
if(!$model->isNewRecord)
{
?>
<td width=10%>
<? if($model->file_mutu2 <> "") {
echo CHtml::link('<i class="icon icon-search"></i> View File ',Yii::app()->baseUrl . "/FileUpload/".$model->file_mutu2, array('target'=>'_blank'));
} else
{
echo CHtml::link('<i class="icon icon-remove"></i> Tidak ada File ','#');
}
?>
</td>
<? } ?>
</tr>
//....... until 50
//controller
public function actionCreate()
{
$level = Yii::app()->user->getState("level");
$username = Yii::app()->user->name;
$month = substr(date('Y-m-d'),0,7);
$model=new NilaiStandarMutu;
if(isset($_POST['NilaiStandarMutu']))
{
$model->attributes=$_POST['NilaiStandarMutu'];
$file_standar_mutu->attributes=$_POST['FileStandarMutu'];
$i=1;
$uploadedFile = array();
$fileName = array();
for ($i = 1; $i <= 50; $i++)
{
$rnd = rand(0,9999);
$nama = 'file_mutu' . '' .$i;
$uploadedFile[$i]=CUploadedFile::getInstance($model,$nama);
//var_dump($uploadedFile['$i']);
$fileName[$i] = "{$rnd}-{$uploadedFile[$i]}"; // random number + file name
if(!empty($uploadedFile[$i]))
{
$model->$nama = $fileName[$i];
}
}
if($model->save())
{
$arrlength = count($uploadedFile);
for($x = 0; $x <= $arrlength; $x++) {
if(!empty($uploadedFile[$x])) // check if uploaded file is set or not
{
$uploadedFile[$x]->saveAs(Yii::app()->basePath.'/../FileUpload/'.$fileName[$x]);
}
}
$this->redirect(array('view','id'=>$model->id_nilai_sm));
}
}
if(isset($_GET[mode])=="new")
{
if($level == "prodi")
{
$model->CekJadwal();
$criteria = new CDbCriteria();
$criteria->select = 'tgl_input ';
$criteria->condition ="username='$username' and left(tgl_input,7)='$month'";
$find = NilaiStandarMutu::model()->count($criteria);
if($find >= 1)
{
Yii::app()->user->setFlash('error','Tambah gagal !!, Data sudah ada di tahun yang sama !!');
$this->redirect(array("admin"));
}
}
}
$this->render('create',array(
'model'=>$model,
'file_standar_mutu' => $file_standar_mutu,
));
}
Related
I have a form with fields like pincode,village,district etc. auto fill these values when I enter pincode. Please provide a sample code for achieving this.
thanks in advance.
<tr>
<div class="row">
<td><?php echo $form->labelEx($model,'pin'); ?></td>
<td><?php echo $form->textField($model,'pin',array('size'=>6,'maxlength'=>6,'style'=>'height:34px;')); ?>
<?php echo $form->error($model,'pin'); ?></td>
</div>
<tr>
<div class="row">
<td><?php echo $form->labelEx($model,'street'); ?></td>
<td><?php echo $form->textField($model,'street',array('size'=>25,'maxlength'=>25,'style'=>'height:34px;')); ?>
<?php echo $form->error($model,'street'); ?></td>
</div>
<tr>
<div class="row">
<td><?php echo $form->labelEx($model,'village'); ?></td>
<td><?php echo $form->textField($model,'village',array('size'=>25,'maxlength'=>25,'style'=>'height:34px;')); ?>
<?php echo $form->error($model,'village'); ?></td>
</div>
thanks in advance.
I am assuming your table name is areas, and Areas is Model for that table.
Bellow i am repeating(not exactly) view code from your question and i am attaching ajax call on your pincode field and class property on your other text fields.
<?php echo $form->labelEx($model,'pin'); ?>
<?php echo $form->textField($model,'pin',array(
'size'=>6,
'maxlength'=>6,
'style'=>'height:34px;',
//Ajax call to get the pin related values, onBlur.
'ajax' => array
(
'type' => 'POST',
'dataType'=>'JSON',
'url' => CController::createUrl('site/getValuesByPincode'),
'success'=>'js:function(output){$(".setVillage").val(output.village); $(".setStreet").val(output.street);}'
)
)); ?>
<?php echo $form->error($model,'pin'); ?>
<br/><br/>
<?php echo $form->labelEx($model,'street'); ?>
<?php
//adding a class
echo form->textField($model,'street',array('size'=>25,'maxlength'=>25,'style'=>'height:34px;','class'=>'getStreet'));
?>
<?php echo $form->error($model,'street'); ?>
<br/><br/>
<?php echo $form->labelEx($model,'village'); ?>
<?php
//Ading a class
echo $form->textField($model,'village',array('size'=>25,'maxlength'=>25,'style'=>'height:34px;','class'=>'getVillage'));
?>
<?php echo $form->error($model,'village'); ?>
And i am creating an action getValuesByPincode in my controller(ex: site controller) to serve my ajax call.
public function actionGetValuesByPincode()
{
$pincode = $_POST['Areas']['pin'];
$data = Areas::model()->find('pin=:pin', array(':pin' => $pincode));
$output = array();
if (count($data) > 0)
{
$output['village'] = $data->village;
$output['street'] = $data->street;
echo json_encode($output);
}
}
I've went through this tutorial http://www.yiiframework.com/wiki/561/ajax-login-form-with-validation-errors-inside-jquery-modal-dialog/ It appears to be functioning properly, but instead of the form being in the modal dialog, it just renders it right on the page like zii.widgets.jui.CJuiDialog isn't even there.
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'login-dialog',
'options'=>array(
'title'=>'Login',
'autoOpen'=>false,
),
));?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'user_login_form',
'enableAjaxValidation'=>false,
'enableClientValidation'=>true,
'method' => 'POST',
'clientOptions'=>array(
'validateOnSubmit'=>true,
'validateOnChange'=>true,
'validateOnType'=>false,
),
)); ?>
<h1>
Login</h1>
<p>
Please fill out the following form with your login credentials:</p>
<p class="note">
Fields with <span class="required">*</span> are required.</p>
<div id="login-error-div" class="errorMessage" style="display: none;">
</div>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username',array("onfocus"=>"$('#login-error- div').hide();")); ?>
<?php //echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password',array("onfocus"=>"$('#login-error- div').hide();")); ?>
<?php //echo $form->error($model,'password'); ?>
<p class="hint">
Hint: You may login with <tt>demo/demo</tt>.
</p>
</div>
<div class="row rememberMe">
<?php echo $form->checkBox($model,'rememberMe'); ?>
<?php echo $form->label($model,'rememberMe'); ?>
<?php echo $form->error($model,'rememberMe'); ?>
</div>
<div class="row submit">
<?php echo CHtml::ajaxSubmitButton(
'Sign In',
array('/site/login.GetLogin'),
array(
'beforeSend' => 'function(){
$("#login").attr("disabled",true);
}',
'complete' => 'function(){
$("#user_login_form").each(function(){ this.reset();});
$("#login").attr("disabled",false);
}',
'success'=>'function(data){
var obj = jQuery.parseJSON(data);
// View login errors!
// alert(data);
if(obj.login == "success"){
$("#user_login_form").html("<h4>
Login Successful! Please Wait...</h4>
");
parent.location.href = "/";
}
else{
$("#login-error-div").show();
$("#login-error-div").html("Login failed! Try again.");$("#login-error-div").append("
");
}
}'
),
array("id"=>"login","class" => "btn btn-primary")
); ?>
</div>
<?php $this->endWidget(); ?>
</div>
<!-- form -->
<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
Its suppose to render like this above so when i click the link below it opens
echo CHtml::link('Login', array('/site/login.GetLogin'), array('onclick'=>'$("#login-dialog").dialog("open"); return false;'));
Its built in a widget, if you have a look at the tutorial. Here's the complete widget
<?php
class loginProvider extends CWidget{
public static function actions(){
return array(
'GetLogin'=>'application.components.actions.getLogin',
);
}
public function run(){
$this->renderContent();
}
protected function renderContent(){
echo '<span style="float:right;">';
if(Yii::app()->user->isGuest){
echo CHtml::link('Login', array('/site/login.GetLogin'), array('onclick'=>'$("#login-dialog").dialog("open"); return false;'));
echo '</span>';
$this->getController()- >renderPartial('application.components.views.login',array('model'=>new LoginForm));
}
else
echo CHtml::link('Logout ('.Yii::app()->user->name.')', array('site/logout'), array('visible'=>!Yii::app()->user->isGuest));
echo '</span>';
}
}
I'm new to Yii framework and I need to display the validation error message as in login form "Username cannot be blank". Now, I have a text field where I updated the fields and the during validation I want a message to be displayed. How can I do this?
Controller
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// set the parameters for the bizRule
$params = array('GroupzSupport'=>$model);
// now check the bizrule for this user
if (!Yii::app()->user->checkAccess('updateSelf', $params) &&
!Yii::app()->user->checkAccess('admin'))
{
throw new CHttpException(403, 'You are not authorized to perform this action');
}
else
{
if(isset($_POST['GroupzSupport']))
{
$password_current=$_POST['GroupzSupport']['password_current'];
$pass=$model->validatePassword($password_current);
$model->attributes=$_POST['GroupzSupport'];
if($pass==1)
{
$model->password = $model->hashPassword($_POST['GroupzSupport']['password_new']);
if($model->save())
$this->redirect(array('/messageTemplate/admin'));
}
else {$errors="Incorrect Current password"; print '<span style="color:red"><b>';
print '</b><b>'.$errors;
print '</b></span>';}
}
$this->render('update',array(
'model'=>$model,
));
}
}
View
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'password-recovery-reset-password-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="row"><?php
echo $form->labelEx($model,'username');
echo $form->textField($model,'username',array('size'=>45,'maxlength'=>150));
echo $form->error($model,'username');
?></div>
<div class="row">
<?php echo $form->labelEx($model,'current password'); ?>
<?php echo $form->passwordField($model,'password_current',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'password_current'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'new password'); ?>
<?php echo $form->textField($model,'password_new',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'password_new'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'confirm new password'); ?>
<?php echo $form->passwordField($model,'password_repeat',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'password_repeat'); ?>
</div>
<div class="row buttons"><?php
echo CHtml::submitButton('Reset Your Password');
?></div><?php
$this->endWidget(); ?>
</div>
Now currently I'm displaying it at the top.
I want to display it right on the textfield as in login page. How can I do this?
Before redirect, add the message to the desired field.
In the model Validator:
$this->addError('field_name', "Message error.");
Or in Controller action:
$model->addError('field_name', "Message error.");
I am working with a Joomla 2.5 template called Sj_news25 - see the demo here http://demo.smartaddons.com/templates/joomla17/sj-news/
What I want to do is create a module position somewhere between the logo and the search box, so I can fit a language switcher flags there. I have previously used a tutorial on http://docs.joomla.org/How_do_you_add_a_new_module_position%3F and that has worked fine, but this template uses a so-called "Yt Framework" and when I look at the index.php file, I'm stumped. Is there anyone here who could venture a guess? Thanks!
<?php
/****************************************************************************************
* #copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* #license GNU/GPL, see LICENSE.php
* Yt Framework
****************************************************************************************/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
include_once (dirname(__FILE__).DS.'includes'.DS.'yt_template.class.php');
include_once (dirname(__FILE__).DS.'includes'.DS.'frame_inc.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language; ?>" <?php echo ($ytrtl == 'rtl')?'dir="rtl"':''; ?> lang="<?php echo $this->language; ?>">
<head>
<jdoc:include type="head" />
</head>
<body id="<?php echo $yt->template; ?>" class="<?php echo $yt->isHomePage()?'homepage ':'';
echo isset($_GET['option'])?$_GET['option'].' ':'';
echo isset($_GET['view'])?'view-'.$_GET['view'].' ':'';
echo $yt->getParam('sitestyle').' ';
echo $ytrtl=='rtl'?'rtl'.' ':'';
echo $yt->getParam('menustyle').' ';
echo 'fs'.$yt->getParam('fontsize'); ?>">
<div id="yt-wrapper"><div id="yt-wrapper-inner1"><div id="yt-wrapper-inner2">
<?php
// add mobile head
if( $yt->is_mobile ){
include_once (dirname(__FILE__).DS.'includes'.DS.'mobile_head.php');
}
?>
<a id="top" name="scroll-to-top"></a>
<?php
foreach($yt_render->arr_TB as $tagBD): if( $tagBD["countModules"] > 0 ){
if( ($tagBD["name"] == 'content') ){ // Block content - #content ?>
<div id="<?php echo $tagBD["id"]; ?>" class="<?php echo $yt_render->layouttype.$tagBD['class_content'];?>">
<?php
//
if($tagBD['showDivTop']=='1'){ ?>
<div class="yt-main yt-div-top-1"><div class="yt-div-top-2"><div class="yt-div-top-3"></div></div></div>
<?php } ?>
<div class="yt-main"><div class="yt-main-in1"><div class="yt-main-in2 clearfix">
<?php
$countL = $countR = $countM = $countCL1 = $countCL2 = 0;
foreach($tagBD['positions'] as $position):
if( isset($position['column']) && $position['column'] == 'yt-col1' ){
$countCL1++;
if($countCL1==1){
?>
<div id="yt-col1" style="float:left; width:<?php echo $yt_render->cinfo['w-yt-col1']; ?>;<?php echo $yt_render->cinfo['display-yt-col1']; ?>">
<?php
include (dirname(__FILE__).DS.'includes'.DS.'block-content.php');
if($tagBD['count-yt-col1']==1){
?>
</div>
<?php
}
}elseif( $countCL1==$tagBD['count-yt-col1'] && $tagBD['count-yt-col1']>1 ){
include (dirname(__FILE__).DS.'includes'.DS.'block-content.php');
?>
</div>
<?php
}else{
include (dirname(__FILE__).DS.'includes'.DS.'block-content.php');
}
}elseif( isset($position['column']) && $position['column'] == 'yt-col2' ){
$countCL2++;
if($countCL2==1){
?>
<div id="yt-col2" style="float:right; width:<?php echo $yt_render->cinfo['w-yt-col2']; ?>;<?php echo $yt_render->cinfo['display-yt-col2']; ?>">
<?php
include (dirname(__FILE__).DS.'includes'.DS.'block-content.php');
if($tagBD['count-yt-col2']==1){
?>
</div>
<?php
}
}elseif( $countCL2==$tagBD['count-yt-col2'] && $tagBD['count-yt-col2']>1 ){
include (dirname(__FILE__).DS.'includes'.DS.'block-content.php');
?>
</div>
<?php
}else{
include (dirname(__FILE__).DS.'includes'.DS.'block-content.php');
}
}else{
include (dirname(__FILE__).DS.'includes'.DS.'block-content.php');
}
endforeach; //End foreach position of block content
?>
</div></div></div>
<?php
//
if($tagBD['showDivBottom']=='1'){ ?>
<div class="yt-main yt-div-bottom-1"><div class="yt-div-bottom-2"><div class="yt-div-bottom-3"></div></div></div>
<?php } ?>
</div>
<?php
}elseif($tagBD["name"] != 'content'){ // Block is not content
?>
<div id="<?php echo $tagBD["id"]; ?>">
<div class="yt-main"><div class="yt-main-in1"><div class="yt-main-in2 clearfix">
<?php
if( !empty($tagBD["hasGroup"]) && $tagBD["hasGroup"]=="1"){ // Tag Body has group
$flag = ''; $openG = 0; $c = 0;
foreach( $tagBD['positions'] as $posFG ): $c = $c+1;
if( $posFG['group'] != "" && $posFG['group']!= $flag){
$flag = $posFG['group'];
if($openG == 0){ $openG =1;?>
<div class="group-<?php echo $flag.$tagBD['class_groupnormal'];?> clearfix" style="<?php echo isset($tagBD['width-'.$flag])?'width:'.$tagBD['width-'.$flag].'; ':'' ; ?><?php echo $float1;?>">
<?php
echo $yt->renPositionGroup($posFG);
if($c == count( $tagBD['positions']) ){echo '</div>';}
}else{
$openG = 0;
?>
</div>
<div class="group-<?php echo $flag; ?>" style="width:<?php echo $tagBD['width-'.$flag]; ?>; <?php echo $float1;?>">
<?php
echo $yt->renPositionGroup($posFG);
}
}elseif($posFG['group']!="" && $posFG['group'] == $flag){
echo $yt->renPositionGroup($posFG);
if($c == count( $tagBD['positions']) ){echo '</div>';}
}elseif($posFG['group']==""){
if($openG ==1){
$openG = 0;
echo '</div>';
}
echo $yt->renPositionGroup($posFG);
}
endforeach;
}else{ //Tag Body normal
if(isset($tagBD['positions'])){
if(isset($tagBD['autosize'])){
echo $yt->renPositionNormals($tagBD['positions'], $tagBD["countModules"], $tagBD["limited"], $tagBD['autosize']);
}else{
echo $yt->renPositionNormals($tagBD['positions'], $tagBD["countModules"], $tagBD["limited"]);
}
}
}
?>
</div></div></div>
</div>
<?php
} // end elseif($tagBD["name"] != 'content')
}
endforeach;
?>
</div></div></div>
<jdoc:include type="modules" name="debug" />
<?php
if( !$yt->is_mobile && $yt->getParam('showCpanel') ) {
include_once (dirname(__FILE__).DS.'includes'.DS.'cpanel.php');
}
?>
</body>
</html>
<?php /*}*/ ?>
Please go to file: your_template/layouts/layout-homepage.xml(or current layout) replace code:
#logo
header1
by:
#logo
your_position
header1
You can find out more about Yt Framework here: http://www.smartaddons.com/joomla/templates/yt-framework
friends!
i generated a dynamic product field and quantity filed with javascript in order customer makes ordering over one product. but why does controller can't set POST['OrderDetail']? the controller can save only one model, Order.
Please help to correct me.
I have four models: Product, Customer, Order, and Order_detail.
view/order/_form.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'order-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'customer_id'); ?>
<?php //echo $form->textField($model,'customer_id'); ?>
<?php echo $form->dropDownList($model,'customer_id',CHtml::listData(Customers::model()->findAll(),'customer_id','fullname'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error($model,'customer_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'order_status'); ?>
<?php echo $form->textField($model,'order_status'); ?>
<?php //echo $form->dropDownList($model,'order_id', array(1=>'Pending', 2=>'Processing',3=>'Completed'));?>
<?php echo $form->error($model,'order_status'); ?>
</div>
<?php /*?>
<div class="row">
<?php echo $form->labelEx($model,'lat'); ?>
<?php echo $form->textField($model,'lat'); ?>
<?php echo $form->error($model,'lat'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'lng'); ?>
<?php echo $form->textField($model,'lng'); ?>
<?php echo $form->error($model,'lng'); ?>
</div>
<?php */?>
<div class="row">
<?php echo $form->labelEx($model,'address'); ?>
<?php echo $form->textField($model,'address',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'address'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'staff_id'); ?>
<?php //echo $form->textField($model,'staff_id'); ?>
<?php echo $form->dropDownList($model,'staff_id',CHtml::listData(Staff::model()->findAll(),'staff_id','fullname'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error($model,'staff_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'received_date'); ?>
<?php echo $form->textField($model,'received_date'); ?>
<?php echo $form->error($model,'received_date'); ?>
</div>
<script type="text/javascript">
function addProduct() {
var ni = document.getElementById('divProduct');
var numi = document.getElementById('countLastInput');
var num = (document.getElementById('countLastInput').value -1)+ 2;
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = num;
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = <?php echo $form->dropDownList($orderdetail,'product_id',CHtml::listData(Products::model()->findAll(),'product_id','product_name'),
array('empty' => '--- Choose---','name'=>'productorder[]')); ?>+<?php echo $form->textField($orderdetail,'qty', array('name'=>'qtyorder[]')); ?>+'Remove';
ni.appendChild(newdiv);
}
function removePhoto(divNum) {
var d = document.getElementById('divProduct');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
var minus=document.getElementById('countLastInput').value;
document.getElementById('countLastInput').value=minus-1;
}
</script>
<div id="divProduct"> </div>
<input type="button" name="service_photo" value="Add Product" class="Allbutton" onclick="addProduct();" />
<input type="hidden" value="0" id="countLastInput" name="countLastInput" />
<?php /*?>
<div class="row">
<?php echo $form->labelEx($orderdetail,'product_id'); ?>
<?php echo $form->dropDownList($orderdetail,'product_id',CHtml::listData(Products::model()->findAll(),'product_id','product_name'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error($orderdetail,'product_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($orderdetail,'qty'); ?>
<?php echo $form->textField($orderdetail,'qty'); ?>
<?php echo $form->error($orderdetail,'qty'); ?>
</div>
<?php /*?>
<?php //$orderdetail=new OrderDetail();?>
<?php //echo $this->renderPartial("_partial_order",array('orderdetail'=>$orderdetail));?>
<?php /* ?><form action="php_multiple_textbox4.php" method="post" name="form1">
<input type="text" name="txtSiteName[]">
<input name="btnButton" type="button" value="+" onClick="JavaScript:fncCreateElement();"><br>
<span id="mySpan"></span>
<input name="btnSubmit" type="submit" value="Submit">
</form>
<?php */?>
<?php /*?>
<div class="row">
<?php echo $form->labelEx($model,'completed_date'); ?>
<?php echo $form->textField($model,'completed_date'); ?>
<?php echo $form->error($model,'completed_date'); ?>
</div>
<?php */?>
<?php /*?>
<div class="row">
<?php echo $form->labelEx($model,'created_date'); ?>
<?php echo $form->textField($model,'created_date'); ?>
<?php echo $form->error($model,'created_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'upated_date'); ?>
<?php echo $form->textField($model,'upated_date'); ?>
<?php echo $form->error($model,'upated_date'); ?>
</div>
<?php */?>
<?php /*?>
<table id="students">
<thead>
<tr>
<td>Product Name</td>
<td>Quantity</td>
<td>
<?php echo CHtml::link('<b>Add Product</b>', '', array('onClick'=>'addProduct($(this))', 'class'=>'add'));?>
</td>
</tr>
</thead>
</table>
<input type="hidden" value="0" id=lastInput name="lastInput" />
<?php */?>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
OrderController.php
<?php
class OrderController extends Controller
{
/**
* #var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';
public $orderid;
/**
* #return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* #return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','showlog'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('*'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('*'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
/**
* Displays a particular model.
* #param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionShowLog(){
//Yii::log("hi, h r u?" ,"trace","application.controllers.OrderController");
var_dump(Yii::getLogger()->getLogs());
//Yii::trace("The actionCreate() method is being requested","application.controllers.OrderController");
}
public function actionCreate()
{
$model=new Order;
$orderdetail=new OrderDetail();
$product=new Products();
$date=date('y-m-d');
// Uncomment the following line if AJAX validation is needed
//$this->performAjaxValidation(array($model,$orderdetail));
if(isset($_POST['Order']))
{
$model->attributes=$_POST['Order'];
$model->lat='12.53';
$model->lng='13.2';
$model->completed_date=$date;
$model->received_date=$date;
$model->created_date=$date;
$model->upated_date=$date;
if($model->save())
{
Yii::log("order save","info","application.controllers.OrderController");
if(isset($_POST['OrderDetail'])){
for($i=1;$i<count($_POST['productorder']);$i++){
//$orderdetail->attributes=$_POST['OrderDetail'];
$orderdetail->product_id=$_POST['productorder'][$i];
$orderdetail->qty=$_POST['qtyorder'][$i];
$orderdetail->order_id= $model->order_id;
$orderdetail->order_item_status=1;
$orderdetail->created_date=$date;
$orderdetail->updated_date=$date;
$orderdetail->save();
}
$this->redirect(array('view','id'=>$model->order_id));
//$qty=$orderdetail->qty=$_POST['qty'];
//$productid=$orderdetail->product_id=$_POST['txtproduct'];
/*
for($i=1;$i<=count($qty);$i++){
$orderdetail->order_id= $model->order_id;
$orderdetail->order_item_status=1;
$orderdetail->created_date=$date;
$orderdetail->updated_date=$date;
$orderdetail->product_id=1;
//$orderdetail->qty=$qty[$i];
//$orderdetail->save();
var_dump($_POST['qty']);
}
$this->redirect(array('view','id'=>$model->order_id));
*/
}else{
Yii::log("Failed ordedetails","warning","application.controllers.OrderController");
}
//$OrderDetailController=new OrderDetail();
//$this->redirect(array('OrderDetail/create'));
}
}
$this->render('create',array(
'model'=>$model,
'orderdetail'=>$orderdetail,
'product'=>$product,
));
}
/*
public function actionCreate()
{
Yii::import('ext.multimodelform.MultiModelForm');
$model = new Order;
$orderdetail=new OrderDetail();
$product=new Products();
$validatedMembers = array(); //ensure an empty array
if(isset($_POST['Order']))
{
$model->attributes=$_POST['Order'];
if( //validate detail before saving the master
MultiModelForm::validate($model,$validatedMembers,$deleteItems) &&
$model->save()
)
{
//the value for the foreign key 'groupid'
$masterValues = array ('order_id'=>$model->order_id);
if (MultiModelForm::save($model,$validatedMembers,$deleteMembers,$masterValues))
$this->redirect(array('view','id'=>$model->order_id));
}
}
$this->render('create',array(
'model'=>$model,
//submit the member and validatedItems to the widget in the edit form
'orderdetail'=>$orderdetail,
'product'=>$product,
'validatedMembers' => $validatedMembers,
));
}
*/
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* #param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$date=date('y-m-d');
$model=$this->loadModel($id);
//$orderdetail=new OrderDetail();
$product=new Products();
$orderdetail=OrderDetail::model()->findByAttributes(array('order_id'=>$_GET['id']));
//$product->findByAttributes(array('order_id'=>$_GET['id']));
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Order']))
{
$model->attributes=$_POST['Order'];
$model->lat='12.53';
$model->lng='13.2';
$model->completed_date=$date;
$model->received_date=$date;
$model->created_date=$date;
$model->upated_date=$date;
if($model->save())
if(isset($_POST['OrderDetail'])){
$orderdetail->attributes=$_POST['OrderDetail'];
$orderdetail->order_id= $model->order_id;
$orderdetail->order_item_status=1;
$orderdetail->created_date=$date;
$orderdetail->updated_date=$date;
if($orderdetail->save())
$this->redirect(array('view','id'=>$model->order_id));
}
}
$this->render('update',array(
'model'=>$model,
'orderdetail'=>$orderdetail,
'product'=>$product,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* #param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Order');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new Order('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Order']))
$model->attributes=$_GET['Order'];
$this->render('admin',array(
'model'=>$model,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* #param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model=Order::model()->findByPk((int)$id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
//$model=Order::model()->with(Products::model(),OrderDetail::model())->findByPk((int)$id);
// if($model===null)
// throw new CHttpException(404,'Page not found.');
//return $model;
}
/**
* Performs the AJAX validation.
* #param CModel the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='order-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
Thanks in advance.
Try to enable CWebLogRoute to see if you have any security issues.
Yii wiki: How to log and debug variables using CWebLogRoute