Welcome Guest, Not a member yet? Register   Sign In
Pass a variable of a controller to another controller
#6

[eluser]masentinel900[/eluser]
Thanks everybody by your responses.
I'm doing this:
Controller 1
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class Maincontent extends CI_Controller
{
public function __construct()
{
  parent::__construct();  
  $this->load->model('content','', TRUE);
  $this->load->helper('form');
}
function index()
{  
  $query = $this->content->contenido();
  echo "
  [removed][removed]
  <table cellpadding='0' cellspacing='0' border='0' class='display' id='tabla_lista_paises'>
    <thead>
                    <tr>
                        <th>Id</th>
                        <th>Nombre</th>
      <th>Propietario</th>
      <th>Ultima modificacion</th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th></th>
                        <th></th>
                        <th></th>
                        <th></th>
                    </tr>
                </tfoot>
                  <tbody>
  ";

  foreach($query->result() as $row)
  {
   echo "
   <tr>
    <td id=''>&lt;input name='opcion-res' type='radio' align='center'/&gt;&lt;/td>
    <td id=''><a href='download'>$row->rutaarchivo</a></td>
    <td id=''>$row->modificadopor</td>
    <td id=''>$row->fechademodificacion</td>
    &lt;input type='hidden' value='hola'/&gt;
   </tr>  
   ";  
  $data = array(
  'rutaarchivo' => $row->rutaarchivo,
  );
  }  
  $this->session->set_userdata($data);
}
}
?&gt;

In this controller I generate a dynamic table with info from the database. The table have four rows, in the second row appear the name of the file.. When the user onclick in the name of the file ("second row"), active the download controller with "href".

This is the controller "download"

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class Download extends CI_Controller
{
public function __construct()
{
  parent::__construct();  
  $this->load->model('content','', TRUE);
}
function index()
{
  /*
  $query = $this->content->contenido();
  foreach($query->result() as $row)
  {
   $ruta = $row->rutaarchivo;
  }  
  */
  $ruta = $this->input->post('hola');
  $this->load->helper('download');
  $data = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Online-App/filesFolder/" . $ruta);
  $name = $ruta;
  force_download($name, $data);
}

function insert()
{
  $nombre = array(
  'nombreacta' => $this->input->post('nombreacta'),
  'descripcion' => $this->input->post('descripcion'),
  'rutaarchivo' => $this->input->post('nombreacta'),
  );
  $this->content->insert($nombre);
}
}
?&gt;

Right now I just i'm using the index method, Which about the route of the file download the corresponding file stored in my server folders.

The problem is that I need load the variable rutaarchivo which is a row of my DB, this variable should to be in due controller, In the frst bucause there I'm bringing from the DB, and the second controller because there I going to use it for may to do the download..

When I store the variable "$data" and I set for the userdata session Show me the next log error..



A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www\Online-App\CodeIgniter\application\controllers\maincontent.php:46)

Filename: libraries/Session.php

Line Number: 672


And also I tried of pass it through form helper, but I see that is not possible because I donĀ“t have the button of submit for pass the value..


Messages In This Thread
Pass a variable of a controller to another controller - by El Forum - 11-07-2012, 01:18 PM
Pass a variable of a controller to another controller - by El Forum - 11-07-2012, 07:59 PM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 05:22 AM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 06:25 AM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 06:28 AM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 06:51 AM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 08:59 AM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 09:47 AM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 10:01 AM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 10:11 AM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 10:39 AM
Pass a variable of a controller to another controller - by El Forum - 11-08-2012, 11:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB