|
|
|
|
|
для: Рома
(30.06.2009 в 22:21)
| | нас много | |
|
|
|
|
|
|
|
для: nikita2206
(29.06.2009 в 18:16)
| | В конце сделал так
templ_creator.php
<?
class templ{
public $tr_found = 0;
public $replace;
public $tpl;
public $result;
private $top;
private $down;
private $constructor;
private $center;
public function __construct($tplDir,$tplFile){
$this->tplDir = $tplDir;
$this->tplFile = $tplFile;
}
public function set($value = NULL){
$this->replace[$this->tr_found] = $value;
$this->tr_found += 1;
}
public function Counstruct(){
$this->tpl = file_get_contents($this->tplDir.$this->tplFile.'.tpl');
preg_match_all('|(.+?){foreach}(.+?){/foreach}(.*)|s', $this->tpl, $cycles);
$this->top=$cycles[1][0];
$this->constructor=$cycles[2][0];
$this->down=$cycles[3][0];
$cycles = null;
preg_match_all('|({\$\d})|s', $this->constructor, $cycles);
$count = count($cycles[0]);
for($a=0;$a<$this->tr_found;$a++){
$shab =$this->constructor;
for($i = 0; $i < $count; $i++){
$shab = str_replace($cycles[0][$i], $this->replace[$a][$i] ,$shab);
}
$this->center .= $shab;
}
$this->result = $this->top.$this->center.$this->down;
return $this->result;
}
}
?>
|
question_list.php
<table title="Some text" width="100%" rules="rows">
<tr>
<td title="סטטוס" width="1%"></td>
<td title="Some text"><strong title="Some text">Some text</strong></td>
<td title="Some text" width="1%"></td>
<td title="Some text" width="2%"></td>
<td title="Some text" width="5%"><strong title="Some text">Some text</strong></td>
<td title="Some text" width="3%"><strong title="Some text">Some text</strong></td>
<td title="Some text" width="1%"><strong title="Some text">Some text</strong></td>
</tr>
{foreach}
<tr title="{$0}" style="border-bottom-style:1px solid;border-bottom-color: #99CCCC;">
<td><span class="{$1}" dir="ltr"></span></td>
<td nowrap="nowrap"><span onclick="javascript: window.location='?vio=1&act=view&id={$2}'" style="font-weight:bold;">{$3}</span></td>
<td><span class="star" dir="ltr"></span></td>
<td><span dir="ltr">{$4}</span></td>
<td><span>{$5}</span></td>
<td><span dir="ltr"><strong>{$6}</strong></span></td>
<td><span dir="ltr">{$7}</span></td>
</tr>
{/foreach}
</table>
<br />
|
<?
require_once 'templ_creator.php';
$templator = new templ('tample/vio/','question_list');
$templator->set(array(
$f[id_subj],
$pic_class,
$f[id],
mb_substr($f[id_subj],0,122),
$f[id_ball],
get_name($f[id_user]),
$f[id_answers],
gmdate(' H:i',$f[id_date]),
));
echo $templator->Counstruct();
?>
|
| |
|
|
|
|
|
|
|
для: golovdinov
(30.06.2009 в 21:24)
| | Да с телефона писать неудобно.
То есть двух шаблонов не исбежать? Фигово. Но всё же я попробую покрутить выше приведённый скрипт :-) всего то надо массив ещё один добавить или сделать его войнным. | |
|
|
|
|
|
|
|
для: werd
(30.06.2009 в 14:54)
| | Правильно говоришь, я тоже предпочитаю разбираться в каждом кусочке своего кода. | |
|
|
|
|
|
|
|
для: werd
(30.06.2009 в 20:46)
| | Этого не избежать, т.к. вышеприведенный принцип применяется абсолютно везде (Smarty, XSLT и т.д.). Если записей неограниченное количество, то по другому никак. Тем более, что недостатков в таком подходе минимум.
PS: п*здец у тебя грамматика с орфографией :) | |
|
|
|
|
|
|
|
для: golovdinov
(30.06.2009 в 18:39)
| | Это имено то чего нехочу. | |
|
|
|
|
|
|
|
для: GeorgeIV
(30.06.2009 в 19:38)
| | Это да :-)
Большой проект другой разговор , даже 2 разработчика уже другое дело. Но я один. И за принцип взял сам все разработывать. | |
|
|
|
|
|
|
|
для: werd
(30.06.2009 в 14:54)
| | все это хорошо, когда балуешься со своей страничкой и неприемлемо в больших проектах | |
|
|
|
|
|
|
|
для: werd
(29.06.2009 в 06:34)
| |
<?php
$templateTable = <<<HTML
<table>{rows}</table>
HTML;
$templateRow = <<<HTML
<tr>
<td>{val1}</td>
<td>{val2}</td>
<td>{val3}</td>
</tr>
HTML;
$data = array (
array (1,2,3),
array (4,5,6),
array (7,8,9)
);
$sRows = "";
foreach ($data as $rowData) {
$sRow = $templateRow;
$sRow = str_replace ("{val1}", $rowData[0], $sRow);
$sRow = str_replace ("{val2}", $rowData[1], $sRow);
$sRow = str_replace ("{val3}", $rowData[2], $sRow);
$sRows .= $sRow;
}
$result = str_replace ("{rows}", $sRows, $templateTable);
?>
|
Суть проста: есть шаблон таблицы и шаблон строки (<tr>), складываем несколько обработанных шаблонов строки и вставляем в таблицу. | |
|
|
|
|
|
|
|
для: GeorgeIV
(30.06.2009 в 10:57)
| | да нет, это всего лишь называется работать своими мозгами.
Я предпочитаю понимать каждую функцию в своём коде. Нежели лазить по мануалам других разработчиков | |
|
|
|
|