Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

question

posted by mungiu 10 years ago

i have this code:

	for($j=1; $j<=1; $j++){
		if(!empty($row["poza".$j])) {

			$picx_mic= $thumb."?src=../media/foto_news/".$row["poza".$j]."&w=80";
			$picx= "../media/foto_news/".$row["poza".$j]."&w=500";
			${"x2_".$j} = "<img src='".$picx_mic."' onclick='open_view(\\"".$picx."\\",\\"".$row["titlu"]."\\")' style='cursor:pointer;' title='".$row["titlu"]."' />";
			${"POZA_".$j} = ${"x2_".$j};
			
		}else {
			${"POZA_".$j} = '<img src="" width="80" />';
		}
		$xtpl->assign("POZA$j", ${"POZA_".$j});	
	}
	

how can i transform this in flourish stye to be like

foreach ( $details as $detail ) {
	
	
	
	for($j=1; $j<=1; $j++){
		if(!empty($detail->getIdNews().......$j)) {

I think I would need to know a little bit more about your database schema to give any insight. From what I can tell, there are a number of columns in your table that hold image filenames and you need to create HTML from those and assign it to a template.

I am guessing you want to know how to do with with the ORM? Your current code should work just fine using a plain fDatabase::query() call.

posted by wbond 10 years ago

Yes, you right, if i have 2 or more columns like picture1, picture2, etc, to loop trought amoungh this not to verify every columnt if contain picture, and i asked if it is posible to do with orm, but i guess is't possible, so if i will need this i use a regular mysql statement, tank you for response.

posted by mungiu 10 years ago

It certainly is possible with the ORM. Here is how I would do it with your current setup:

foreach ($details as $detail) {
	for($j=1; $j<=1; $j++){
		
		$value  = $detail->{'getPoza' . $j}();
		
		if ($value) {
			$html_picx_mic = fHTML::encode($thumb . "?src=../media/foto_news/" . $value . "&w=80");
			$js_picx       = fJSON::encode("../media/foto_news/" . $value . "&w=500");
			$js_titlu      = fJSON::encode($detail->getTitlu());
			// This is the same as fHTML::encode($detail->getTitlu())
			$html_titlu    = $detail->encodeTitlu();
			$html          = '<img src="' . $html_picx_mic . '" onclick="open_view(' . $picx . ',' . $js_titlu . ')" style="cursor:pointer;" title="' . $html_titlu . '" />';
			
		} else {
			$html = '<img src="" width="80" />';
		}
		
		$xtpl->assign("POZA" . $j, $html);    
	} 
}
posted by wbond 10 years ago

tank yo for this, i don't know php perfectly and for this $value = $detail->{'getPoza' . $j}(); i lookin' for. on the other hand, to not open another topic, i would like to ask u if you know if the showChecked function work fine in new releases, i updated today to last relase and now it not workin' corectly. i have something like this

$xtpl->assign ( 'checked', fHTML::showChecked($customer->prepareActiv(), 1) );

whith change into flourish function to return not to print.

posted by mungiu 10 years ago

fHTML::showChecked() follows the MethodNaming conventions of Flourish, with the show part meaning that it will conditionally print something. It also returns a boolean indicating if it printed or not. My recommendation would be to write your own method if you just want to see if a value is equal or in an array instead of also printing checked="checked".

posted by wbond 10 years ago

but why before this method work for me and now isn't? i have column 'activ' with 0 and 1 values, i want the 1 value to get checked atribute

posted by mungiu 10 years ago

fHTML::showChecked() (which used to be fCRUD::showChecked()) has always printed something and returned a boolean. The only changes that have been made recently are at http://flourishlib.com/changeset/588/fHTML.php. This change requires that comparing to a NULL value requires a strict equality (i.e. both must be NULL) where the old code equated 0 and NULL. This change was made because databases tend to allow for NULL, FALSE and TRUE values in boolean columns and I wanted to reflect this distinction.

posted by wbond 10 years ago

ok, i think i find where is the problem , i use prepareActiv method, 'activ' been a column whit tinyint value 0 and 1, and prepare transform into yes and no, now i put getActiv, and when i printed, print only value equal whith 1. why? this didn't happend 'till i upgrade to 598, i think u make some change till then on the prepare method

posted by mungiu 10 years ago

I haven't changed the prepare method in quite a while. You can see what happened at each revision by browsing around at http://flourishlib.com/changeset/598. Like I said, I don't see how that code would ever have worked correctly since fHTML::showChecked() has always printed checked="checked".

posted by wbond 10 years ago