• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem to load array since the controller to view

#1
[eluser]Yayo[/eluser]
In my application is not possible load one array since the controller to views.
How is possible if another arrays in controller's function can be loaded?

This is my controllerSadMY_Controller is new controller make for me, it work fine, the Controller.php make for code Igniter exist too en library)

class Reporte extends MY_Controller
{
function __construct()
{
parent::MY_Controller();
$this->load->model('ReporteModel', 'model');
}
function ReporteGeneral(){

$data2['array_inv2'] = $this->model->get('v_estudiantes_invitados2_cant');
$data2['array_inv1'] = $this->model->get('v_estudiantes_invitados1_cant');
$data2['array_no_inv'] = $this->model->get('v_estudiantes_sin_invitados_cant');
$data2['array_facultad'] = $this->model->get('v_sin_reservar_cant');
$data2['total_facultad'] = $this->model->get('v_total_por_facultad');
$data2['sin_invitados'] = $this->model->get('v_sin_invitados_fac_cant');
$data['view_estudiantes_con_inv'] = $this->load->view("pages/reporte/estudiantes_con_invitados",$data2,true);
$data['array'] = $this->model->get('v_familiar_punto_recogida_cant');
$this->template['content'] = $this->load->view('pages/reporte/general', $data,true);
$this->render();
}
}

My view: general

<?php
var_dump($sin_invitados);
?>

Messaje error:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: sin_invitados
NULL

What is the error? The another arrays (array_inv2,array_inv1...)are detected in the view.
The unique no detected is thisConfusedin_invitados

#2
[eluser]WeeJames[/eluser]
The data that is passed to your view does not contain a key called 'sin_invitidos' and therefore is inaccessible by the general view. $sin_invitidos is only accessible in $data2 which is passed to the 'estudiantes_con_invitados' view. If you want $sin_invitidos to be availible to the general view it must be a key in the array ($data) passed to the general view.

#3
[eluser]Yayo[/eluser]
Thanks for respond my post, but look my controller, you see the sentences:

$data2[’sin_invitados’] = $this->model->get(’v_sin_invitados_fac_cant’);
.
.
.
$data[’view_estudiantes_con_inv’] = $this->load->view("pages/reporte/estudiantes_con_invitados",$data2,true); .
.
.
.
$this->template[’content’] = $this->load->view(’pages/reporte/general’, $data,true);

The array $data2 is passed. With this explanation, I'm hope that you can help me
to solve the problem.

I'm think that it is a possible bug of Code Igniter. What is your opinion?

#4
[eluser]WeeJames[/eluser]
No.. you're not passing $data2 to the general template. All you are passing through is a value called $view_estudiantes_con_inv while contains the output generated by

Code:
$this->load->view("pages/reporte/estudiantes_con_invitados",$data2,true);

Values in $data2 are local to the 'estudiantes_con_invitados' template and values in $data are local to the 'general' template. At no point are you making the values in $data2 available to 'general', you're only making the output of the view that uses it available.

Its not a bug of CI.. its a problem with your understanding of the way views work.

#5
[eluser]Yayo[/eluser]
But the another arrays (Example:$data2[’array_inv2’],$data2[’array_inv1’]) used yes passed to general

The array data2 is passed to the view estudiantes_con_invitados, but this view is inside in the view general.

The another arrays in the function of the controller, can passed to the view, only the array $data2[’sin_invitados’] Can not pass.

Excuse me for the english, my native language is the spanish.

#6
[eluser]Yayo[/eluser]
Explanation:

the function called for the class model ($this->model->get('’v_sin_invitados_fac_cant')), return one array; this array is save in another array in the controller: $data2,
$data2 is passed to the view in the sentences:


$data[’view_estudiantes_con_inv’] = $this->load->view("pages/reporte/estudiantes_con_invitados",$data2,true);

and the array $data is passed to view general in the sentences

$this->template[’content’] = $this->load->view(’pages/reporte/general’, $data,true);
Then show the view with the function $this->render();
this ultimate function is make in the controller MY_Vontroller make for me. This work fine, are test in another application.

#7
[eluser]WeeJames[/eluser]
No.. you dont pass anything from $data2 to general.. all you pass is the html generated using $data2 in 'estudiantes_con_invitados' as a new variable called $view_estudiantes_con_inv to the general view.

#8
[eluser]Yayo[/eluser]
You have the reason, to the view general, do not pass the array $data2, is the html, but to make the html, I'm paasing the array $data2 to the view in this sentences.

$data[’view_estudiantes_con_inv’] = $this->load->view("pages/reporte/estudiantes_con_invitados",$data2,true); .

The html is here: $data[’view_estudiantes_con_inv’], but to the view "estudiantes_con_invitados" no pass the data of
$data2['sin_invitados'], however, the another data can pass to the view estudiantes_con_invitados (Example can pass:$data2[’array_facultad’], $data2[’array_no_inv’]). All this arrays are present in the same array $data2, include the array $data2['sin_invitados'] where is present the problem.

Then, How pass the array $data2['in_invitados'] to the view "estudiantes_con_invitados"?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.