├── Config ├── Backend.php └── Notification.php ├── Controllers └── BaseController.php ├── Helpers ├── array_helper.php ├── calc_helper.php ├── date_helper.php ├── error_helper.php └── string_helper.php ├── LICENSE ├── Libraries └── Notification.php ├── README.md ├── Views ├── home │ └── index.php ├── layouts │ ├── application.php │ ├── backend.php │ └── nolayout.php └── login │ └── index.php └── composer.json /Config/Backend.php: -------------------------------------------------------------------------------- 1 | '#343a40', 9 | 'sidebarLink' => '#c2c7d0', 10 | 'sidebarHover' => 'rgba(255,255,255,.1)', 11 | 'sidebarHoverLink' => '#FFFFFF', 12 | 'primaryColor' => '#007bff', 13 | 'contentWrapper' => '#f4f6f9', 14 | ]; 15 | public $siteName = 'CI - Toolkit'; 16 | public $logoutControllerMethod = '#'; 17 | public $loginName = 'Login'; 18 | public $brandLink = '#'; 19 | public $brand = 'CI - Tookit'; 20 | public $logo = ''; 21 | public $background = ''; 22 | public $copyrightLeft = 'All rights reserved'; 23 | public $copyrightRight = null; 24 | public $breadcrumb = false; 25 | 26 | public $assetsPath = 'backend'; 27 | public $css = [ 28 | '/plugins/fontawesome-free/css/all.min.css', 29 | 'https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.cs', 30 | '/dist/css/adminlte.min.css', 31 | 'https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700', 32 | ]; 33 | public $js = [ 34 | '/plugins/jquery/jquery.min.js', 35 | '/plugins/bootstrap/js/bootstrap.bundle.min.js', 36 | '/dist/js/adminlte.min.js', 37 | ]; 38 | 39 | public $navigation = [ 40 | [ 41 | 'name' => 'Dashboard', 42 | 'link' => '#', 43 | 'icon' => 'fas fa-circle nav-icon', 44 | ], 45 | ]; 46 | } 47 | -------------------------------------------------------------------------------- /Config/Notification.php: -------------------------------------------------------------------------------- 1 | 'html', 9 | 'protocol' => 'smtp', 10 | 'smtp_host' => '', 11 | 'smtp_user' => '', 12 | 'smtp_pass' => '', 13 | 'smtp_port' => '587', 14 | 'smtp_timeout' => '15', 15 | ]; 16 | public $from = [ 17 | 'email' => 'noreply@site.com', 18 | 'name' => 'noreply', 19 | ]; 20 | public $bcc = ''; 21 | } 22 | -------------------------------------------------------------------------------- /Controllers/BaseController.php: -------------------------------------------------------------------------------- 1 | session = \Config\Services::session(); 56 | // Required if you're using flashdata 57 | $this->session = \Config\Services::session(); 58 | 59 | //-------------------------------------------------------------------- 60 | // Check for flashdata 61 | //-------------------------------------------------------------------- 62 | $this->data['confirm'] = $this->session->getFlashdata('confirm'); 63 | $this->data['errors'] = $this->session->getFlashdata('errors'); 64 | 65 | // Arguments to be used in the callback remap 66 | $segments = $request->uri->getSegments(); 67 | $this->arguments = array_slice($segments, (($this->directory === null) ? 2 : 3)); 68 | 69 | $this->data['adminConf'] = new \Toolkit\Config\Backend(); 70 | } 71 | 72 | /** 73 | * -------------------------------------------------------------------- 74 | * REMAP AUTOLOAD VIEWS 75 | * -------------------------------------------------------------------- 76 | */ 77 | 78 | /** 79 | * Remap the CI request, running the method 80 | * and loading the view automagically 81 | * @param string $method The method we're trying to load 82 | */ 83 | public function _remap($method = null) 84 | { 85 | $router = service('router'); 86 | 87 | $controller_full_name = explode('\\', $router->controllerName()); 88 | $view_folder = strtolower(end($controller_full_name)); 89 | 90 | if (method_exists($this, $method)) { 91 | $redirect = call_user_func_array(array($this, $method), $this->arguments); 92 | } else { 93 | throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); 94 | } 95 | 96 | if (isset($redirect) && is_object($redirect) && get_class($redirect) === 'CodeIgniter\HTTP\RedirectResponse') { 97 | return $redirect; 98 | } elseif (isset($redirect) && is_object($redirect) && get_class($redirect) === 'CodeIgniter\HTTP\Response') { 99 | return $redirect; 100 | } else if (is_array($redirect) && isset($redirect['url'])) { 101 | $confirm = (isset($redirect['confirm'])) ? $redirect['confirm'] : null; 102 | if (!empty($confirm)) { 103 | return redirect()->to($redirect['url'])->with('confirm', $redirect['confirm']); 104 | } 105 | $errors = (isset($redirect['errors'])) ? $redirect['errors'] : null; 106 | if (!empty($errors)) { 107 | return redirect()->to($redirect['url'])->with('errors', $redirect['errors']); 108 | } 109 | return redirect()->to($redirect['url']); 110 | } 111 | 112 | if ($this->view !== false) { 113 | $this->data['layout'] = (empty($this->layout)) ? 'layouts/nolayout' : $this->layout; 114 | $this->data['yield'] = (!empty($this->view)) ? $this->view : strtolower($this->directory . $view_folder . '/' . $router->methodName()); 115 | echo view($this->data['yield'], $this->data); 116 | } else { 117 | return $redirect; 118 | } 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /Helpers/array_helper.php: -------------------------------------------------------------------------------- 1 | $value) { 17 | if (is_array($value)) { 18 | $result = array_merge($result, array_flatten($value)); 19 | } else { 20 | $result[$key] = $value; 21 | } 22 | } 23 | return $result; 24 | } 25 | } 26 | 27 | /* 28 | * Return array average 29 | */ 30 | if (!function_exists('avg_array')) { 31 | function avg_array($array) 32 | { 33 | if (!is_array($array)) { 34 | return false; 35 | } 36 | if (empty($array)) { 37 | return 0.0; 38 | } 39 | return round((array_sum($array) / count($array)), 1); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Helpers/calc_helper.php: -------------------------------------------------------------------------------- 1 | = $min_score) { 37 | return 0; 38 | } else { 39 | return (($min_score - $score) * 100) / ($min_score - $max_score); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Helpers/date_helper.php: -------------------------------------------------------------------------------- 1 | format($format) == $date; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Helpers/error_helper.php: -------------------------------------------------------------------------------- 1 | 'a', 37 | '/[ÁÀÂÃÄ]/u' => 'A', 38 | '/[ÍÌÎÏ]/u' => 'I', 39 | '/[íìîï]/u' => 'i', 40 | '/[éèêë]/u' => 'e', 41 | '/[ÉÈÊË]/u' => 'E', 42 | '/[óòôõºö]/u' => 'o', 43 | '/[ÓÒÔÕÖ]/u' => 'O', 44 | '/[úùûü]/u' => 'u', 45 | '/[ÚÙÛÜ]/u' => 'U', 46 | '/ç/' => 'c', 47 | '/Ç/' => 'C', 48 | '/ñ/' => 'n', 49 | '/Ñ/' => 'N', 50 | '/–/' => '-', 51 | '/[’‘‹›‚]/u' => ' ', 52 | '/[“”«»„]/u' => ' ', 53 | '/ /' => ' ', 54 | ); 55 | return preg_replace(array_keys($utf8), array_values($utf8), $original_utf8); 56 | } 57 | 58 | } 59 | 60 | if (!function_exists('decimal_number')) { 61 | /** 62 | * Set any number to a set of decimal number eg. 1 = 1.0 63 | * @param int $number The number to be formated 64 | * @param integer $decimal How many decimals 65 | * @return double 66 | */ 67 | function decimal_number($number = null, $decimal = 1) 68 | { 69 | if (is_null($number)) { 70 | return 0; 71 | } 72 | return number_format($number, $decimal, '.', ' '); 73 | } 74 | } 75 | 76 | if (!function_exists('round_up')) { 77 | /** 78 | * Round up a number 79 | */ 80 | function round_up($number, $precision = 3) 81 | { 82 | $fig = (int) str_pad('1', $precision, '0'); 83 | return (ceil($number * $fig) / $fig); 84 | } 85 | } 86 | 87 | if (!function_exists('round_down')) { 88 | /** 89 | * Round down a number 90 | */ 91 | function round_down($number, $precision = 3) 92 | { 93 | $fig = (int) str_pad('1', $precision, '0'); 94 | return (floor($number * $fig) / $fig); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Marco Monteiro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Libraries/Notification.php: -------------------------------------------------------------------------------- 1 | config = config('Notification'); 13 | } 14 | 15 | /** 16 | * SEND NOTIFICATION 17 | */ 18 | public function send($data = []) 19 | { 20 | $email = \Config\Services::email(); 21 | 22 | $config = $this->config; 23 | 24 | $email->initialize($config->settings); 25 | if (isset($data['from'])) { 26 | $email->setFrom($data['from'], $data['from_name']); 27 | } else { 28 | $email->setFrom($config->from['email'], $config->from['name']); 29 | } 30 | if (isset($data['to'])) { 31 | $data['to'] = $this->validEmail($data['to']); 32 | $email->setTo($data['to']); 33 | } else { 34 | return false; 35 | } 36 | 37 | if (isset($data['cc'])) { 38 | $data['cc'] = $this->validEmail($data['cc']); 39 | $email->setCC($data['cc']); 40 | } 41 | 42 | $bcc = $config->bcc; 43 | 44 | if (isset($data['bcc'])) { 45 | $data['bcc'] = $this->validEmail($data['bcc']); 46 | $bcc .= ',' . $data['bcc']; 47 | } 48 | $email->setBCC($bcc); 49 | 50 | if (!isset($data['subject'])) { 51 | return false; 52 | } else { 53 | $email->setSubject($data['subject']); 54 | } 55 | 56 | if (!isset($data['message'])) { 57 | return false; 58 | } else { 59 | $email->setMessage($data['message']); 60 | } 61 | 62 | if (isset($data['attach'])) { 63 | $email->attach($data['attach']); 64 | } 65 | 66 | if ($email->send()) { 67 | return true; 68 | } else { 69 | echo $email->printDebugger(['headers']); 70 | die(); 71 | } 72 | } 73 | 74 | /* valid emails before send */ 75 | public function validEmail($emails = []) 76 | { 77 | $emails_valid = []; 78 | if (!is_array($emails)) { 79 | $emails = explode(', ', $emails); 80 | } 81 | foreach ($emails as $key => $email) { 82 | if (!!filter_var($email, FILTER_VALIDATE_EMAIL)) { 83 | $emails_valid[$key] = $email; 84 | } 85 | } 86 | return $emails_valid = implode(', ', $emails_valid); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # codeigniter 4 Toolkit 2 | 3 | A set of libraries and helpers for codeigniter 4 4 | 5 | ## Composer Install 6 | 7 | This way you should run the following command in your terminal. 8 | 9 | composer require mpmont/ci-toolkit dev-master 10 | 11 | Or add the following to your composer.json file. 12 | 13 | { 14 | "require": { 15 | "mpmont/ci-toolkit": "dev-master" 16 | } 17 | } 18 | 19 | ## Dependencies 20 | 21 | - elephpant/breadcrumb [Breacrumb Library](https://github.com/sergiodanilojr/breadcrumb) 22 | - almasaeed2010/adminlte [Admin LTE template](https://github.com/ColorlibHQ/AdminLTE) 23 | 24 | ## Suggested dependencies 25 | 26 | ### IonAuth 27 | 28 | As an authentication system I suggest using Ion Auth. To add that to your project just run the following commands on your project. 29 | 30 | $ composer config minimum-stability dev 31 | $ composer config repositories.ionAuth vcs git@github.com:benedmunds/CodeIgniter-Ion-Auth.git 32 | $ composer require benedmunds/CodeIgniter-Ion-Auth:4.x-dev 33 | 34 | Documentation for Ion Auth can be found [Here](https://github.com/benedmunds/CodeIgniter-Ion-Auth/blob/4/USERGUIDE.md). 35 | 36 | ### pwrsrg/codeigniter4-cart-module 37 | 38 | In case you're building a store and need a cart module just add this to your composer.json and you're good to go. 39 | 40 | $ composer require pwrsrg/codeigniter4-cart-module 41 | 42 | Documentation can be found [Here](https://github.com/pwrsrg/codeigniter4-cart-module). 43 | 44 | ## Base Controller 45 | 46 | codeigniter-base-controller is an extended `BaseController` class to use in your CodeIgniter applications. Any controllers that inherit from `BaseController` get intelligent view autoloading and layout support. It's strongly driven by the ideals of convention over configuration, favouring simplicity and consistency over configuration and complexity. 47 | 48 | #### Usage 49 | 50 | If you install the package via composer then controllers should use a different namespace. In that case your controllers that extend to base Controller should extend to \Toolkit\Controllers\BaseController, like so: 51 | 52 | data` will be passed through to the view and the layout. By default, the class will look for the view in _app/views/controller/action.php_. 69 | 70 | In order to prevent the view being automatically rendered, set `$this->view` to `false`. 71 | 72 | $this->view = false; 73 | 74 | Or, to load a different view than the automatically guessed view: 75 | 76 | $this->view = 'some_path/some_view.php'; 77 | 78 | Views will be loaded into a layout. The class will look for an _app/views/layouts/backend.php_ layout file or _app/views/layouts/application.php_ depending if it's the baseController or the adminController. 79 | 80 | In case you want to override this in your controller just set your layout to whatever you want. 81 | 82 | $this->layout = 'layouts/yourlayout.php' 83 | 84 | In order to specify where in your layout you'd like to output the view, the rendered view will be stored in a `$yield` variable: 85 | 86 |
Footer
93 | 94 | If you wish to disable the layout entirely and only display the view - a technique especially useful for AJAX requests - you can set `$this->layout` to `FALSE`. 95 | 96 | $this->layout = FALSE; 97 | 98 | Like with `$this->view`, `$this->layout` can also be used to specify an unconventional layout file: 99 | 100 | $this->layout = 'layouts/mobile.php'; 101 | 102 | Any variables set in `$this->data` will be passed through to both the view and the layout files. 103 | 104 | #### View structure 105 | 106 | Your views should be created to support the built in functionality of layouts that comes with codeigniter 4 107 | 108 | extend($layout); ?> 109 | 110 | section('yield') ?> 111 |loginName; ?>
37 | 38 |