CakePHP: FormHelper Timefield not inserting any data - php

The formHelper For time is not inserting data to the database:
+---------------------------------------------------+
|attendence_id|id |in_time |out_time|date. |
+---------------------------------------------------+
|15 |4 |00:00:30 |00:00:30|2014-04-12|
+---------------------------------------------------+
My View
<div class="index">
<?php
echo $this->Form->create('Employee In Time');
echo $this->Form->input('Employee ID',array("name"=>"id"));
echo $this->Form->input('In Time', array(
'name' => 'in_time',
'timeFormat' => '24',
'type' => 'time',
'selected' => '09:30:00'
));
echo $this->Form->input('Out Time', array(
'name' => 'out_time',
'timeFormat' => '24',
'type' => 'time',
'selected' => '09:30:00'
));
echo $this->Form->input('Date Insert in Y/M/D', array(
'name' => 'date',
'dateFormat' => 'YMD',
'minYear' => date('Y') - 70,
'maxYear' => date('Y') - 18 ));
echo $this->Form->end('Add');
?>
</div>
<div class="actions">
<h3>Actions</h3>
<ul>
<li>New Employee</li>
<li>Attendance</li>
<li>Salary Calculator</li>
</ul>
</div>
My Model
class Attendence extends AppModel {
function add($data){
if (!empty($data)) {
$this->create();
if($this->save($data)) {
return true ;
}
}
}
My Controller
class AttendencesController extends AppController {
public function intime()
{
if($this->Attendence->add($this->request->data)==true){
$this->redirect(array('action'=>'intime'));
}
}
}
Please Help

Take attention on CakePHP´s code convention:
The first parameter of echo $this->Form->create('Model'); is the model name, the view is related to. Replace your Employee in Time by your model´s name: echo $this->Form->create('Attendence');
I suggest to put your model´s code into the controller:
class AttendencesController extends AppController
{
public function intime()
{
if($this->request->is('post','put'))
{
$this->Attendence->create();
if($this->Attendence->save($this->request->data))
{
$this->redirect(array('action'=>'intime'));
}
}
}
}

Related

How to checkboxlist checked in Yii 1.6?

I am beginner in Yii Framework.I have created the _form.php with Yii widget CActiveForm.I have made the Checkbox list for week of days.I have serialized checkbox values on actioncreate and save into database table.Actually problem is that When i calling the actionupdate then my checked values are not showing that i have insert on actioncreate.actioncreate and actionupdate using the same form _form.php.
I have written my code below
actioncreate
public function actionCreate()
{
$model=new CustomerAccounts;
if(isset($_POST['CustomerAccounts']))
{
$model->attributes=$_POST['CustomerAccounts'];
$model->DateCreated = date('Y-m-d H:i:s');
$model->DeliveryDay = serialize($_POST['CustomerAccounts']['DeliveryDay']);
if($model->save()) {
Yii::app()->user->setFlash('success', 'Customer Account create successfully.');
$this->redirect(array('admin'));
} else {
Yii::app()->user->setFlash('danger','An error occurred. Please try again.');
}
}
$this->render('create',array(
'model'=>$model,
));
}
actionupdate
public function actionUpdate($id)
{
$model=$this->loadModel($id);
if(isset($_POST['CustomerAccounts']))
{
$model->attributes=$_POST['CustomerAccounts'];
$model->DeliveryDay = serialize($_POST['CustomerAccounts']['DeliveryDay']);
$model->DateCreated = date('Y-m-d H:i:s');
if($model->save()) {
Yii::app()->user->setFlash('success', 'Customer Account update successfully.');
$this->redirect(array('admin'));
} else {
Yii::app()->user->setFlash('danger','An error occurred. Please try again.');
}
}
$this->render('update',array(
'model'=>$model,
));
}
_form.php
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'customer-accounts-form',
'enableAjaxValidation'=>false,
<div class="row">
<div class="col-lg-12" style="padding-left: 34px;">
<?php echo $form->labelEx($model, 'DeliveryDay'); ?>
<?php echo $form->error($model, 'DeliveryDay'); ?>
<div id="checkbox" style="padding-left: 90px;">
<?php
$htmlOptions = array('template' => '<tr><td >{input}</td> <td> {label}</td> </tr', 'multiple' => true, 'checked' => 'checked');
echo $form->checkBoxList($model, 'DeliveryDay', Yii::app()->params['WeekDays'], $htmlOptions);
?>
</div></div></div>
<?php $this->endWidget(); ?>
Here my model
class CustomerAccounts extends CActiveRecord
{
public function tableName()
{
return 'customer_accounts';
}
public function rules()
{
return array(
array('DeliveryDay, Status, CustomerID, Employee_ID, PaymentModeID', 'required'),
array('CustomerID, Employee_ID, PaymentModeID, PcBottle, Bottle6Ltr, Bottle1500Ml, Bottle500Ml, TabStand, Pump, DispensirStatus, PCBottlesQuantity, PCBottleSecurity, DispensirQuantity, DispensirSerialNo, DispensirSecurity, TotalAmount, Status', 'numerical', 'integerOnly'=>true),
array('DateJoin', 'length', 'max'=>250),
array('Description', 'safe'),
array('CustomerAccountID, CustomerID, Employee_ID, PaymentModeID, DateJoin, PcBottle, Bottle6Ltr, Bottle1500Ml, Bottle500Ml, TabStand, Pump, DispensirStatus, PCBottlesQuantity, PCBottleSecurity, DispensirQuantity, DispensirSerialNo, DispensirSecurity, TotalAmount, DeliveryDay, Description, Status, DateCreated', 'safe', 'on'=>'search'),
);
}
public function relations()
{
return array(
'customer' => array(self::BELONGS_TO, 'Customer', 'CustomerID'),
'employee' => array(self::BELONGS_TO, 'Employee', 'Employee_ID'),
'paymentMode' => array(self::BELONGS_TO, 'PaymentMods', 'PaymentModeID'),
);
}
public function attributeLabels()
{
return array(
'CustomerAccountID' => 'Customer Account',
'CustomerID' => 'Customer',
//'Employee_ID' => 'Employee',
'Employee_ID' => 'Sale Person',
'PaymentModeID' => 'Payment Mode',
'DateJoin' => 'Date Join',
'PcBottle' => 'Pc Bottle',
'Bottle6Ltr' => 'Bottle6 Ltr',
'Bottle1500Ml' => 'Bottle1500 Ml',
'Bottle500Ml' => 'Bottle500 Ml',
'TabStand' => 'Tab Stand',
'Pump' => 'Pump',
'DispensirStatus' => 'Dispensir Status',
'PCBottlesQuantity' => 'Pcbottles Quantity',
'PCBottleSecurity' => 'Pcbottle Security',
'DispensirQuantity' => 'Dispensir Quantity',
'DispensirSerialNo' => 'Dispensir Serial No',
'DispensirSecurity' => 'Dispensir Security',
'TotalAmount' => 'Total Amount',
'DeliveryDay' => 'Delivery Day',
'Description' => 'Description',
'Status' => 'Status',
'DateCreated' => 'Date Created',
);
}
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('CustomerAccountID',$this->CustomerAccountID);
$criteria->compare('CustomerID',$this->CustomerID);
$criteria->compare('Employee_ID',$this->Employee_ID);
$criteria->compare('PaymentModeID',$this->PaymentModeID);
$criteria->compare('DateJoin',$this->DateJoin,true);
$criteria->compare('PcBottle',$this->PcBottle);
$criteria->compare('Bottle6Ltr',$this->Bottle6Ltr);
$criteria->compare('Bottle1500Ml',$this->Bottle1500Ml);
$criteria->compare('Bottle500Ml',$this->Bottle500Ml);
$criteria->compare('TabStand',$this->TabStand);
$criteria->compare('Pump',$this->Pump);
$criteria->compare('DispensirStatus',$this->DispensirStatus);
$criteria->compare('PCBottlesQuantity',$this->PCBottlesQuantity);
$criteria->compare('PCBottleSecurity',$this->PCBottleSecurity);
$criteria->compare('DispensirQuantity',$this->DispensirQuantity);
$criteria->compare('DispensirSerialNo',$this->DispensirSerialNo);
$criteria->compare('DispensirSecurity',$this->DispensirSecurity);
$criteria->compare('TotalAmount',$this->TotalAmount);
$criteria->compare('DeliveryDay',$this->DeliveryDay,true);
$criteria->compare('Description',$this->Description,true);
$criteria->compare('Status',$this->Status);
$criteria->compare('DateCreated',$this->DateCreated,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
Would anyone Can tell me when i call the actionupdate How the checked values will be shows from database table ?
You have to unserialized checkbox values afterFind() function in your model file (i.e. models/CustomerAccounts.php) as follows:
public function afterFind() {
$this->DeliveryDay = unserialize($this->DeliveryDay);
parent::afterFind();
}

Connecting Radio Button to Database using CodeIgniter

I got trouble inputing the radio button value to database, when i choose "submit" it won't add into database. This is the form view:
<?php
$form = array(
'no pengujian' => array(
'name' => 'NO_PENGUJIAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_PENGUJIAN', isset($form_value['NO_PENGUJIAN']))),
'id kendaraan' => array(
'name' => 'ID_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('ID_KENDARAAN', isset($form_value['ID_KENDARAAN']))),
'no kendaraan' => array(
'name' => 'NO_KENDARAAN',
'size' => '30',
'class' => 'form_field',
'value' => set_value('NO_KENDARAAN', isset($form_value['NO_KENDARAAN']))),
'lampu' => array(
'name' => 'LAMPU',
'size' => '30',
'class' => 'radio',
'value' => set_value('LAMPU', isset($_POST['LAMPU']))),
'submit' => array(
'name' => 'submit',
'id' => 'submit',
'value' => 'Simpan'
)
);
?>
<h2><?php echo $breadcrumb ?></h2>
<!-- pesan start -->
<?php if (! empty($pesan)) : ?>
<div class="pesan">
<?php echo $pesan; ?>
</div>
<?php endif ?>
<!-- pesan end -->
<!-- form start -->
<?php echo form_open($form_action); ?>
<p>
<?php echo form_label('No Pengujian', 'NO_PENGUJIAN'); ?>
<?php echo form_input($form['no pengujian']); ?>
</p>
<?php echo form_error('NO_PENGUJIAN', '<p class = "field_error">', '</p>');?>
<p>
<?php echo form_label('Id Kendaraan', 'ID_KENDARAAN'); ?>
<?php echo form_input($form['id kendaraan']); ?>
</p>
<?php echo form_error('ID_KENDARAAN', '<p class="field_error">', '</p>'); ?>
<p>
<?php echo form_label('No Kendaraan', 'NO_KENDARAAN'); ?>
<?php echo form_input($form['no kendaraan']); ?>
</p>
<?php echo form_error('NO_KENDARAAN', '<p class="field_error">', '</p>'); ?>
<p>
<?php echo form_label('Lampu', 'LAMPU'); ?>
<input type ="radio" name = "lulus" value="Lulus"/> Lulus
<input type ="radio" name = "lulus" value= "Gagal"/> Gagal
</p>
<p>
<?php echo form_submit($form['submit']); ?>
<?php echo anchor('pengujian', 'Batal', array('class' => 'cancel')) ?>
</p>
<?php echo form_close(); ?>
This is the controller (tambah is "insert" function to database)
<?php if (!defined('BASEPATH')) exit ('No direct script access allowed');
class Pengujian extends MY_Controller
{
public $data = array(
'modul' => 'pengujian',
'breadcrumb' => 'Pengujian',
'pesan' => '',
'pagination' => '',
'tabel_data' => '',
'main_view' => 'view_pengujian/pengujian_view',
'form_action' => '',
'form_value' => '',
'option_uji' => '',
);
public function __construct()
{
parent::__construct();
$this->load->model('Pengujian_model', 'pengujian', TRUE);
$this->load->helper('form');
//$this->load->model('Penguji_model', 'penguji', TRUE);
}
public function index($offset = 0)
{
$this->session->unset_userdata('no_pengujian_sekarang', '');
$pengujian = $this->pengujian->cari_semua($offset);
if ($pengujian)
{
$tabel = $this->pengujian->buat_tabel($pengujian);
$this->data['tabel_data'] = $tabel;
$this->data['pagination'] = $this->pengujian->paging(site_url('pengujian/halaman'));
}
else
{
$this->data['pesan'] = 'Tidak ada data pengujian';
}
$this->load->view('template', $this->data);
}
public function tambah()
{
$this->data['breadcrumb'] = 'Pengujian > Tambah';
$this->data['main_view'] = 'view_pengujian/pengujian_form';
$this->data['form_action'] = 'pengujian/tambah';
//$penguji = $this->penguji->cari_semua();
//if($penguji)
//{
// foreach($penguji as $row)
// {
// $this->data['option_pengujian'][$row->id_penguji] = $row->penguji;
//}
//}
//else
//{
$this->data['option_pengujian']['00'] = '-';
// $this->data['pesan'] = 'Data penguji tidak tersedia. Silahkan isi dahulu data penguji.';
// if submit
if($this->input->post('submit'))
{
if($this->pengujian->validasi_tambah())
{
if($this->pengujian->tambah())
{
$this->session->set_flashdata('pesan', ' Proses tambah data berhasil');
redirect('pengujian');
}
else
{
$this->data['pesan'] = 'Proses tambah data gagal';
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
else
{
$this->load->view('template', $this->data);
}
}
This is the model:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Pengujian_model extends CI_Model
{
public $db_tabel ='pengujian';
public $per_halaman = 100;
public $offset = 0;
public function cari_semua($offset = 0)
{
if (is_null($offset) || empty($offset))
{
$this->offset = 0;
}
else
{
$this->offset = ($offset * $this->per_halaman) - $this->per_halaman;
}
return $this->db->select('NO_PENGUJIAN, ID_KENDARAAN, NO_KENDARAAN, LAMPU, EMISI, REM, WAKTU_UJI')
->from($this->db_tabel)
->limit($this->per_halaman, $this->offset)
->order_by('NO_PENGUJIAN', 'ASC')
->get()
->result();
}
public function buat_tabel($data)
{
$this->load->library('table');
$tmpl = array('row_alt_start' => '<tr class="zebra">');
$this->table->set_template($tmpl);
$this->table->set_heading('No', 'No Pengujian', 'Id Kendaraan', 'No Kendaraan', 'Lampu','Emisi','Rem', 'Waktu Uji', 'Aksi');
$no = 0 + $this->offset;
foreach ($data as $row)
{
$this->table->add_row(
++$no,
$row->NO_PENGUJIAN,
$row->ID_KENDARAAN,
$row->NO_KENDARAAN,
$row->LAMPU,
$row->EMISI,
$row->REM,
$row->WAKTU_UJI,
anchor('pengujian/edit/'.$row->NO_PENGUJIAN,'Edit',array('class' => 'edit')).' '.
anchor('pengujian/hapus/'.$row->NO_PENGUJIAN,'Hapus',array('class' => 'delete','onclick'=>"return confirm('Anda yakin menghapus data ini?')")));
}
$tabel = $this->table->generate();
return $tabel;
}
public function paging($base_url)
{
$this->load->library('pagination');
$config = array(
'base_url' => $base_url,
'total_rows' => $this->hitung_semua(),
'per_page' => $this->per_halaman,
'num_links' => 4,
'use_page_number' => TRUE,
'first link' => '|< First',
'last link' => 'Last >|',
'next link' => 'Next >',
'prev_link' => '< Prev',
);
$this->pagination->initialize($config);
return $this->pagination->create_links();
}
public function hitung_semua()
{
return $this->db->count_all($this->db_tabel);
}
private function load_form_rules_tambah()
{
$form = array(
array(
'field' => 'NO_PENGUJIAN',
'label' => 'no pengujian',
'rules' => 'required'
),
array(
'field' => 'ID_KENDARAAN',
'label' => 'id kendaraan',
'rules' => 'required'
),
array(
'field' => 'NO_KENDARAAN',
'label' => 'no kendaraan',
'rules' => 'required'
),
array(
'field' => 'LAMPU',
'label' => 'lampu',
'rules' => 'required'
),
);
return $form;
}
public function validasi_tambah()
{
$form = $this->load_form_rules_tambah();
$this->form_validation->set_rules($form);
if($this->form_validation->run())
{
return TRUE;
}
else
{
return FALSE;
}
}
public function tambah()
{
$pengujian = array(
'NO_PENGUJIAN' => $this->input->post('NO_PENGUJIAN'),
'ID_KENDARAAN' => $this->input->post('ID_KENDARAAN'),
'NO_KENDARAAN' => $this->input->post('NO_KENDARAAN'),
'LAMPU' => $this->input->post('lampu[]'),
//'EMISI' => $this->input->post('EMISI'),
//'REM' => $this->input->post('REM')
);
$lulus = $_POST["lulus"];
//$statement = "INSERT INTO pengujian VALUES($lulus)"
$this->db->insert($this->db_tabel, $pengujian);
if($this->db->affected_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
I got no trouble in the formfield. The trouble is the radio button "lampu"
The best thing to do, I think, is to check where it's going wrong. I usually do this, in this case, by checking if the value is being passed back to the controller and model. This way you understand better what's going on inside your code. Do something like this:
In the model:
public function tambah()
{
// Check to see if we get a value. If not, do the same in the controller
var_dump($this->input->post('lampu'));
exit;
$pengujian = array(
'NO_PENGUJIAN' => $this->input->post('NO_PENGUJIAN'),
'ID_KENDARAAN' => $this->input->post('ID_KENDARAAN'),
'NO_KENDARAAN' => $this->input->post('NO_KENDARAAN'),
'LAMPU' => $this->input->post('lampu[]'),
//'EMISI' => $this->input->post('EMISI'),
//'REM' => $this->input->post('REM')
);
$lulus = $_POST["lulus"];
//$statement = "INSERT INTO pengujian VALUES($lulus)"
$this->db->insert($this->db_tabel, $pengujian);
if($this->db->affected_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
I hope this helps a bit....

yii framework: how to make search result empty in search form?

Hello i created a separate search form having input box and button.
in my model i want to search products by category wise...
but problem is that when input box is empty and clicking on search buttons it displays all entries from the database table..
controller code is-
class AddController extends Controller
{
public function actionAddsearch()
{
$model_form = new Add("search");
$attributes = Yii::app()->getRequest()->getPost("Add");
if(!is_null($attributes))
{
$model_form->setAttributes(Yii::app()->getRequest()->getPost("Add"));
}
$this->render("searchResults", array(
"model" => $model_form,
"models" => $model_form->searchAdd(),
));
}
model code--
class Add extends CActiveRecord
{
public function searchAdd()
{
$criteria = new CDbCriteria();
$criteria->compare("addname", $this->category, TRUE, "OR");
$criteria->compare("category", $this->category, TRUE, "OR");
return Add::model()->findAll($criteria);
}
view code- addsearch.php
<div class="search-bar">
<?php
$form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
"action"=>$this->createUrl("add/addsearch"),
'type'=>'search',
)
);
echo $form->textFieldRow($model,'category');
echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
$this->widget('bootstrap.widgets.TbButton',array(
'buttonType'=>'submit',
'type'=>'success',
'size'=>'large',
'label'=>'Search For Products ',
));
$this->endWidget();
?>
</div>
searchResults.php
<?php
echo "<h4>Results for Your Search</h4>";
foreach($models as $model):
$this->beginWidget('bootstrap.widgets.TbDetailView',array(
'type'=>'bordered condensed',
'data' => array(
'Shop Name' =>CHtml::link(CHtml::encode($model->addname),array('add/view','id'=> $model->addid)),
'Category' => $model->category
),
'attributes' => array(array('name' => 'Shop Name', 'label' => 'Name of Shop','value'=>CHtml::link(CHtml::encode($model->addname),
array('add/view','id'=>$model->addid)),'type'=>'raw'),
array('name' => 'Category', 'label' => 'Category of Shop'),
),
)
);
echo "<br><hr><br>";
$this->endWidget();
endforeach;
?>
what is wrong in the code??
I want to display no any product when text box is empty..
thanks in advance
change this
if(!is_null($attributes))
{
$model_form->setAttributes(Yii::app()->getRequest()->getPost("Add"));
}
$this->render("searchResults", array(
"model" => $model_form,
"models" => $model_form->searchAdd(),
));
To
if($attributes)
{
$model_form->setAttributes(Yii::app()->getRequest()->getPost("Add"));
$this->render("searchResults", array(
"model" => $model_form,
"models" => $model_form->searchAdd(),
));
}
1) Is the 'caterory' attribute safe on search scenario ? (in rules)
2) category is an attribute of the table schema ?

cake PHP data not save to database table

Controller created for UserController.php
public function myappointment() {
$this->loadmodel('event');
if ($this->request->is('post')) {
$this->Event->create();
if ($this->Event->save($this->request->data)) {
$this->Session->setFlash(__('Your appointment has been saved.'));
} else {
$this->Session->setFlash(__('Unable to add your appointment.'));
}
}
}
model name for event
event.php
class Event extends UserMgmtAppModel {
}
appointment form code in view
<?php
$this->Form->create('Event');
echo $this->Form->input("title" ,array('label' => false ));
echo $this->Form->input("from", array('label' =>false, 'type' => 'text', 'class' => 'fl tal vat w300p', 'error' => false , 'id' => 'select_date'));
echo $this->Html->div('datepicker_img w100p fl pl460p pa', $this->Html->image('calendar.png'),array('id' => 'datepicker_img')); ?>
<?php echo $this->Html->div('datepicker fl pl460p pa', ' ' ,array('id' => 'datepicker'));
echo 'End time';
echo $this->Form->input("to", array('label' =>false, 'type' => 'text', 'class' => 'fl tal vat w300p', 'error' => false , 'id' => 'select_date1'));
echo $this->Html->div('datepicker_img1 w100p fl pl460p pa', $this->Html->image('calendar.png'),array('id' => 'datepicker_img1')); ?>
<?php echo $this->Html->div('datepicker1 fl pl460p pa', ' ' ,array('id' => 'datepicker1'));
echo $this->Form->end('Create appointment');
Try this in your model.
App::uses('UserMgmtAppModel', 'Event.Model');
class Event extends UserMgmtAppModel {
}
Your controller action
public function myappointment() {
$this->loadmodel('Event');
if ($this->request->is('post')) {
$this->Event->create();
if ($this->Event->save($this->request->data)) {
$this->Session->setFlash(__('Your appointment has been saved.'));
} else {
$this->Session->setFlash(__('Unable to add your appointment.'));
}
}
}

cakephp, save multiple row of the same model

I'm tying to figure out how to save, for example 4 days of schedule in one view, and have each field validation message show if validation fails.
My approach was at first to use $this->SomeModel->saveAll() but couldn't save so I tried another way using foreach and all data is saved (pass validation) but no validation message is shown. if you guys know better way to do this I'm open for any suggestions.
Model
public $validate = array(
'hour_from'=>array(
'some mgs' => array(
'rule' => 'good_hours',
),
),
);
public function good_hours($data) {
//throw new Exception(($data['hour_from'] >= $this->data['Hour']['hour_to']));
if ($data['hour_from'] >= $this->data['Hour']['hour_to']) {
return false;
}
return true;
}
Controller:
if ($this->request->is('post')) {
$all_good = true;
foreach ($this->request->data['Hour'] as $day){
if ($this->Hour->save($day)){
}else {
$all_good = false;
$this->Session->setFlash('hours not saved');
}
}
//if all saves are correct rediredt to index
if ($all_good) {
$this->Session->setFlash(__('Hours saved'));
return $this->redirect(array('action' => 'index'));
}
}
View
foreach ($days as $count => $day):
$form_model ='Hour.'.$count. '.';
?>
<fieldset>
<legend><?php
$day_array = (array) $day;
$day = $day_array['date'];
echo $day;
?></legend>
<?php
echo $this->Form->input($form_model.'type_holiday_id', array(
'label'=> 'Typ urlopu',
'type' => 'select',
'options' => $type_holidays,
'empty' => true
));
echo $this->Form->input($form_model.'hour_from', array('label' => 'od'));
echo $this->Form->input($form_model.'hour_to', array('label' => 'do'));
echo $this->Form->input($form_model.'date', array('type' => 'hidden', 'value' => $day));
echo $this->Form->input($form_model.'subordinate_id', array('type' => 'hidden', 'value' => $user['User']['id']));
echo $this->Form->input($form_model.'supervisor_id', array('type' => 'hidden', 'value' => $current_user['id']));
?>
</fieldset>
Request->data array
Hour(array)
0(array)
type_holiday_id
hour_from 8
hour_to 15
date 2014-01-20
subordinate_id 193
supervisor_id 557
1(array)
type_holiday_id
hour_from 7
hour_to 14
date 2014-01-21
subordinate_id 193
supervisor_id 557
Ok i found solution, and everything works perfectly now in controller i needed to change save to saveAll, function add in Controller should look like this:
if ($this->request->is('post')) {
if ($this->Hour->saveAll($this->request->data['Hour'], Array('validate' => 'first', 'deep' => true))){ <--- most important is that data['Hour']
$this->Session->setFlash(__('Godziny robocze zapisane'));
return $this->redirect(array('action' => 'index'));
} else{
$this->Session->setFlash('Godziny robocze nie zostały zapisane.');
}
}

Categories