-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMY_Controller.php
More file actions
90 lines (84 loc) · 2.36 KB
/
MY_Controller.php
File metadata and controls
90 lines (84 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* MY_Controller Class
*
* @package MY_Controller
* @subpackage MY_Controller
* @category CodeIgniter Common
* @author Evtimiy Mihaylov <evo@vaupe.com>
* @link http://neatlogos.com
*/
class MY_Controller extends CI_Controller {
/**
* __construct function
*
*/
public function __construct() {
parent::__construct();
}
/**
* Loads the header, central(one or more) and footer partials
* @param array $views views that showld be loaded
* @param array $data params passed to the view
* @return
*
**/
public function loadView($views,$data){
$this->load->view('common/header',$data);
if(is_array($views)) {
foreach($views as $view) {
$this->load->view($view,$data);
}
} else {
$this->load->view($views,$data);
}
$this->load->view('common/footer',$data);
}
/**
* Custom validation rules for separate array field validation and separate error messages
* @param array $field the names of the field
* @param array $properties
* @param array $field_human_name human name of the field used on error
* @param $rules
* @param $field_error
* @return array
*
**/
public function generateValidation($field,$properties,$field_human_name,$rules,$field_error=null) {
$this->load->library('form_validation');
$fields = $this->input->post($field);
$items_array = array();
if($fields) {
$i=0;
foreach($fields as $field_param=>$field_items) {
foreach($field_items as $field_item=>$item_value) {
$items_array[$field_item][$field_param] = $item_value;
}
$i++;
}
$i=0;
foreach($items_array as $item) {
foreach($properties as $property) {
$this->form_validation->set_rules($field.'['.$property['property'].']['. $i .']',$property['human_name'], $property['rules']);
}
$i++;
}
}else{
if(!empty($field_error)){
$this->form_validation->set_rules($field, $field_human_name, 'callback_required_items['.$field_error.']');
}
}
return $items_array;
}
/**
* Custom required form items function when there are no fields added
* @param array $str
* @param array $field_error is the custom message
* @return bool
*
**/
public function required_items($str,$field_error) {
$this->form_validation->set_message('required_items', $field_error);
return false;
}
}