Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14348

Some assignments to $this->data array not 'sticking'

$
0
0
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' ]  = [];

}

Viewing all articles
Browse latest Browse all 14348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>