Pogledajte određenu poruku
Staro 12. 10. 2011.   #1
bogdan16
novi član
Na probnom radu
 
Datum učlanjenja: 27.08.2011
Poruke: 17
Hvala: 8
0 "Hvala" u 0 poruka
bogdan16 is on a distinguished road
Question Templejt sistem?

Nasao sam templejt klasu koja umnogome odgovara mojim zahtevima medjutim treba malo da je prilagodim.Medjutim ne znam kako to da uradim.Ipak to mi se cini mnogo lakse nego da iznova pisem svoj templejt menadzment sistem ili da ucim i koristim Smarty ili neki drugi template engine.
Sada cu vam dati glavne funkcije koje se odnose na ubacivanje html templejta.Kasnije cu se sam pozabaviti ubacivanjem podataka da vas sad ne opterecujem time.
Ova templejt klasa sadrzi sablon bitova preko koga treba da se ubacuju html sabloni.Bas to mi to nije jasno.KAKO UBACITI HTML SABLONE PREKO OVOG KODA I GDE,to je u sustini neki glavni problem.Pokusao sam sam da razumem kod i nadjem resenje ali jos uvek nisam uspeo.
U kodu cu napisati koji mi redovi nisu jasni.

/** * Set the content of the page based on a number of templates * pass template file locations as individual arguments * @return void */
public function buildFromTemplates()
{
$bits = func_get_args();
$content = "";
foreach( $bits as $bit ) //Foreach petlja prolazi kroz svaki element(ovde bit) niza bits i izvrsava blok naredbi
{
if( strpos( $bit, 'views/' ) === false )
{
$bit = 'views/' . $this->registry->getSetting('view') . '/templates/' . $bit; //Ovde se stringu $bit koji prestavlja element niza dodeljuje ovo 'views/' koje ne znam sta prestavlja putanju ili sta vec
}
if( file_exists( $bit ) == true )
{
$content .= file_get_contents( $bit );
}
}
$this->page->setContent( $content );
}

/** * Add a template bit from a view to our page * @param String $tag the tag where we insert the template e.g.{hello} * @param String $bit the template bit (path to file, or just the
filename) * @param Array $replacements template bit specific replacements * @return void */
//Gde god templejt $bit pronadje $tag ukljucuje novi sablon u okviru glavnog sablona U $tag se ubacuje sablon a u $bit putanja do fajla ili ime fajla otprilike ovako sam ja ruzumeo ovu funkciju.Sad mi nije jasno kako stringu $tag dodeliti ovaj neki html sablon i gde
public function addTemplateBit( $tag, $bit, $replacements=array() )
{
if( strpos( $bit, 'views/' ) === false )
{
$bit = 'views/' . $this->registry->getSetting('view') . '/templates/' . $bit;
}
$this->page->addTemplateBit( $tag, $bit, $replacements );
{
$this->bits[ $tag ] = array( 'template' => $bit,'replacements' => $replacements);
}}



/** * Take the template bits from the view and insert them into our page
content * Updates the pages content * @return void */
//U ovoj trecoj funkciji se vrsi zamena.Samim tim sto mi prethodne f-je nisu jasne logicno da mi ni ova nije jasna
private function replaceBits()
{
$bits = $this->page->getBits();
// loop through template bits
foreach( $bits as $tag => $template )
{
$templateContent = file_get_contents( $template['template'] );
$tags = array_keys( $template['replacements'] );
$tagsNew = array();
foreach( $tags as $taga ) { $tagsNew[] = '{' . $taga . '}';
}
$values = array_values( $template['replacements'] );
$templateContent = str_replace( $tagsNew, $values,$templateContent );
$newContent = str_replace( '{' . $tag . '}', $templateContent,$this->page->getContent() );
$this->page->setContent( $newContent );
}
}

Molim vas ako moze neko da mi pojasni ove f-je ili da mi da neki tutorijal u koje je ovo objasnjeno.Nalazio sam nekoliko tutorijala u vezi template klasa ali ni iz jednog ne mogu da zakljucim kako da resim ovaj problem.
Hvala unapred.
bogdan16 je offline   Odgovorite uz citat