Tutorial on Creating a Search Pagination Session in Codeigniter

In this tutorial we will learn how to create a search system for data tables that have pagination with the help of sessions in Codeigniter, of course you will ask what sessions in pagination are for, it will be easier to understand after you compare ordinary pagination with pagination sessions, enough discussion now we will start .

codeigniter search pagination session
Photo Illustration via cnblogs.com

First create a database with the name of the exercise, table and input some data, the following is the sql:

— Database: practice

— Structure of the pagination . table

CREATE TABLE IF NOT EXISTS pagination (
nim bigint(20) NOT NULL,
name varchar(50) NOT NULL,
major varchar(30) NOT NULL,
address text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=111999030 DEFAULT CHARSET=latin1;

— Data dumping for pagination . table

INSERT INTO pagination (nim, name, department, address) VALUES
(111999014, ‘Rahmayanti’, ‘PGSD’, ‘Kp. Mekarsari RT.15/03 No.33’),
(111999021, ‘Muhammad Yusuf Hamdani’, ‘Informatics Engineering’, ‘Jln. Cipaku Haji RT.02/07 No.15’),
(111999023, ‘Putri Andini’, ‘Information System’, ‘Kp. Mekarsari RT/RW 22/55 No.34’),
(111999025, ‘Anggra Triawan Skom’, ‘S2 Infirmatics Engineering’, ‘Kp. Buntar RT.02 / RW.09 Kel. Ciawi Kec. Bogor Selatan’),
(111999027, ‘Alisya Rahmadani’, ‘PGBK’, ‘Pakuan Hill Housing, Monte Carlo, Ciawi Bogor Selatan’),
(111999029, ‘Muhammad Afnan’, ‘Law’, ‘Pakuan Hill Housing, Monte Carlo, Ciawi Bogor Selatan’);

— Indexes for dumped tables

— Indexes for table pagination

ALTER TABLE pagination
ADD PRIMARY KEY(nim);

— AUTO_INCREMENT for dumped tables

— AUTO_INCREMENT for table pagination

ALTER TABLE pagination
MODIFY nim bigint(20) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=111999030;
SQL Database
The database structure in phpmyadmin will look like below

ps1

The filled table will look like below

ps2

In this tutorial we need a .htaccess file (this file has no name, only has an .htaccess extension) to remove index.php in the url, please create a new file then save the file in the pagination_session_ci / project folder.

RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
.htaccess
To make it easier for friends, you can download .htaccess

Open the autoload.php file, which is located in application/config/autoload.php, then find and modify the helpers and libraries section like this:

$autoload[‘libraries’] = array(‘database’, ‘session’, ‘pagination’);
$autoload[‘helper’] = array(‘url’, ‘file’, ‘form’);
application/config/autoload.php
Open the config.php file, which is located in application/config/config.php, then find and modify it like this:

$config[‘base_url’] = ‘http://localhost/pagination_session_ci/’;

$config[‘encryption_key’] = ‘TWD’;
application/config/config.php
Open the database.php file, which is located in application/config/database.php, then find and modify it like this:

$active_group = ‘default’;
$active_record = TRUE;

application/config/database.php
Then open the welcome.php file, controllers/welcome.php and edit it as below:

How to Upload Videos With PHP

Video has now become one of the elements on a website that can make people interested and feel at home on the website for a long time, let’s call it Youtube, the youtube website is currently the number 3 most visited website in the world.

If you are having trouble creating a website that can upload videos, here is a script for uploading videos with PHP that you can follow.

Here TWD will only provide an example in one upload-video.php file, for further details you can develop your own according to the arrangement of the web creation directory you are working on.

First a php file with the name upload-video.php

Next, write the following script to create a form and process the video when the UPLOAD button is pressed, put this script in the body and /body tags.

How to Install Phalcon Framework PHP on Windows

To install the Phalcon Framework on Windows and use it for web development purposes, you can first download the Phalcon library DLL.

After downloading, extract the dll then copy-paste it into the xampp/php/ext folder, see the picture below for details.

Untitled1

Then open the php.ini file in the xampp/php folder. Here’s a picture for details

Untitled2

Add phalcon extension in php.ini as shown below:

Capture1

Now we will check whether the phalcon framework has been installed or not. Simply create a .php file or you can look at phpinfo.

Untitled3

Check with the .php file, create a new folder in htdocts named phalcon_cek then create a new file index.php with the source code to check phalcon


Open a browser and run http://localhost:8080/phalcon_cek/ it will look like this if phalcon is installed

Untitled4

Congratulations you have finished installing phalcon 🙂

Creating a “Hello World!” Application with Phalcon Framework PHP

application with Phalcon Framework | In this tutorial we will try to create a “Hello World” with Phalcon Framework PHP. Before using phalcon you have to install phalcon .dll in xampp (Installing Phalcon Framework PHP on Windows).

Create a folder and some files as follows:

Capture1

Open the Phalcon_HelloWorld/.htaccess file and enter the source code below:

RewriteEngine on RewriteRule ^$ public_html/ [L] RewriteRule (.*) public_html/$1 [L]
.htaccess
All requests to the application will be rewritten to the public_html/ directory making it the document root. This step ensures that the system’s internal folders remain hidden from public view and eliminates a security threat to this vulnerabilities.

Open the second file Phalcon_HelloWorld/public_html/.htaccess

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) index.php?_url=/$1 [QSA,L]
public_html/.htaccess
Then we will create a bootsrap file. This file is very important as it acts as the base of the application giving you all the control.

Phalcon_HelloWorld/public/index.php

<?php

try {

//Register an autoloader
$loader = new PhalconLoader();
$loader->registerDirs(array(
    '../app/controllers/',
    '../app/models/'
))->register();

//Create a DI
$di = new PhalconDIFactoryDefault();

//Setup the view component
$di->set('view', function(){
    $view = new PhalconMvcView();
    $view->setViewsDir('../app/views/');
    return $view;
});

//Setup a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function(){
    $url = new PhalconMvcUrl();
    $url->setBaseUri('/Phalcon_HelloWorld/');
    return $url;
});

//Handle the request
$application = new PhalconMvcApplication($di);

echo $application->handle()->getContent();

} catch(PhalconException $e) {
echo “PhalconException: “, $e->getMessage();
}
public_html/index.php
Creating a controller by default Phalcon will look for a controller named “Index”. This is the starting point when no controller or action is requested in the request. Create a new file named IndexController.php in the folder Phalcon_HelloWorld/app/controllers/IndexController.php

<?php

class IndexController extends PhalconMvcController
{

public function indexAction()
{
    echo "<h1>Hello World!</h1>";
}

}
app/controller/IndexController.php
The controller class must end in “Controller” and the actions on the controller must end in “Action”. If you have finished following all the tutorials above, the folder arrangement will look like this:

Capture2

Now let’s see in the browser, if it is correct it will look like this http://localhost:8080/Phalcon_HelloWorld/

Untitled1

Congratulations, you have finished learning the basics of the phalcon framework 😀

Session Implementation in Codeigniter 3

How to use or implement sessions in Codeigniter 3 | The function of the session is to store the information needed by the application and can be shared throughout the web page, and this session is stored in a file on the web server environment.

To be able to use the Session class, we need to load the Session.php class library into the controller

$this->load->library(‘session’)
load session
Creating and Accessing SESSION
In native PHP, the function called to run a session is session_start(); at the beginning of the script. In Codeigniter this is not required. If we create a session in native php, we use $_SESSION;

start_session()_;
$_SESSION[‘session_name’] = “value”;
then the case is different if we use the session in codeigniter. We can directly write with the following code:

$this->session->set_userdata(‘session_name’, ‘session_value’)
as an example :

$this->session->set_userdata(‘username’,’administrator’)
example
To access session variables that have been created previously, we can use the following code:

$this->session->userdata(‘username’)
if you want to display the contents of the session variable, just add echo, so it becomes

session->userdata(‘username’);
?>
That is all and thank you 🙂