How To redirect in codeigniter Examples

Today, We want to share with you How To redirect in codeigniter Examples.In this post we will show you codeigniter redirect refresh, hear for call to undefined function redirect() we will give you demo and example for implement.In this post, we will learn about How To Open URL In New Tab Using CodeIgniter with an example.

How To redirect in codeigniter Examples

There are the Following The simple About codeigniter redirect to homepage Full Information With Example and source code.

As I will cover this Post with live Working example to develop redirects in codeigniter using base_url, so the redirects to external url in codeigniter is used for this example is following below.

CodeIgniter – Page Redirection

How To redirect in codeigniter Examples
How To redirect in codeigniter Examples

While building PHP Based codeigniter User Friendly web application, I always required to open new tabe redirect the any other from one page to another page with parameters. here PHP Based CodeIgniter creates this task with demo easy for us. The codeigniter redirect() methods is used for this best solution for us.

Another must read:  Wordpress Advanced Search query custom fields

Step 1: Create a codeigniter controller

application/controller/Product_controller.php

<?php 
   class Product_controller extends CI_Controller { 
	
      public function index() { 
         $this->load->helper('url'); 
         redirect('https://www.pakainfo.com'); 
      }
		
      public function product_list() { 
         $this->load->helper('url'); 
         redirect('https://www.pakainfo.com/product_list/index.htm'); 
      } 
  
      public function estores() { 
         $this->load->helper('url'); 
         redirect('redirect/product_list'); 
      } 
		
   } 
?>

Step 2: Change the routes in codeigniter

application/config/routes.php

$route['redirect'] = 'Product_controller'; 
$route['redirect/estores'] = 'Product_controller/estores'; 
$route['redirect/product_list'] = 'Product_controller/product_list';

Step 3: run in Browsers

http://domain-name.com/index.php/redirect
http://domain-name.com/index.php/redirect/product_list

CodeIgniter redirect: white page

redirect('product-list');

//using Refresh
header("Refresh:0;url=".$uri);

//using and location:
header("Location: ".$uri, TRUE, $http_response_code);

redirect in codeigniter using base_url

CodeIgniter: Passing some data along with the redirect

redirect('/signin/form/', 'refresh');

$this->session->set_flashdata('products', 'products_value');
$message = $this->session->flashdata('products');

here full example of the Pass Data From CodeIgniter Controller to View page

Make a View

application/views/shoplistweb.php

<html>
<head>
        <title>Wordpress</title>
</head>
<body>
        <h1>Welcome to Wordpress</h1>
</body>
</html>

Load the View

$this->load->view('name');

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

controller -> WordPress.php

<?php
class Wordpress extends CI_Controller {
    public function index()
    {
        $this->load->view('shoplistweb');
    }
}

Your-domain.com/index.php/blog/

Pass array from controller to view

$data['mega_header'][] = (object) array('seo_title_part' => 'Welcome To Pakainfo' ,
    'img' => 'https://www.pakainfo.com/semail/default.jpeg' );
$this->load->view('multiple_array', $data);

view file

<?php
        if (isset($mega_header)){
            foreach ($mega_header as $key) {
                ?>
                <div class="header_item">
                    <img alt="<?php echo($key['seo_title_part']); ?>" src="<?php echo($key->img); ?>"/>
                </div>
                <?php
            }
        }
        ?>

Load Multiple Views

<?php
class Page extends CI_Controller {
    public function index()
    {
        $data['page_title'] = 'seo_title_part';
        $this->load->view('header');
        $this->load->view('menu');
        $this->load->view('content', $data);
        $this->load->view('footer');
    }
}

Sort Views in Subfolders

$this->load->view(‘directory_name/file_name’);

Add Dynamic Data to Views

$data = array(
    'seo_title_part' => 'Online Development and Testing Tools',
    'title_h1_part' => 'Pakainfo - Online Educational Computer Programming website',
    'message' => ' Pakainfo helps build web applications,tutorials,programming,examples,source code,demos,tips.It is an educational blog for learning web technologies online.'
);
$this->load->view('shoplistweb', $data);

in controller

Another must read:  Laravel Encryption Decryption using Crypt class

<?php
class Wordpress extends CI_Controller {
    public function index()
    {
        $data['seo_title_part'] = "Online Development and Testing Tools";
        $data['title_h1_part'] = "Pakainfo - Online Educational Computer Programming website";
        $this->load->view('shoplistweb', $data);
    }
}

the view file

<html>
<head>
    <title><?php echo $seo_title_part;?></title>
</head>
<body>
<h1><?php echo $title_h1_part;?></h1>
</body>
</html>

Make the Loops

<?php
class Wordpress extends CI_Controller
{
    public function index()
    {
        $data['task_all'] = array('pakainfo', 'infinityknow', 'jdk group');
        $data['seo_title_part'] = "Online Development and Testing Tools";
        $data['title_h1_part'] = "Pakainfo - Online Educational Computer Programming website";
        $this->load->view('shoplistweb', $data);
    }
}

the view file

<html>
<head>
    <title><?php echo $seo_title_part;?></title>
</head>
<body>
<h1><?php echo $title_h1_part;?></h1>
<ul>
    <?php foreach ($task_all as $task):?>
    <li><?php echo $task;?></li>
    <?php endforeach;?>
</ul>
</body>
</html>

Returning View as Data

$string = $this->load->view('fileview', '', TRUE);

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about redirects with success message in codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Another must read:  PHP Ternary shorthand If/Else Examples

Leave a Reply

Your email address will not be published. Required fields are marked *