Php Foreach Causing “White Page” In Yii Framework, Loading Styles From Db

Hey Fellow YiiTES! I’ve been working with the framework for a few months and loving every minute of it. However, when dabbling with my own CMS style implementation using the BLOG demo I have come across a strange “white page” situaton.

I am loading my stylesheets from my DB, kind my own interesting attempt at building a CMS. Anyways I am currently doing this by calling the styles in the head section of my main.php in my layout. This is the Yii framework btw. It’s very strange because this worked for about 10 hours and then all of a sudden stopped being accepted. I am thinking it may be a bad value in the database that is throwing the stylesheets off but they all seem to load correctly when i preview the html. Here is my code;

I have narrowed it down to this line is somehow causing the error (which php will not report on) but I can’t figure out why:




     echo $valueStrip.":".$cssAttrib->$value2.";";



here is the rest of the code so you can make sense of it:




$sql = 'Select selector from tbl_css t';


 $css= Yii::app()->db->createCommand($sql)->queryAll();

$cssCols = new Css;

$cssColsAr = $cssCols->attributeLabels('');


 foreach($css as $key => $value)

 {


 foreach($cssColsAr as $key2 => $value2)

 {

  $cssAttrib = Css::model()->find('selector=:selector', 

                                  array(':selector'=>$value['selector']));

  $valueStrip = $value2;

  $valueStrip = str_replace('_','-',$value2);

 

  echo "<style>";

  echo $value['selector']."{";

  echo $valueStrip.":".$cssAttrib->$value2.";";

  echo "}</style>";

 }

}



here’s an example of the generated styles:

body{color:white;} body{margin:0 px auto;}

etc… I see no reason for it to crash? Any help from the YiiMasters is greatly appreciated.

my understanding is that you want query your database for all key-value pairs associated with one particular selector. you should post a database table, but you could do it with one query.

1 Like