CodeIgniter Forums
echo redirection - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: echo redirection (/showthread.php?tid=54552)



echo redirection - El Forum - 09-13-2012

[eluser]Captain_Fluffy_Pants[/eluser]
How to echo a redirection in a controller?
i tried
Code:
<?php
class Blog extends CI_Controller {

public function index()
{
  echo page_url'pages/home';
}

public function comments()
{
  echo 'Look at this!';
}
}
but that didnt work.



echo redirection - El Forum - 09-13-2012

[eluser]term25[/eluser]
page_url'pages/home'is wrong

you can use instead

Code:
base_url('pages/home');

or

Code:
site_url('pages/home');

btw. you need to use
Code:
die();
after the echo in your controller if you want to stop execution the code and check what is the problem when debugging like:

Code:
echo base_url('pages/home');
die();

The other way is to send the value to your view like:

Code:
$data_to_send_to_view = base_url('pages/home');
$this->load->view('your-view', $data_to_send_to_view);

And in your view output like:
Code:
echo $data_to_send_to_view;