└── application ├── libraries └── MY_Controller.php └── helpers └── MY_form.php /application/libraries/MY_Controller.php: -------------------------------------------------------------------------------- 1 | validation = new Validation($_POST); 12 | $this->links = array('Главная' => url::base()); 13 | } 14 | 15 | public function get_validation() 16 | { 17 | return $this->validation; 18 | } 19 | 20 | public function get_breadcrumbs() 21 | { 22 | $breadcrumbs = array(); 23 | 24 | $get_breadcrumbs = html::breadcrumb($this->links); 25 | while (current($get_breadcrumbs)) 26 | { 27 | // Check if we have reached the last crumb 28 | if (key($get_breadcrumbs) < (count($get_breadcrumbs) - 1)) 29 | { 30 | // If we haven't, add a breadcrumb separator 31 | $breadcrumbs .= current($get_breadcrumbs) . ' / '; 32 | } 33 | else 34 | { 35 | // If we have, remove the anchor from the breadcrumb and make it bold 36 | $breadcrumbs .= strip_tags("" . current($get_breadcrumbs) . "", ""); 37 | } 38 | next($get_breadcrumbs); 39 | } 40 | return $breadcrumbs; 41 | } 42 | } -------------------------------------------------------------------------------- /application/helpers/MY_form.php: -------------------------------------------------------------------------------- 1 | $val) 23 | { 24 | $str[$key] = self::prep($val); 25 | } 26 | 27 | return $str; 28 | } 29 | 30 | if ($str === '') 31 | { 32 | return ''; 33 | } 34 | 35 | // we've already prepped a field with this name 36 | // @todo need to figure out a way to namespace this so 37 | // that we know the *exact* field and not just one with 38 | // the same name 39 | if (isset($prepped_fields[$field_name])) 40 | { 41 | return $str; 42 | } 43 | 44 | $str = html::specialchars($str); 45 | 46 | if ($field_name != '') 47 | { 48 | $prepped_fields[$field_name] = $str; 49 | } 50 | return $str; 51 | } 52 | /** 53 | * 54 | * @param string $field 55 | * @param string $default 56 | * @return string 57 | */ 58 | public function set_value($field, $default = '') 59 | { 60 | // Getting validation object 61 | $validation = Kohana::instance()->get_validation(); 62 | if (! ($validation instanceof Validation)) 63 | { 64 | if (!isset($_POST[$field])) 65 | { 66 | return $default; 67 | } 68 | return form::prep($_POST[$field], $field); 69 | } 70 | $post = $validation->as_array(); 71 | 72 | // Will fill only if form has been submitted 73 | if ($validation->submitted() && isset($post[$field])) 74 | { 75 | return form::prep($post[$field], $field); 76 | } else 77 | { 78 | return $default; 79 | } 80 | } 81 | /** 82 | * 83 | * @param string $field 84 | * @param string $value 85 | * @param boolean $default 86 | * @return string 87 | */ 88 | public function set_radio($field = '', $value = '', $default = FALSE) 89 | { 90 | // Getting validation object 91 | $validation = Kohana::instance()->get_validation(); 92 | if (! ($validation instanceof Validation)) 93 | { 94 | if (!isset($_POST[$field])) 95 | { 96 | if (count($_POST) === 0 AND $default == TRUE) 97 | { 98 | return ' checked="checked"'; 99 | } 100 | return ''; 101 | } 102 | $field = $_POST[$field]; 103 | 104 | if (is_array($field)) 105 | { 106 | if (!in_array($value, $field)) 107 | { 108 | return ''; 109 | } 110 | } 111 | else 112 | { 113 | if (($field == '' OR $value == '') OR ($field != $value)) 114 | { 115 | return ''; 116 | } 117 | } 118 | 119 | return ' checked="checked"'; 120 | } 121 | // Validation object exists 122 | $post = $validation->as_array(); 123 | 124 | $submitted = $validation->submitted(); 125 | if (!$submitted || !isset($post[$field])) 126 | { 127 | if ($default === TRUE AND !$submitted) 128 | { 129 | return ' checked="checked"'; 130 | } 131 | return ''; 132 | } 133 | 134 | $field = $post[$field]; 135 | if (is_array($field)) 136 | { 137 | if (!in_array($value, $field)) 138 | { 139 | return ''; 140 | } 141 | } 142 | else 143 | { 144 | if (($field == '' OR $value == '') OR ($field != $value)) 145 | { 146 | return ''; 147 | } 148 | } 149 | 150 | return ' checked="checked"'; 151 | } 152 | public function set_checkbox($field = '', $value = '', $default = FALSE) 153 | { 154 | return self::set_radio($field,$value,$default); 155 | } 156 | } --------------------------------------------------------------------------------