Welcome Guest, Not a member yet? Register   Sign In
Some assignments to $this->data array not 'sticking'
#1

(This post was last modified: 10-11-2016, 04:12 PM by howardb1.)

I'm stuck on a problem where several assignments to the $this->data array do not seem to be happening.  No errors are output, but it is as if these assignments were not made.  In the view function of one of my controllers there are several assignments to this array, which work, but now I'm trying to add new functionality to the page built by this function and none of the new assignments to this array can be seen by the resulting page.

Here are several that work:

  $results = $this->person_model->get_profile( $slug );
  if( $results ) $this->data[ 'person_data' ] = $results;

  $results = $this->person_model->get_photos( $user_id );
  if( $results ) $this->data[ 'person_photos' ] = $results;

  $results = $this->person_model->get_videos( $user_id );
  if( $results ) $this->data[ 'artist_videos' ] = $results;

  if( $anchor != -1 ) $this->data[ 'person_anchor' ] = $anchor;


Here are two of the assignments that don't appear to be happening:

  $this->data[ 'counter1' ] = 100;
  $this->data[ 'allOtherInfo' ] = 'hi';

The page  that is created after these statements occurs outputs the keys that are in the $this->data array using this statement:

  print_r( array_keys( $this->data ) );

Here is that output:

  Array ( [0] => headjs,  [1] => person_data,  [2] => 1, person_videos [3] => person_photos )

The output is messing the person_anchor, counter1 and allOtherInfo keys!

Here is the view function that intern calls the render function to actually create the output, in which the $this-data array's keys are shown:


Code:
function view( $slug=NULL, $anchor=-1 ) {

 $this->data[ 'headjs' ] = "...";

 // The slug and anchor parameters are
 // overwritten with the URL segments,
 // below:

 $slug   = $this->uri->segment( 3 );
 $anchor = $this->uri->segment( 4 );

 // Clear any previously assigned values.
 $this->data[ 'person_data' ]   = [];
 $this->data[ 'allOtherInfo' ]  = [];


 // Meaningless assignment just for demonstration.
 $this->data[ 'counter1' ] = 100;  // Doesn't show in output!

 // slug contains the name of a person
 // to be displayed.

 if( !is_numeric( $slug ) ) {

   $results = $this->person_model->get_profile( $slug );
   if( $results ) $this->data[ 'person_data' ] = $results;

   $row = $this->person_model->user_slug( $slug );
   $user_id = $row[ 0 ]->user_id;
   $artist_id  = $row[ 0 ]->id;

   $results = $this->person_model->get_photos( $user_id );
   if( $results ) $this->data[ 'person_photos' ] = $results;

   $this->data[ 'allOtherInfo' ] = 'hi';  // Doesn't show in output!

   $results = $this->person_model->get_videos( $user_id );
   if( $results ) $this->data[ 'person_videos' ] = $results;

   if( $anchor != -1 ) $this->data[ 'person_anchor' ] = $anchor;

   $this->_render_page( 'public/profile.tpl.php', $this->data );

 }

 $this->data[ 'person_data' ]   = [];
 $this->data[ 'person_photos' ] = [];
 $this->data[ 'person_videos' ] = [];
 $this->data[ 'allOtherInfo' ]  = [];

}
Reply
#2

Try using this after you set all your data and see if it works.

PHP Code:
$this->load->vars($this->data); 

Remove the $this->data from your render view.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

It might be helpful if you could show the _render_page function.
Reply
#4

(10-11-2016, 05:31 PM)InsiteFX Wrote: Try using this after you set all your data and see if it works.

PHP Code:
$this->load->vars($this->data); 

Remove the $this->data from your render view.

Thanks.   Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB