Redirect URL di Page Hadapan Codeigniter

6:28 PTG 0 Comments A+ a-

Pergi ke folder application->config dan edit routes.php, tukar dari welcom kepada -> pages
br> Pergi ke main folder, create new file nama .htaccess dan paste code seperti dibawah.




$config['index_page'] = 'index.php';
tukar kepada
$config['index_page'] = '';

Create Form Menggunakan Form Helper Codeigniter

8:10 PTG 0 Comments A+ a-

Rujukan Create form menggunakan form helper:

https://www.codeigniter.com/user_guide/helpers/form_helper.html 1- Kena enable autoload helper

2- Buka Pages.php didalam controller kemudian buka route untuk ciform dengan memanggil master template yang diisi dengan view ciform:

Create 1 lagi table users menggunakan migration

7:57 PTG 0 Comments A+ a-

1) New file dalam folder migrations create 002_create_users.php


taip migra kemudian ctrl+space load->library('migration'); if($this->migration->current()===FALSE) { show_error($this->migration->error_string()); } else{ echo "Migration executed !!"; } } }

Masukkan id,nama,email dan tarikh:

Penting:

ubah $config['migration_version'] = 1; kepada $config['migration_version'] = 2;

ia untuk jalankan script 1 sehingga 2. jika tukar $config['migration_version'] = 0, maka dia akan rollback (hapuskan semua sekali). Sekarang kita letak 2.

kemudian run:
http://localhost/ci_tuto/index.php/migrate


https://1drv.ms/u/s!AspBq_BZqy8X8jMh7TTFtOTZhp4k?e=lzIcQg

Create Database dalam Codeigniter Menggunakan Migration

6:28 PTG 0 Comments A+ a-

Create ci_tuto dalam phpmyadmin



create folder migrations dan file 001_create_posts.php didalam folder application

taip di file 001_create_posts.php, migra kemudian tekan ctrl+space dalam sublime text, akan keluar


setting di database




Taip migra kemudian ctrl+space dalam 001_create_posts.php

Didalam function up difile 001_create_posts.php, letak:


defined('BASEPATH') OR exit('No direct script access allowed');

class Migration_Create_posts extends CI_Migration {

	public function __construct()
	{
		$this->load->dbforge();
		$this->load->database();
	}

	public function up() {
		$this->dbforge->add_field(
			array(
				'id'=>array(
					'type'=> 'INT',
					'constraint' =>5,
					'unsigned' =>TRUE,
					'auto_increment' =>TRUE
				),

				'title'=>array(
					'type'=> 'VARCHAR',
					'constraint' => 200
				),
				'body'=>array(
					'type'=> 'TEXT',
					'null' =>TRUE
				),
				'created_at'=>array(
					'type'=> 'timestamp',
				),
			)
		);
		$this->dbforge->add_key('id',TRUE);
		$this->dbforge->create_table('posts');
	}

	public function down() {
		$this->dbforge->drop_table('posts');
				
	}

}
Kemudian:

Pergi ke application->config->migration.php
$config['migration_enabled'] = TRUE;

$config['migration_type'] = 'timestamp'; tukar kepada:
$config['migration_type'] = 'sequential';

$config['migration_version'] = 0; tukar kepada:
$config['migration_version'] = 1;



Pergi ke application->config->autoload.php
$autoload['libraries'] = array();  tukar kepada;
$autoload['libraries'] = array('database');


FULL Coding untuk 001_create_post.php:
full coding untuk migrate.php
taip controller kemudian tekan ctrl+space untuk auto script snippet. Tukar nama class kepada Migrate dan letak code seperti dibawah:


defined('BASEPATH') OR exit('No direct script access allowed');

class Migrate extends CI_Controller {

	public function __construct()
	{
		parent::__construct();


	}



	public function index()
	{
		$this->load->library('migration');

		if($this->migration->current()===FALSE)
		{
			show_error($this->migration->error_string());

		}
		else{
			echo "Migration executed !!";
		}
		
	}

}






Run di browser:
Di database:

Sublime Key Bindings Reindent

12:02 PG 0 Comments A+ a-

Preferences -> key bindings, paste;


[
{
"keys": [
"alt+shift+f"
],
"command": "reindent",
"args": {
"single_line": false
}
}
]


Tutup.

Pergi ke code, tekan alt+shift+f untuk reindent.

Setting Bootstrap Dalam Codeigniter

11:23 PTG 0 Comments A+ a-

Create folder assets jika tiada:
H:\xampp\htdocs\ci_tuto\assets

download bootstrap compiled, extract & copy css & js ke dlm folder assets.

Application->config->Autoload.php
$autoload['helper'] = array('url');

Application->config->config.php
$config['base_url'] = 'http://localhost/ci_tuto';

di dalam file view, letak command di dalam selepas
sebelum :



Refresh di browser, view anda sepatutnya sudah menerima bootsrap.

Sample dan documentation boleh lihat di;

https://getbootstrap.com/docs/4.3/getting-started/introduction/

Sublime Setting Untuk Codeigniter

11:15 PTG 0 Comments A+ a-

Sublime-> Preference->Package Control

Package Control
HTML5
AdvancedNewFile
Bootstrap 4 Autocomplete
Bootstrap 4 Snippets
Codeigniter Snippets
Emmet