Sabtu, 01 Desember 2018

Membuat Framework PHP Menggunakan Codeigniter

Nama : Hafidz Firman Asqalany
NRP   : 05111740000195
Kelas  : PWEB-C

Kali ini saya akan menampilkan hasil Membuat Framework PHP Menggunakan Codeigniter dari tutorial petani kode 1-6 (https://petanikode.com/codeigniter-pemula/). langsung saja berikut hasilnya :

1. Tampilan awal dari source code Codeigniter


 2. Tampilan awal Versi saya



 3. Tampilan contact us

4. Tampilan about us

5 Tampilan awal web yang telah di edit


6. Tampilan ketika menambahkan product


 7. tampilan ketika klik menu list siswa(melihat hasil dari product yang telah di input). Disini juga         kita bisa menghapus atau mengedit product yang telah di input.



8. database gudanghiphop


Berikut merupakan hasil Source Code saya :

1.  welcome_message.php

 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 ?><!DOCTYPE html>  
 <html lang="en">  
 <head>  
      <meta charset="utf-8">  
      <title>Welcome to CodeIgniter</title>  
      <style type="text/css">  
      ::selection { background-color: #E13300; color: white; }  
      ::-moz-selection { background-color: #E13300; color: white; }  
      body {  
           background-color: #fff;  
           margin: 40px;  
           font: 13px/20px normal Helvetica, Arial, sans-serif;  
           color: #4F5155;  
      }  
      a {  
           color: #003399;  
           background-color: transparent;  
           font-weight: normal;  
      }  
      h1 {  
           color: #444;  
           background-color: transparent;  
           border-bottom: 1px solid #D0D0D0;  
           font-size: 19px;  
           font-weight: normal;  
           margin: 0 0 14px 0;  
           padding: 14px 15px 10px 15px;  
      }  
      code {  
           font-family: Consolas, Monaco, Courier New, Courier, monospace;  
           font-size: 12px;  
           background-color: #f9f9f9;  
           border: 1px solid #D0D0D0;  
           color: #002166;  
           display: block;  
           margin: 14px 0 14px 0;  
           padding: 12px 10px 12px 10px;  
      }  
      #body {  
           margin: 0 15px 0 15px;  
      }  
      p.footer {  
           text-align: right;  
           font-size: 11px;  
           border-top: 1px solid #D0D0D0;  
           line-height: 32px;  
           padding: 0 10px 0 10px;  
           margin: 20px 0 0 0;  
      }  
      #container {  
           margin: 10px;  
           border: 1px solid #D0D0D0;  
           box-shadow: 0 0 8px #D0D0D0;  
      }  
      </style>  
 </head>  
 <body>  
 <div id="container">  
      <h1>Welcome to gudanghiphop</h1>  
      <div id="body">  
           <p>The page you are looking at is being generated dynamically by CodeIgniter.</p>  
           <p>If you would like to edit this page you'll find it located at:</p>  
           <code>application/views/welcome_message.php</code>  
           <p>The corresponding controller for this page is found at:</p>  
           <code>application/controllers/Welcome.php</code>  
           <p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>  
      </div>  
      <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>  
 </div>  
 </body>  
 </html>  

2. about.php

 <h1>About Us</h1>  
 <p>gudanghiphop adalah oldshop fashion hip-hop masa kini dimana semua barangnya 100% original dan terpercaya.</p>  

3. contact.php

 <h1>Contact Us</h1>  
 <p>email : hafidzasqalany28@gmail.com</p>  
 <p>Line : 30059928</p>  
 <p>WA  : 085243131373</p>  
 <p>IG  : 30059928</p>  

4.config.php

 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 /*  
 |--------------------------------------------------------------------------  
 | Base Site URL  
 |--------------------------------------------------------------------------  
 |  
 | URL to your CodeIgniter root. Typically this will be your base URL,  
 | WITH a trailing slash:  
 |  
 |     http://example.com/  
 |  
 | WARNING: You MUST set this value!  
 |  
 | If it is not set, then CodeIgniter will try guess the protocol and path  
 | your installation, but due to security concerns the hostname will be set  
 | to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.  
 | The auto-detection mechanism exists only for convenience during  
 | development and MUST NOT be used in production!  
 |  
 | If you need to allow multiple domains, remember that this file is still  
 | a PHP script and you can easily do that on your own.  
 |  
 */  
 $config['base_url'] = 'http://localhost/gudanghiphop';  
 /*  
 |--------------------------------------------------------------------------  
 | Index File  
 |--------------------------------------------------------------------------  
 |  
 | Typically this will be your index.php file, unless you've renamed it to  
 | something else. If you are using mod_rewrite to remove the page set this  
 | variable so that it is blank.  
 |  
 */  
 $config['index_page'] = 'index.php';  
 /*  
 |--------------------------------------------------------------------------  
 | URI PROTOCOL  
 |--------------------------------------------------------------------------  
 |  
 | This item determines which server global should be used to retrieve the  
 | URI string. The default setting of 'REQUEST_URI' works for most servers.  
 | If your links do not seem to work, try one of the other delicious flavors:  
 |  
 | 'REQUEST_URI'  Uses $_SERVER['REQUEST_URI']  
 | 'QUERY_STRING'  Uses $_SERVER['QUERY_STRING']  
 | 'PATH_INFO'   Uses $_SERVER['PATH_INFO']  
 |  
 | WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!  
 */  
 $config['uri_protocol']     = 'REQUEST_URI';  
 /*  
 |--------------------------------------------------------------------------  
 | URL suffix  
 |--------------------------------------------------------------------------  
 |  
 | This option allows you to add a suffix to all URLs generated by CodeIgniter.  
 | For more information please see the user guide:  
 |  
 | https://codeigniter.com/user_guide/general/urls.html  
 */  
 $config['url_suffix'] = '';  
 /*  
 |--------------------------------------------------------------------------  
 | Default Language  
 |--------------------------------------------------------------------------  
 |  
 | This determines which set of language files should be used. Make sure  
 | there is an available translation if you intend to use something other  
 | than english.  
 |  
 */  
 $config['language']     = 'english';  
 /*  
 |--------------------------------------------------------------------------  
 | Default Character Set  
 |--------------------------------------------------------------------------  
 |  
 | This determines which character set is used by default in various methods  
 | that require a character set to be provided.  
 |  
 | See http://php.net/htmlspecialchars for a list of supported charsets.  
 |  
 */  
 $config['charset'] = 'UTF-8';  
 /*  
 |--------------------------------------------------------------------------  
 | Enable/Disable System Hooks  
 |--------------------------------------------------------------------------  
 |  
 | If you would like to use the 'hooks' feature you must enable it by  
 | setting this variable to TRUE (boolean). See the user guide for details.  
 |  
 */  
 $config['enable_hooks'] = FALSE;  
 /*  
 |--------------------------------------------------------------------------  
 | Class Extension Prefix  
 |--------------------------------------------------------------------------  
 |  
 | This item allows you to set the filename/classname prefix when extending  
 | native libraries. For more information please see the user guide:  
 |  
 | https://codeigniter.com/user_guide/general/core_classes.html  
 | https://codeigniter.com/user_guide/general/creating_libraries.html  
 |  
 */  
 $config['subclass_prefix'] = 'MY_';  
 /*  
 |--------------------------------------------------------------------------  
 | Composer auto-loading  
 |--------------------------------------------------------------------------  
 |  
 | Enabling this setting will tell CodeIgniter to look for a Composer  
 | package auto-loader script in application/vendor/autoload.php.  
 |  
 |     $config['composer_autoload'] = TRUE;  
 |  
 | Or if you have your vendor/ directory located somewhere else, you  
 | can opt to set a specific path as well:  
 |  
 |     $config['composer_autoload'] = '/path/to/vendor/autoload.php';  
 |  
 | For more information about Composer, please visit http://getcomposer.org/  
 |  
 | Note: This will NOT disable or override the CodeIgniter-specific  
 |     autoloading (application/config/autoload.php)  
 */  
 $config['composer_autoload'] = FALSE;  
 /*  
 |--------------------------------------------------------------------------  
 | Allowed URL Characters  
 |--------------------------------------------------------------------------  
 |  
 | This lets you specify which characters are permitted within your URLs.  
 | When someone tries to submit a URL with disallowed characters they will  
 | get a warning message.  
 |  
 | As a security measure you are STRONGLY encouraged to restrict URLs to  
 | as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-  
 |  
 | Leave blank to allow all characters -- but only if you are insane.  
 |  
 | The configured value is actually a regular expression character group  
 | and it will be executed as: ! preg_match('/^[<permitted_uri_chars>]+$/i  
 |  
 | DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!  
 |  
 */  
 $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';  
 /*  
 |--------------------------------------------------------------------------  
 | Enable Query Strings  
 |--------------------------------------------------------------------------  
 |  
 | By default CodeIgniter uses search-engine friendly segment based URLs:  
 | example.com/who/what/where/  
 |  
 | You can optionally enable standard query string based URLs:  
 | example.com?who=me&what=something&where=here  
 |  
 | Options are: TRUE or FALSE (boolean)  
 |  
 | The other items let you set the query string 'words' that will  
 | invoke your controllers and its functions:  
 | example.com/index.php?c=controller&m=function  
 |  
 | Please note that some of the helpers won't work as expected when  
 | this feature is enabled, since CodeIgniter is designed primarily to  
 | use segment based URLs.  
 |  
 */  
 $config['enable_query_strings'] = FALSE;  
 $config['controller_trigger'] = 'c';  
 $config['function_trigger'] = 'm';  
 $config['directory_trigger'] = 'd';  
 /*  
 |--------------------------------------------------------------------------  
 | Allow $_GET array  
 |--------------------------------------------------------------------------  
 |  
 | By default CodeIgniter enables access to the $_GET array. If for some  
 | reason you would like to disable it, set 'allow_get_array' to FALSE.  
 |  
 | WARNING: This feature is DEPRECATED and currently available only  
 |     for backwards compatibility purposes!  
 |  
 */  
 $config['allow_get_array'] = TRUE;  
 /*  
 |--------------------------------------------------------------------------  
 | Error Logging Threshold  
 |--------------------------------------------------------------------------  
 |  
 | You can enable error logging by setting a threshold over zero. The  
 | threshold determines what gets logged. Threshold options are:  
 |  
 |     0 = Disables logging, Error logging TURNED OFF  
 |     1 = Error Messages (including PHP errors)  
 |     2 = Debug Messages  
 |     3 = Informational Messages  
 |     4 = All Messages  
 |  
 | You can also pass an array with threshold levels to show individual error types  
 |  
 |      array(2) = Debug Messages, without Error Messages  
 |  
 | For a live site you'll usually only enable Errors (1) to be logged otherwise  
 | your log files will fill up very fast.  
 |  
 */  
 $config['log_threshold'] = 0;  
 /*  
 |--------------------------------------------------------------------------  
 | Error Logging Directory Path  
 |--------------------------------------------------------------------------  
 |  
 | Leave this BLANK unless you would like to set something other than the default  
 | application/logs/ directory. Use a full server path with trailing slash.  
 |  
 */  
 $config['log_path'] = '';  
 /*  
 |--------------------------------------------------------------------------  
 | Log File Extension  
 |--------------------------------------------------------------------------  
 |  
 | The default filename extension for log files. The default 'php' allows for  
 | protecting the log files via basic scripting, when they are to be stored  
 | under a publicly accessible directory.  
 |  
 | Note: Leaving it blank will default to 'php'.  
 |  
 */  
 $config['log_file_extension'] = '';  
 /*  
 |--------------------------------------------------------------------------  
 | Log File Permissions  
 |--------------------------------------------------------------------------  
 |  
 | The file system permissions to be applied on newly created log files.  
 |  
 | IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal  
 |      integer notation (i.e. 0700, 0644, etc.)  
 */  
 $config['log_file_permissions'] = 0644;  
 /*  
 |--------------------------------------------------------------------------  
 | Date Format for Logs  
 |--------------------------------------------------------------------------  
 |  
 | Each item that is logged has an associated date. You can use PHP date  
 | codes to set your own date formatting  
 |  
 */  
 $config['log_date_format'] = 'Y-m-d H:i:s';  
 /*  
 |--------------------------------------------------------------------------  
 | Error Views Directory Path  
 |--------------------------------------------------------------------------  
 |  
 | Leave this BLANK unless you would like to set something other than the default  
 | application/views/errors/ directory. Use a full server path with trailing slash.  
 |  
 */  
 $config['error_views_path'] = '';  
 /*  
 |--------------------------------------------------------------------------  
 | Cache Directory Path  
 |--------------------------------------------------------------------------  
 |  
 | Leave this BLANK unless you would like to set something other than the default  
 | application/cache/ directory. Use a full server path with trailing slash.  
 |  
 */  
 $config['cache_path'] = '';  
 /*  
 |--------------------------------------------------------------------------  
 | Cache Include Query String  
 |--------------------------------------------------------------------------  
 |  
 | Whether to take the URL query string into consideration when generating  
 | output cache files. Valid options are:  
 |  
 |     FALSE   = Disabled  
 |     TRUE    = Enabled, take all query parameters into account.  
 |            Please be aware that this may result in numerous cache  
 |            files generated for the same page over and over again.  
 |     array('q') = Enabled, but only take into account the specified list  
 |            of query parameters.  
 |  
 */  
 $config['cache_query_string'] = FALSE;  
 /*  
 |--------------------------------------------------------------------------  
 | Encryption Key  
 |--------------------------------------------------------------------------  
 |  
 | If you use the Encryption class, you must set an encryption key.  
 | See the user guide for more info.  
 |  
 | https://codeigniter.com/user_guide/libraries/encryption.html  
 |  
 */  
 $config['encryption_key'] = '';  
 /*  
 |--------------------------------------------------------------------------  
 | Session Variables  
 |--------------------------------------------------------------------------  
 |  
 | 'sess_driver'  
 |  
 |     The storage driver to use: files, database, redis, memcached  
 |  
 | 'sess_cookie_name'  
 |  
 |     The session cookie name, must contain only [0-9a-z_-] characters  
 |  
 | 'sess_expiration'  
 |  
 |     The number of SECONDS you want the session to last.  
 |     Setting to 0 (zero) means expire when the browser is closed.  
 |  
 | 'sess_save_path'  
 |  
 |     The location to save sessions to, driver dependent.  
 |  
 |     For the 'files' driver, it's a path to a writable directory.  
 |     WARNING: Only absolute paths are supported!  
 |  
 |     For the 'database' driver, it's a table name.  
 |     Please read up the manual for the format with other session drivers.  
 |  
 |     IMPORTANT: You are REQUIRED to set a valid save path!  
 |  
 | 'sess_match_ip'  
 |  
 |     Whether to match the user's IP address when reading the session data.  
 |  
 |     WARNING: If you're using the database driver, don't forget to update  
 |          your session table's PRIMARY KEY when changing this setting.  
 |  
 | 'sess_time_to_update'  
 |  
 |     How many seconds between CI regenerating the session ID.  
 |  
 | 'sess_regenerate_destroy'  
 |  
 |     Whether to destroy session data associated with the old session ID  
 |     when auto-regenerating the session ID. When set to FALSE, the data  
 |     will be later deleted by the garbage collector.  
 |  
 | Other session cookie settings are shared with the rest of the application,  
 | except for 'cookie_prefix' and 'cookie_httponly', which are ignored here.  
 |  
 */  
 $config['sess_driver'] = 'files';  
 $config['sess_cookie_name'] = 'ci_session';  
 $config['sess_expiration'] = 7200;  
 $config['sess_save_path'] = NULL;  
 $config['sess_match_ip'] = FALSE;  
 $config['sess_time_to_update'] = 300;  
 $config['sess_regenerate_destroy'] = FALSE;  
 /*  
 |--------------------------------------------------------------------------  
 | Cookie Related Variables  
 |--------------------------------------------------------------------------  
 |  
 | 'cookie_prefix'  = Set a cookie name prefix if you need to avoid collisions  
 | 'cookie_domain'  = Set to .your-domain.com for site-wide cookies  
 | 'cookie_path'   = Typically will be a forward slash  
 | 'cookie_secure'  = Cookie will only be set if a secure HTTPS connection exists.  
 | 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)  
 |  
 | Note: These settings (with the exception of 'cookie_prefix' and  
 |    'cookie_httponly') will also affect sessions.  
 |  
 */  
 $config['cookie_prefix']     = '';  
 $config['cookie_domain']     = '';  
 $config['cookie_path']          = '/';  
 $config['cookie_secure']     = FALSE;  
 $config['cookie_httponly']      = FALSE;  
 /*  
 |--------------------------------------------------------------------------  
 | Standardize newlines  
 |--------------------------------------------------------------------------  
 |  
 | Determines whether to standardize newline characters in input data,  
 | meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value.  
 |  
 | WARNING: This feature is DEPRECATED and currently available only  
 |     for backwards compatibility purposes!  
 |  
 */  
 $config['standardize_newlines'] = FALSE;  
 /*  
 |--------------------------------------------------------------------------  
 | Global XSS Filtering  
 |--------------------------------------------------------------------------  
 |  
 | Determines whether the XSS filter is always active when GET, POST or  
 | COOKIE data is encountered  
 |  
 | WARNING: This feature is DEPRECATED and currently available only  
 |     for backwards compatibility purposes!  
 |  
 */  
 $config['global_xss_filtering'] = FALSE;  
 /*  
 |--------------------------------------------------------------------------  
 | Cross Site Request Forgery  
 |--------------------------------------------------------------------------  
 | Enables a CSRF cookie token to be set. When set to TRUE, token will be  
 | checked on a submitted form. If you are accepting user data, it is strongly  
 | recommended CSRF protection be enabled.  
 |  
 | 'csrf_token_name' = The token name  
 | 'csrf_cookie_name' = The cookie name  
 | 'csrf_expire' = The number in seconds the token should expire.  
 | 'csrf_regenerate' = Regenerate token on every submission  
 | 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks  
 */  
 $config['csrf_protection'] = FALSE;  
 $config['csrf_token_name'] = 'csrf_test_name';  
 $config['csrf_cookie_name'] = 'csrf_cookie_name';  
 $config['csrf_expire'] = 7200;  
 $config['csrf_regenerate'] = TRUE;  
 $config['csrf_exclude_uris'] = array();  
 /*  
 |--------------------------------------------------------------------------  
 | Output Compression  
 |--------------------------------------------------------------------------  
 |  
 | Enables Gzip output compression for faster page loads. When enabled,  
 | the output class will test whether your server supports Gzip.  
 | Even if it does, however, not all browsers support compression  
 | so enable only if you are reasonably sure your visitors can handle it.  
 |  
 | Only used if zlib.output_compression is turned off in your php.ini.  
 | Please do not use it together with httpd-level output compression.  
 |  
 | VERY IMPORTANT: If you are getting a blank page when compression is enabled it  
 | means you are prematurely outputting something to your browser. It could  
 | even be a line of whitespace at the end of one of your scripts. For  
 | compression to work, nothing can be sent before the output buffer is called  
 | by the output class. Do not 'echo' any values with compression enabled.  
 |  
 */  
 $config['compress_output'] = FALSE;  
 /*  
 |--------------------------------------------------------------------------  
 | Master Time Reference  
 |--------------------------------------------------------------------------  
 |  
 | Options are 'local' or any PHP supported timezone. This preference tells  
 | the system whether to use your server's local time as the master 'now'  
 | reference, or convert it to the configured one timezone. See the 'date  
 | helper' page of the user guide for information regarding date handling.  
 |  
 */  
 $config['time_reference'] = 'local';  
 /*  
 |--------------------------------------------------------------------------  
 | Rewrite PHP Short Tags  
 |--------------------------------------------------------------------------  
 |  
 | If your PHP installation does not have short tag support enabled CI  
 | can rewrite the tags on-the-fly, enabling you to utilize that syntax  
 | in your view files. Options are TRUE or FALSE (boolean)  
 |  
 | Note: You need to have eval() enabled for this to work.  
 |  
 */  
 $config['rewrite_short_tags'] = FALSE;  
 /*  
 |--------------------------------------------------------------------------  
 | Reverse Proxy IPs  
 |--------------------------------------------------------------------------  
 |  
 | If your server is behind a reverse proxy, you must whitelist the proxy  
 | IP addresses from which CodeIgniter should trust headers such as  
 | HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP in order to properly identify  
 | the visitor's IP address.  
 |  
 | You can use both an array or a comma-separated list of proxy addresses,  
 | as well as specifying whole subnets. Here are a few examples:  
 |  
 | Comma-separated:     '10.0.1.200,192.168.5.0/24'  
 | Array:          array('10.0.1.200', '192.168.5.0/24')  
 */  
 $config['proxy_ips'] = '';  

5. constants.php

 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 /*  
 |--------------------------------------------------------------------------  
 | Display Debug backtrace  
 |--------------------------------------------------------------------------  
 |  
 | If set to TRUE, a backtrace will be displayed along with php errors. If  
 | error_reporting is disabled, the backtrace will not display, regardless  
 | of this setting  
 |  
 */  
 defined('SHOW_DEBUG_BACKTRACE') OR define('SHOW_DEBUG_BACKTRACE', TRUE);  
 /*  
 |--------------------------------------------------------------------------  
 | File and Directory Modes  
 |--------------------------------------------------------------------------  
 |  
 | These prefs are used when checking and setting modes when working  
 | with the file system. The defaults are fine on servers with proper  
 | security, but you may wish (or even need) to change the values in  
 | certain environments (Apache running a separate process for each  
 | user, PHP under CGI with Apache suEXEC, etc.). Octal values should  
 | always be used to set the mode correctly.  
 |  
 */  
 defined('FILE_READ_MODE') OR define('FILE_READ_MODE', 0644);  
 defined('FILE_WRITE_MODE') OR define('FILE_WRITE_MODE', 0666);  
 defined('DIR_READ_MODE')  OR define('DIR_READ_MODE', 0755);  
 defined('DIR_WRITE_MODE') OR define('DIR_WRITE_MODE', 0755);  
 /*  
 |--------------------------------------------------------------------------  
 | File Stream Modes  
 |--------------------------------------------------------------------------  
 |  
 | These modes are used when working with fopen()/popen()  
 |  
 */  
 defined('FOPEN_READ')              OR define('FOPEN_READ', 'rb');  
 defined('FOPEN_READ_WRITE')           OR define('FOPEN_READ_WRITE', 'r+b');  
 defined('FOPEN_WRITE_CREATE_DESTRUCTIVE')    OR define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care  
 defined('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE') OR define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care  
 defined('FOPEN_WRITE_CREATE')          OR define('FOPEN_WRITE_CREATE', 'ab');  
 defined('FOPEN_READ_WRITE_CREATE')       OR define('FOPEN_READ_WRITE_CREATE', 'a+b');  
 defined('FOPEN_WRITE_CREATE_STRICT')      OR define('FOPEN_WRITE_CREATE_STRICT', 'xb');  
 defined('FOPEN_READ_WRITE_CREATE_STRICT')    OR define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');  
 /*  
 |--------------------------------------------------------------------------  
 | Exit Status Codes  
 |--------------------------------------------------------------------------  
 |  
 | Used to indicate the conditions under which the script is exit()ing.  
 | While there is no universal standard for error codes, there are some  
 | broad conventions. Three such conventions are mentioned below, for  
 | those who wish to make use of them. The CodeIgniter defaults were  
 | chosen for the least overlap with these conventions, while still  
 | leaving room for others to be defined in future versions and user  
 | applications.  
 |  
 | The three main conventions used for determining exit status codes  
 | are as follows:  
 |  
 |  Standard C/C++ Library (stdlibc):  
 |    http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html  
 |    (This link also contains other GNU-specific conventions)  
 |  BSD sysexits.h:  
 |    http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits  
 |  Bash scripting:  
 |    http://tldp.org/LDP/abs/html/exitcodes.html  
 |  
 */  
 defined('EXIT_SUCCESS')    OR define('EXIT_SUCCESS', 0); // no errors  
 defined('EXIT_ERROR')     OR define('EXIT_ERROR', 1); // generic error  
 defined('EXIT_CONFIG')     OR define('EXIT_CONFIG', 3); // configuration error  
 defined('EXIT_UNKNOWN_FILE')  OR define('EXIT_UNKNOWN_FILE', 4); // file not found  
 defined('EXIT_UNKNOWN_CLASS') OR define('EXIT_UNKNOWN_CLASS', 5); // unknown class  
 defined('EXIT_UNKNOWN_METHOD') OR define('EXIT_UNKNOWN_METHOD', 6); // unknown class member  
 defined('EXIT_USER_INPUT')   OR define('EXIT_USER_INPUT', 7); // invalid user input  
 defined('EXIT_DATABASE')    OR define('EXIT_DATABASE', 8); // database error  
 defined('EXIT__AUTO_MIN')   OR define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code  
 defined('EXIT__AUTO_MAX')   OR define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code  
 /*  
 |--------------------------------------------------------------------------  
 | Constants for Site  
 |--------------------------------------------------------------------------  
 |  
 */  
 define('SITE_NAME', 'gudanghiphop');  

6. overview.php

 <!DOCTYPE html>  
 <html lang="en">  
 <head>  
      <?php $this->load->view("admin/_partials/head.php") ?>  
 </head>  
 <body id="page-top">  
 <?php $this->load->view("admin/_partials/navbar.php") ?>  
 <div id="wrapper">  
      <?php $this->load->view("admin/_partials/sidebar.php") ?>  
      <div id="content-wrapper">  
           <div class="container-fluid">  
     <!--   
     karena ini halaman overview (home), kita matikan partial breadcrumb.  
     Jika anda ingin mengampilkan breadcrumb di halaman overview,  
     silahkan hilangkan komentar (//) di tag PHP di bawah.  
     -->  
           <?php //$this->load->view("admin/_partials/breadcrumb.php") ?>  
           <!-- Icon Cards-->  
           <div class="row">  
                <div class="col-xl-3 col-sm-6 mb-3">  
                <div class="card text-white bg-primary o-hidden h-100">  
                     <div class="card-body">  
                     <div class="card-body-icon">  
                          <i class="fas fa-fw fa-comments"></i>  
                     </div>  
                     <div class="mr-5">26 New Messages!</div>  
                     </div>  
                     <a class="card-footer text-white clearfix small z-1" href="#">  
                     <span class="float-left">View Details</span>  
                     <span class="float-right">  
                          <i class="fas fa-angle-right"></i>  
                     </span>  
                     </a>  
                </div>  
                </div>  
                <div class="col-xl-3 col-sm-6 mb-3">  
                <div class="card text-white bg-warning o-hidden h-100">  
                     <div class="card-body">  
                     <div class="card-body-icon">  
                          <i class="fas fa-fw fa-list"></i>  
                     </div>  
                     <div class="mr-5">11 New Tasks!</div>  
                     </div>  
                     <a class="card-footer text-white clearfix small z-1" href="#">  
                     <span class="float-left">View Details</span>  
                     <span class="float-right">  
                          <i class="fas fa-angle-right"></i>  
                     </span>  
                     </a>  
                </div>  
                </div>  
                <div class="col-xl-3 col-sm-6 mb-3">  
                <div class="card text-white bg-success o-hidden h-100">  
                     <div class="card-body">  
                     <div class="card-body-icon">  
                          <i class="fas fa-fw fa-shopping-cart"></i>  
                     </div>  
                     <div class="mr-5">123 New Orders!</div>  
                     </div>  
                     <a class="card-footer text-white clearfix small z-1" href="#">  
                     <span class="float-left">View Details</span>  
                     <span class="float-right">  
                          <i class="fas fa-angle-right"></i>  
                     </span>  
                     </a>  
                </div>  
                </div>  
                <div class="col-xl-3 col-sm-6 mb-3">  
                <div class="card text-white bg-danger o-hidden h-100">  
                     <div class="card-body">  
                     <div class="card-body-icon">  
                          <i class="fas fa-fw fa-life-ring"></i>  
                     </div>  
                     <div class="mr-5">13 New Tickets!</div>  
                     </div>  
                     <a class="card-footer text-white clearfix small z-1" href="#">  
                     <span class="float-left">View Details</span>  
                     <span class="float-right">  
                          <i class="fas fa-angle-right"></i>  
                     </span>  
                     </a>  
                </div>  
                </div>  
           </div>  
           <!-- Area Chart Example-->  
           <div class="card mb-3">  
                <div class="card-header">  
                <i class="fas fa-chart-area"></i>  
                Visitor Stats</div>  
                <div class="card-body">  
                <canvas id="myAreaChart" width="100%" height="30"></canvas>  
                </div>  
                <div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>  
           </div>  
           </div>  
           <!-- /.container-fluid -->  
           <!-- Sticky Footer -->  
           <?php $this->load->view("admin/_partials/footer.php") ?>  
      </div>  
      <!-- /.content-wrapper -->  
 </div>  
 <!-- /#wrapper -->  
 <?php $this->load->view("admin/_partials/scrolltop.php") ?>  
 <?php $this->load->view("admin/_partials/modal.php") ?>  
 <?php $this->load->view("admin/_partials/js.php") ?>  
 </body>  
 </html>  

7. Overview.php

 <?php  
 class Overview extends CI_Controller {  
   public function __construct()  
   {  
           parent::__construct();  
      }  
      public function index()  
      {  
     // load view admin/overview.php  
     $this->load->view("admin/overview");  
      }  
 }  

8. routes.php

 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 /*  
 | -------------------------------------------------------------------------  
 | URI ROUTING  
 | -------------------------------------------------------------------------  
 | This file lets you re-map URI requests to specific controller functions.  
 |  
 | Typically there is a one-to-one relationship between a URL string  
 | and its corresponding controller class/method. The segments in a  
 | URL normally follow this pattern:  
 |  
 |     example.com/class/method/id/  
 |  
 | In some instances, however, you may want to remap this relationship  
 | so that a different class/function is called than the one  
 | corresponding to the URL.  
 |  
 | Please see the user guide for complete details:  
 |  
 |     https://codeigniter.com/user_guide/general/routing.html  
 |  
 | -------------------------------------------------------------------------  
 | RESERVED ROUTES  
 | -------------------------------------------------------------------------  
 |  
 | There are three reserved routes:  
 |  
 |     $route['default_controller'] = 'welcome';  
 |  
 | This route indicates which controller class should be loaded if the  
 | URI contains no data. In the above example, the "welcome" class  
 | would be loaded.  
 |  
 |     $route['404_override'] = 'errors/page_missing';  
 |  
 | This route will tell the Router which controller/method to use if those  
 | provided in the URL cannot be matched to a valid route.  
 |  
 |     $route['translate_uri_dashes'] = FALSE;  
 |  
 | This is not exactly a route, but allows you to automatically route  
 | controller and method names that contain dashes. '-' isn't a valid  
 | class or method name character, so it requires translation.  
 | When you set this option to TRUE, it will replace ALL dashes in the  
 | controller and method URI segments.  
 |  
 | Examples:     my-controller/index     -> my_controller/index  
 |          my-controller/my-method     -> my_controller/my_method  
 */  
 $route['default_controller'] = 'welcome';  
 $route['404_override'] = '';  
 $route['translate_uri_dashes'] = FALSE;  
 $route['about'] = 'welcome/about';  
 $route['contact'] = 'welcome/contact';  
 $route['admin'] = 'admin/overview';  

9. breadcrumb.php

 <!-- Breadcrumbs-->  
 <ol class="breadcrumb">  
 <?php foreach ($this->uri->segments as $segment): ?>  
      <?php   
           $url = substr($this->uri->uri_string, 0, strpos($this->uri->uri_string, $segment)) . $segment;  
           $is_active = $url == $this->uri->uri_string;  
      ?>  
      <li class="breadcrumb-item <?php echo $is_active ? 'active': '' ?>">  
           <?php if($is_active): ?>  
                <?php echo ucfirst($segment) ?>  
           <?php else: ?>  
                <a href="<?php echo site_url($url) ?>"><?php echo ucfirst($segment) ?></a>  
           <?php endif; ?>  
      </li>  
 <?php endforeach; ?>  
 </ol>  

10. footer.php

 <!-- Sticky Footer -->  
 <footer class="sticky-footer">  
  <div class="container my-auto">  
   <div class="copyright text-center my-auto">  
    <span>Copyright © <?php echo SITE_NAME ." ". Date('Y') ?></span>  
   </div>  
  </div>  
 </footer>  

11. head.php

 <head>  
 <meta charset="utf-8">  
 <meta http-equiv="X-UA-Compatible" content="IE=edge">  
 <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">  
 <title><?php echo SITE_NAME .": ". ucfirst($this->uri->segment(1)) ." - ". ucfirst($this->uri->segment(2)) ?></title>  
 <!-- Bootstrap core CSS-->  
 <link href="<?php echo base_url('assets/bootstrap/css/bootstrap.min.css') ?>" rel="stylesheet">  
 <!-- Custom fonts for this template-->  
 <link href="<?php echo base_url('assets/fontawesome-free/css/all.min.css') ?>" rel="stylesheet" type="text/css">  
 <!-- Page level plugin CSS-->  
 <link href="<?php echo base_url('assets/datatables/dataTables.bootstrap4.css') ?>" rel="stylesheet">  
 <!-- Custom styles for this template-->  
 <link href="<?php echo base_url('css/sb-admin.css') ?>" rel="stylesheet">  
 </head>  

12. js.php

 <!-- Bootstrap core JavaScript-->  
 <script src="<?php echo base_url('assets/jquery/jquery.min.js') ?>"></script>  
 <script src="<?php echo base_url('assets/bootstrap/js/bootstrap.bundle.min.js') ?>"></script>  
 <!-- Core plugin JavaScript-->  
 <script src="<?php echo base_url('assets/jquery-easing/jquery.easing.min.js') ?>"></script>  
 <!-- Page level plugin JavaScript-->  
 <script src="<?php echo base_url('assets/chart.js/Chart.min.js') ?>"></script>  
 <script src="<?php echo base_url('assets/datatables/jquery.dataTables.js') ?>"></script>  
 <script src="<?php echo base_url('assets/datatables/dataTables.bootstrap4.js') ?>"></script>  
 <!-- Custom scripts for all pages-->  
 <script src="<?php echo base_url('js/sb-admin.min.js') ?>"></script>  
 <!-- Demo scripts for this page-->  
 <script src="<?php echo base_url('js/demo/datatables-demo.js') ?>"></script>  
 <script src="<?php echo base_url('js/demo/chart-area-demo.js') ?>"></script>  

13. modal.php

 <!-- Logout Modal-->  
 <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">  
  <div class="modal-dialog" role="document">  
   <div class="modal-content">  
    <div class="modal-header">  
     <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>  
     <button class="close" type="button" data-dismiss="modal" aria-label="Close">  
      <span aria-hidden="true">×</span>  
     </button>  
    </div>  
    <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>  
    <div class="modal-footer">  
     <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>  
     <a class="btn btn-primary" href="login.html">Logout</a>  
    </div>  
   </div>  
  </div>  
 </div>  
 <!-- Logout Delete Confirmation-->  
 <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">  
  <div class="modal-dialog" role="document">  
   <div class="modal-content">  
    <div class="modal-header">  
     <h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>  
     <button class="close" type="button" data-dismiss="modal" aria-label="Close">  
      <span aria-hidden="true">×</span>  
     </button>  
    </div>  
    <div class="modal-body">Data yang dihapus tidak akan bisa dikembalikan.</div>  
    <div class="modal-footer">  
     <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>  
     <a id="btn-delete" class="btn btn-danger" href="#">Delete</a>  
    </div>  
   </div>  
  </div>  
 </div>  

14. navbar.php

 <nav class="navbar navbar-expand navbar-dark bg-success static-top">  
   <a class="navbar-brand mr-1" href="<?php echo site_url('admin') ?>"><?php echo SITE_NAME ?></a>  
   <button class="btn btn-link btn-sm text-white order-1 order-sm-0" id="sidebarToggle" href="#">  
     <i class="fas fa-bars"></i>  
   </button>  
   <!-- Navbar Search -->  
   <form class="d-none d-md-inline-block form-inline ml-auto mr-0 mr-md-3 my-2 my-md-0">  
     <div class="input-group">  
       <input type="text" class="form-control" placeholder="Search for..." aria-label="Search" aria-describedby="basic-addon2">  
       <div class="input-group-append">  
         <button class="btn btn-light" type="button">  
           <i class="fas fa-search"></i>  
         </button>  
       </div>  
     </div>  
   </form>  
   <!-- Navbar -->  
   <ul class="navbar-nav ml-auto ml-md-0">  
     <li class="nav-item dropdown no-arrow mx-1">  
       <a class="nav-link dropdown-toggle" href="#" id="alertsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"  
         aria-expanded="false">  
         <i class="fas fa-bell fa-fw"></i>  
         <span class="badge badge-danger">9+</span>  
       </a>  
       <div class="dropdown-menu dropdown-menu-right" aria-labelledby="alertsDropdown">  
         <a class="dropdown-item" href="#">Action</a>  
         <a class="dropdown-item" href="#">Another action</a>  
         <div class="dropdown-divider"></div>  
         <a class="dropdown-item" href="#">Something else here</a>  
       </div>  
     </li>  
     <li class="nav-item dropdown no-arrow mx-1">  
       <a class="nav-link dropdown-toggle" href="#" id="messagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"  
         aria-expanded="false">  
         <i class="fas fa-envelope fa-fw"></i>  
         <span class="badge badge-danger">7</span>  
       </a>  
       <div class="dropdown-menu dropdown-menu-right" aria-labelledby="messagesDropdown">  
         <a class="dropdown-item" href="#">Action</a>  
         <a class="dropdown-item" href="#">Another action</a>  
         <div class="dropdown-divider"></div>  
         <a class="dropdown-item" href="#">Something else here</a>  
       </div>  
     </li>  
     <li class="nav-item dropdown no-arrow">  
       <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"  
         aria-expanded="false">  
         <i class="fas fa-user-circle fa-fw"></i> Admin  
       </a>  
       <div class="dropdown-menu dropdown-menu-right" aria-labelledby="userDropdown">  
         <a class="dropdown-item" href="#">Settings</a>  
         <a class="dropdown-item" href="#">Activity Log</a>  
         <div class="dropdown-divider"></div>  
         <a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">Logout</a>  
       </div>  
     </li>  
   </ul>  
 </nav>  

15. scrolltop.php

 <!-- Scroll to Top Button-->  
 <a class="scroll-to-top rounded" href="#page-top">  
      <i class="fas fa-angle-up"></i>  
 </a>  

16. sidebar.php

 <!-- Sidebar -->  
 <ul class="sidebar navbar-nav">  
   <li class="nav-item <?php echo $this->uri->segment(2) == 'products' ? 'active': '' ?>">  
     <a class="nav-link" href="<?php echo site_url('admin') ?>">  
       <i class="fas fa-fw fa-tachometer-alt"></i>  
       <span>Overview</span>  
     </a>  
   </li>  
   <li class="nav-item dropdown <?php echo $this->uri->segment(2) == 'products' ? 'active': '' ?>">  
     <a class="nav-link dropdown-toggle" href="#" id="pagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"  
       aria-expanded="false">  
       <i class="fas fa-fw fa-boxes"></i>  
       <span>Products</span>  
     </a>  
     <div class="dropdown-menu" aria-labelledby="pagesDropdown">  
       <a class="dropdown-item" href="<?php echo site_url('admin/products/add') ?>">New Product</a>  
       <a class="dropdown-item" href="<?php echo site_url('admin/products') ?>">List Product</a>  
     </div>  
   </li>  
   <li class="nav-item">  
     <a class="nav-link" href="#">  
       <i class="fas fa-fw fa-users"></i>  
       <span>Users</span></a>  
   </li>  
   <li class="nav-item">  
     <a class="nav-link" href="#">  
       <i class="fas fa-fw fa-cog"></i>  
       <span>Settings</span></a>  
   </li>  
 </ul>  

17. database.php

 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 /*  
 | -------------------------------------------------------------------  
 | DATABASE CONNECTIVITY SETTINGS  
 | -------------------------------------------------------------------  
 | This file will contain the settings needed to access your database.  
 |  
 | For complete instructions please consult the 'Database Connection'  
 | page of the User Guide.  
 |  
 | -------------------------------------------------------------------  
 | EXPLANATION OF VARIABLES  
 | -------------------------------------------------------------------  
 |  
 |     ['dsn']   The full DSN string describe a connection to the database.  
 |     ['hostname'] The hostname of your database server.  
 |     ['username'] The username used to connect to the database  
 |     ['password'] The password used to connect to the database  
 |     ['database'] The name of the database you want to connect to  
 |     ['dbdriver'] The database driver. e.g.: mysqli.  
 |               Currently supported:  
 |                     cubrid, ibase, mssql, mysql, mysqli, oci8,  
 |                     odbc, pdo, postgre, sqlite, sqlite3, sqlsrv  
 |     ['dbprefix'] You can add an optional prefix, which will be added  
 |                     to the table name when using the Query Builder class  
 |     ['pconnect'] TRUE/FALSE - Whether to use a persistent connection  
 |     ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.  
 |     ['cache_on'] TRUE/FALSE - Enables/disables query caching  
 |     ['cachedir'] The path to the folder where cache files should be stored  
 |     ['char_set'] The character set used in communicating with the database  
 |     ['dbcollat'] The character collation used in communicating with the database  
 |                     NOTE: For MySQL and MySQLi databases, this setting is only used  
 |                      as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7  
 |                     (and in table creation queries made with DB Forge).  
 |                      There is an incompatibility in PHP with mysql_real_escape_string() which  
 |                      can make your site vulnerable to SQL injection if you are using a  
 |                      multi-byte character set and are running versions lower than these.  
 |                      Sites using Latin-1 or UTF-8 database character set and collation are unaffected.  
 |     ['swap_pre'] A default table prefix that should be swapped with the dbprefix  
 |     ['encrypt'] Whether or not to use an encrypted connection.  
 |  
 |               'mysql' (deprecated), 'sqlsrv' and 'pdo/sqlsrv' drivers accept TRUE/FALSE  
 |               'mysqli' and 'pdo/mysql' drivers accept an array with the following options:  
 |  
 |                    'ssl_key'  - Path to the private key file  
 |                    'ssl_cert'  - Path to the public key certificate file  
 |                    'ssl_ca'   - Path to the certificate authority file  
 |                    'ssl_capath' - Path to a directory containing trusted CA certificates in PEM format  
 |                    'ssl_cipher' - List of *allowed* ciphers to be used for the encryption, separated by colons (':')  
 |                    'ssl_verify' - TRUE/FALSE; Whether verify the server certificate or not ('mysqli' only)  
 |  
 |     ['compress'] Whether or not to use client compression (MySQL only)  
 |     ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections  
 |                                   - good for ensuring strict SQL while developing  
 |     ['ssl_options']     Used to set various SSL options that can be used when making SSL connections.  
 |     ['failover'] array - A array with 0 or more data for connections if the main should fail.  
 |     ['save_queries'] TRUE/FALSE - Whether to "save" all executed queries.  
 |                     NOTE: Disabling this will also effectively disable both  
 |                     $this->db->last_query() and profiling of DB queries.  
 |                     When you run a query, with this setting set to TRUE (default),  
 |                     CodeIgniter will store the SQL statement for debugging purposes.  
 |                     However, this may cause high memory usage, especially if you run  
 |                     a lot of SQL queries ... disable this to avoid that problem.  
 |  
 | The $active_group variable lets you choose which connection group to  
 | make active. By default there is only one group (the 'default' group).  
 |  
 | The $query_builder variables lets you determine whether or not to load  
 | the query builder class.  
 */  
 $active_group = 'default';  
 $query_builder = TRUE;  
 $db['default'] = array(  
      'dsn'     => '',  
      'hostname' => 'localhost',  
      'username' => 'root',  
      'password' => '',  
      'database' => 'gudanghiphop',  
      'dbdriver' => 'mysqli',  
      'dbprefix' => '',  
      'pconnect' => FALSE,  
      'db_debug' => (ENVIRONMENT !== 'production'),  
      'cache_on' => FALSE,  
      'cachedir' => '',  
      'char_set' => 'utf8',  
      'dbcollat' => 'utf8_general_ci',  
      'swap_pre' => '',  
      'encrypt' => FALSE,  
      'compress' => FALSE,  
      'stricton' => FALSE,  
      'failover' => array(),  
      'save_queries' => TRUE  
 );  

18. Product_model.php

 <?php defined('BASEPATH') OR exit('No direct script access allowed');  
 class Product_model extends CI_Model  
 {  
   private $_table = "products";  
   public $product_id;  
   public $name;  
   public $price;  
   public $image = "default.jpg";  
   public $description;  
   public function rules()  
   {  
     return [  
       ['field' => 'name',  
       'label' => 'Name',  
       'rules' => 'required'],  
       ['field' => 'price',  
       'label' => 'Price',  
       'rules' => 'numeric'],  
       ['field' => 'description',  
       'label' => 'Description',  
       'rules' => 'required']  
     ];  
   }  
   public function getAll()  
   {  
     return $this->db->get($this->_table)->result();  
   }  
   public function getById($id)  
   {  
     return $this->db->get_where($this->_table, ["product_id" => $id])->row();  
   }  
   public function save()  
   {  
     $post = $this->input->post();  
     $this->product_id = uniqid();  
     $this->name = $post["name"];  
     $this->price = $post["price"];  
     $this->image = $this->_uploadImage();  
     $this->description = $post["description"];  
     $this->db->insert($this->_table, $this);  
   }  
   public function update()  
   {  
     $post = $this->input->post();  
     $this->product_id = $post["id"];  
     $this->name = $post["name"];  
     $this->price = $post["price"];  
     if (!empty($_FILES["image"]["name"])) {  
       $this->image = $this->_uploadImage();  
     } else {  
       $this->image = $post["old_image"];  
     }  
     $this->description = $post["description"];  
     $this->db->update($this->_table, $this, array('product_id' => $post['id']));  
   }  
   public function delete($id)  
   {  
     $this->_deleteImage($id);  
     return $this->db->delete($this->_table, array("product_id" => $id));  
   }  
   private function _uploadImage()  
 {  
   $config['upload_path']     = './upload/product/';  
   $config['allowed_types']    = 'gif|jpg|png';  
   $config['file_name']      = $this->product_id;  
   $config['overwrite']               = true;  
   $config['max_size']       = 1024; // 1MB  
   // $config['max_width']      = 1024;  
   // $config['max_height']      = 768;  
   $this->load->library('upload', $config);  
   if ($this->upload->do_upload('image')) {  
     return $this->upload->data("file_name");  
   }  
   return "default.jpg";  
 }  
 private function _deleteImage($id)  
 {  
   $product = $this->getById($id);  
   if ($product->image != "default.jpg") {  
        $filename = explode(".", $product->image)[0];  
           return array_map('unlink', glob(FCPATH."upload/product/$filename.*"));  
   }  
 }  
 }  

19. Product.php

 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Products extends CI_Controller  
 {  
   public function __construct()  
   {  
     parent::__construct();  
     $this->load->model("product_model");  
     $this->load->library('form_validation');  
   }  
   public function index()  
   {  
     $data["products"] = $this->product_model->getAll();  
     $this->load->view("admin/product/list", $data);  
   }  
   public function add()  
   {  
     $product = $this->product_model;  
     $validation = $this->form_validation;  
     $validation->set_rules($product->rules());  
     if ($validation->run()) {  
       $product->save();  
       $this->session->set_flashdata('success', 'Berhasil disimpan');  
     }  
     $this->load->view("admin/product/new_form");  
   }  
   public function edit($id = null)  
   {  
     if (!isset($id)) redirect('admin/products');  
     $product = $this->product_model;  
     $validation = $this->form_validation;  
     $validation->set_rules($product->rules());  
     if ($validation->run()) {  
       $product->update();  
       $this->session->set_flashdata('success', 'Berhasil disimpan');  
     }  
     $data["product"] = $product->getById($id);  
     if (!$data["product"]) show_404();  
     $this->load->view("admin/product/edit_form", $data);  
   }  
   public function delete($id=null)  
   {  
     if (!isset($id)) show_404();  
     if ($this->product_model->delete($id)) {  
       redirect(site_url('admin/products'));  
     }  
   }  
 }  

20 edit-form.php

 <!DOCTYPE html>  
 <html lang="en">  
 <head>  
      <?php $this->load->view("admin/_partials/head.php") ?>  
 </head>  
 <body id="page-top">  
      <?php $this->load->view("admin/_partials/navbar.php") ?>  
      <div id="wrapper">  
           <?php $this->load->view("admin/_partials/sidebar.php") ?>  
           <div id="content-wrapper">  
                <div class="container-fluid">  
                     <?php $this->load->view("admin/_partials/breadcrumb.php") ?>  
                     <?php if ($this->session->flashdata('success')): ?>  
                     <div class="alert alert-success" role="alert">  
                          <?php echo $this->session->flashdata('success'); ?>  
                     </div>  
                     <?php endif; ?>  
                     <!-- Card -->  
                     <div class="card mb-3">  
                          <div class="card-header">  
                               <a href="<?php echo site_url('admin/products/') ?>"><i class="fas fa-arrow-left"></i>  
                                    Back</a>  
                          </div>  
                          <div class="card-body">  
                               <form action="<?php base_url('admin/product/edit') ?>" method="post" enctype="multipart/form-data">  
                                    <input type="hidden" name="id" value="<?php echo $product->product_id?>" />  
                                    <div class="form-group">  
                                         <label for="name">Name*</label>  
                                         <input class="form-control <?php echo form_error('name') ? 'is-invalid':'' ?>"  
                                          type="text" name="name" placeholder="Product name" value="<?php echo $product->name ?>" />  
                                         <div class="invalid-feedback">  
                                              <?php echo form_error('name') ?>  
                                         </div>  
                                    </div>  
                                    <div class="form-group">  
                                         <label for="price">Price</label>  
                                         <input class="form-control <?php echo form_error('price') ? 'is-invalid':'' ?>"  
                                          type="number" name="price" min="0" placeholder="Product price" value="<?php echo $product->price ?>" />  
                                         <div class="invalid-feedback">  
                                              <?php echo form_error('price') ?>  
                                         </div>  
                                    </div>  
                                    <div class="form-group">  
                                         <label for="name">Photo</label>  
                                         <input class="form-control-file <?php echo form_error('image') ? 'is-invalid':'' ?>"  
                                          type="file" name="image" />  
                                         <input type="hidden" name="old_image" value="<?php echo $product->image ?>" />  
                                         <div class="invalid-feedback">  
                                              <?php echo form_error('image') ?>  
                                         </div>  
                                    </div>  
                                    <div class="form-group">  
                                         <label for="name">Description*</label>  
                                         <textarea class="form-control <?php echo form_error('description') ? 'is-invalid':'' ?>"  
                                          name="description" placeholder="Product description..."><?php echo $product->description ?></textarea>  
                                         <div class="invalid-feedback">  
                                              <?php echo form_error('description') ?>  
                                         </div>  
                                    </div>  
                                    <input class="btn btn-success" type="submit" name="btn" value="Save" />  
                               </form>  
                          </div>  
                          <div class="card-footer small text-muted">  
                               * required fields  
                          </div>  
                     </div>  
                     <!-- /.container-fluid -->  
                     <!-- Sticky Footer -->  
                     <?php $this->load->view("admin/_partials/footer.php") ?>  
                </div>  
                <!-- /.content-wrapper -->  
           </div>  
           <!-- /#wrapper -->  
           <?php $this->load->view("admin/_partials/scrolltop.php") ?>  
           <?php $this->load->view("admin/_partials/js.php") ?>  
 </body>  
 </html>  

21. list.php

 <!DOCTYPE html>  
 <html lang="en">  
 <head>  
      <?php $this->load->view("admin/_partials/head.php") ?>  
 </head>  
 <body id="page-top">  
      <?php $this->load->view("admin/_partials/navbar.php") ?>  
      <div id="wrapper">  
           <?php $this->load->view("admin/_partials/sidebar.php") ?>  
           <div id="content-wrapper">  
                <div class="container-fluid">  
                     <?php $this->load->view("admin/_partials/breadcrumb.php") ?>  
                     <!-- DataTables -->  
                     <div class="card mb-3">  
                          <div class="card-header">  
                               <a href="<?php echo site_url('admin/products/add') ?>"><i class="fas fa-plus"></i> Add New</a>  
                          </div>  
                          <div class="card-body">  
                               <div class="table-responsive">  
                                    <table class="table table-hover" id="dataTable" width="100%" cellspacing="0">  
                                         <thead>  
                                              <tr>  
                                                   <th>Name</th>  
                                                   <th>Price</th>  
                                                   <th>Photo</th>  
                                                   <th>Description</th>  
                                                   <th>Action</th>  
                                              </tr>  
                                         </thead>  
                                         <tbody>  
                                              <?php foreach ($products as $product): ?>  
                                              <tr>  
                                                   <td width="150">  
                                                        <?php echo $product->name ?>  
                                                   </td>  
                                                   <td>  
                                                        <?php echo $product->price ?>  
                                                   </td>  
                                                   <td>  
                                                        <img src="<?php echo base_url('upload/product/'.$product->image) ?>" width="64" />  
                                                   </td>  
                                                   <td class="small">  
                                                        <?php echo substr($product->description, 0, 120) ?>...</td>  
                                                   <td width="250">  
                                                        <a href="<?php echo site_url('admin/products/edit/'.$product->product_id) ?>"  
                                                         class="btn btn-small"><i class="fas fa-edit"></i> Edit</a>  
                                                        <a onclick="deleteConfirm('<?php echo site_url('admin/products/delete/'.$product->product_id) ?>')"  
                                                         href="#!" class="btn btn-small text-danger"><i class="fas fa-trash"></i> Hapus</a>  
                                                   </td>  
                                              </tr>  
                                              <?php endforeach; ?>  
                                         </tbody>  
                                    </table>  
                               </div>  
                          </div>  
                     </div>  
                </div>  
                <!-- /.container-fluid -->  
                <!-- Sticky Footer -->  
                <?php $this->load->view("admin/_partials/footer.php") ?>  
           </div>  
           <!-- /.content-wrapper -->  
      </div>  
      <!-- /#wrapper -->  
      <?php $this->load->view("admin/_partials/scrolltop.php") ?>  
      <?php $this->load->view("admin/_partials/modal.php") ?>  
      <?php $this->load->view("admin/_partials/js.php") ?>  
 <script>  
 function deleteConfirm(url){  
      $('#btn-delete').attr('href', url);  
      $('#deleteModal').modal();  
 }  
 </script>  
 </body>  
 </html>  

22. new_form.php

 <!DOCTYPE html>  
 <html lang="en">  
 <head>  
      <?php $this->load->view("admin/_partials/head.php") ?>  
 </head>  
 <body id="page-top">  
      <?php $this->load->view("admin/_partials/navbar.php") ?>  
      <div id="wrapper">  
           <?php $this->load->view("admin/_partials/sidebar.php") ?>  
           <div id="content-wrapper">  
                <div class="container-fluid">  
                     <?php $this->load->view("admin/_partials/breadcrumb.php") ?>  
                     <?php if ($this->session->flashdata('success')): ?>  
                     <div class="alert alert-success" role="alert">  
                          <?php echo $this->session->flashdata('success'); ?>  
                     </div>  
                     <?php endif; ?>  
                     <div class="card mb-3">  
                          <div class="card-header">  
                               <a href="<?php echo site_url('admin/products/') ?>"><i class="fas fa-arrow-left"></i> Back</a>  
                          </div>  
                          <div class="card-body">  
                               <form action="<?php base_url('admin/product/add') ?>" method="post" enctype="multipart/form-data" >  
                                    <div class="form-group">  
                                         <label for="name">Name*</label>  
                                         <input class="form-control <?php echo form_error('name') ? 'is-invalid':'' ?>"  
                                          type="text" name="name" placeholder="Product name" />  
                                         <div class="invalid-feedback">  
                                              <?php echo form_error('name') ?>  
                                         </div>  
                                    </div>  
                                    <div class="form-group">  
                                         <label for="price">Price*</label>  
                                         <input class="form-control <?php echo form_error('price') ? 'is-invalid':'' ?>"  
                                          type="number" name="price" min="0" placeholder="Product price" />  
                                         <div class="invalid-feedback">  
                                              <?php echo form_error('price') ?>  
                                         </div>  
                                    </div>  
                                    <div class="form-group">  
                                         <label for="name">Photo</label>  
                                         <input class="form-control-file <?php echo form_error('price') ? 'is-invalid':'' ?>"  
                                          type="file" name="image" />  
                                         <div class="invalid-feedback">  
                                              <?php echo form_error('image') ?>  
                                         </div>  
                                    </div>  
                                    <div class="form-group">  
                                         <label for="name">Description*</label>  
                                         <textarea class="form-control <?php echo form_error('description') ? 'is-invalid':'' ?>"  
                                          name="description" placeholder="Product description..."></textarea>  
                                         <div class="invalid-feedback">  
                                              <?php echo form_error('description') ?>  
                                         </div>  
                                    </div>  
                                    <input class="btn btn-success" type="submit" name="btn" value="Save" />  
                               </form>  
                          </div>  
                          <div class="card-footer small text-muted">  
                               * required fields  
                          </div>  
                     </div>  
                     <!-- /.container-fluid -->  
                     <!-- Sticky Footer -->  
                     <?php $this->load->view("admin/_partials/footer.php") ?>  
                </div>  
                <!-- /.content-wrapper -->  
           </div>  
           <!-- /#wrapper -->  
           <?php $this->load->view("admin/_partials/scrolltop.php") ?>  
           <?php $this->load->view("admin/_partials/js.php") ?>  
 </body>  
 </html>  

Tidak ada komentar:

Posting Komentar