Здравствуйте. Уже беспокоила с вопросом по валидации. Так и не разобралась.
Задача: ввести в таблицу бд данные заказчика. 5полей (customer_id, fio, adres, tels, info). Ввод информации происходит, но ПРОБЛЕМА с валидацией:
После обработки формы с пустым значением fio данные в форму не попадаю, но и ошибка не выводится.
Листинг модель, конструктор, вид, файл с ошибками ->
ps. в программировании не сильна. самоучка чайник. проект оч нужен. и не судите строго пожалуйста
модельКод:
<?php defined('SYSPATH') or die('No direct script access.');
{
Class Model_Newcustomer extends Model {
protected $_tableCustomer = 'customer';
public function get_customer($customer_id)
{
$query = DB::select('fio', 'adres', 'tels', 'info')
->from($this->_tableCustomer)
->where('customer_id', '=', $customer_id)
->execute()
->as_array();
if($query)
return $query;
else
return array();
}
//создание нового заказчика
public function create_customer($customer_id, $fio, $adres, $tels, $info)
{
DB::insert($this->_tableCustomer, array('customer_id', 'fio', 'adres', 'tels', 'info'))
->values(array($customer_id, $fio, $adres, $tels, $info))
->execute();
}
}
}
Контроллер:Код:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Newcustomer extends Controller_Template {
public $template = 'basecus'; //загрузка базового вида
public function action_index()
{
if($this->request->is_initial())
Request::initial()->redirect(URL::site('/newcustomer'));
$customer_id = $this->request->param('id');
$content = View::factory('newcustomerview')
->bind('customers', $customers);
if($_POST)
{
$_POST = Arr::map('trim', $_POST);
$post = Validation::factory($_POST);
$post -> rule('fio', 'not_empty');
if($post -> check())
{
Model::factory('Newcustomer')->create_customer($customer_id, $_POST['fio'], $_POST['adres'], $_POST['tels'], $_POST['info']);
$uri = Request::detect_uri('/newcustomer');
Request::initial()->redirect($uri);
}
else
{
$errors = $post -> errors('customer');
}
}
$customers = Model::factory('Newcustomer')->get_customer($customer_id);
$this->template->content = $content;
}
}
Файл с ошибками (\application\messages\):
Код:
<?php
return array(
'fio' => array(
'not_empty' => 'Вы не ввели имя заказчика',
), );