Dzięki za info, już poprawione.
Dokumentacja starego OPT dostępna jest pod adresem:
https://invenzzia.org/docs/opt-en/ (jedynie w wersji angielskiej)
|
1
on: April 09, 2008, 02:14:21 PM
|
||
| Started by deallas - Last post by eXtreme | ||
|
Dzięki za info, już poprawione.
Dokumentacja starego OPT dostępna jest pod adresem: https://invenzzia.org/docs/opt-en/ (jedynie w wersji angielskiej) |
||
|
2
on: April 08, 2008, 10:38:06 PM
|
||
| Started by deallas - Last post by deallas | ||
|
Coś wam się krzaczą style na forum. Kropa wchodzi na tekst. Błąd wystepuje pod Firefoxem 2 pod Linuxem i pod Epiphany. Nie wiem jak jest na windowsie ale domyślam sie że tak samo. Najprościej dodać do pliku style.css (line 5) coś takiego: list-style-type:none;
pozdro P.S Apropo gdzie jest dokumentacja ze starej strony bo nie mogłem znaleźć wersji online |
||
|
3
on: April 05, 2008, 03:15:51 PM
|
||
| Started by kapitan_hak - Last post by eXtreme | ||
|
A co, jeśli będziesz miał "lukę" w indentyfikatorach (bo np. skasujesz jakąś kategorię)?
Nie tak to powinieneś był zrobić. Nie wiem jak pobierasz dane z bazy ale zakładam, że masz jakieś "źródło" i robisz to np. tak: (przykład z kosmosu)
Code:
// pobieranie rekordów z bazy danych Czy jakkolwiek, ale bądź co bądź zasadą jest by stworzyć tablicę wynikową, która zawiera kolejne rekordy numerowane od 0 (a powyższa metoda to gwarantuje).
// ... $categories = array(); while($item = $resource->fetch()) { $categories[] = array( 'id' => $item->id, 'name' => $item->name, 'description' => $item->description ); } |
||
|
4
on: April 05, 2008, 02:27:42 PM
|
||
| Started by kapitan_hak - Last post by kapitan_hak | ||
|
No cóż, troszke nieeleganco to musiałem zrobić(catid - 1), ale działa...
|
||
|
5
on: April 05, 2008, 11:47:01 AM
|
||
| Started by kapitan_hak - Last post by eXtreme | ||
|
Może dlatego, że indeksy tej tablicy zaczynają się od 1?
Sekcja iteruje tablicę zgodnie z automatycznymi indeksami liczonymi od 0. U ciebie indeks kategorii to 1. Zmień na 0 i następnym kategoriom nadawaj kolejne indeksy +1. Nie przypisuj im jakichś własnych ID, np z bazy danych bo nie będzie to działać. |
||
|
6
on: April 05, 2008, 08:30:46 AM
|
||
| Started by kapitan_hak - Last post by kapitan_hak | ||
|
Witam, mam problem z zagnierzdżonymi sekcjami. Otórz gdy uruchmię skrypt który przekazuje do szablonu takie oto tablice(górna to arts, dolna to categories):
Code:
array(1) { [1]=> array(1) { [0]=> array(7) { ["titleen"]=> string(13) "Inglish title" ["titlepl"]=> string(12) "Polsky title" ["contentpl"]=> string(14) "Polsky content" ["contenten"]=> string(15) "inglish content" ["author"]=> string(11) "kapitan_hak" ["date"]=> string(11) "kapitan_hak" ["catid"]=> string(1) "1" } } } array(1) { [1]=> array(2) { ["name"]=> string(12) "inglish nejm" ["description"]=> string(12) "inglish desc" } }
Code:
<?xml version="1.0" ?> To mój błąd? Z góry dzięki za pomoc.
<opt:extend file="index.tpl"> <opt:snippet name="content"> <opt:section name="categories"> <h2>{$categories.name}</h2> <p>{$categories.description}</p> <ul> <opt:section name="arts"> <li>{$arts.author}</li> </opt:section> </ul> </opt:section> </opt:snippet> </opt:extend> |
||
|
7
on: March 26, 2008, 02:12:43 PM
|
||
| Started by wimg - Last post by Zyx | ||
|
Ad. OPT2 -> at this point, I assume that about 80% of the library is completed and the rest will be added soon. But this is only a development version and it was not tested on the real website yet. Once the code is completed, there will be a beta release, then at least one Release Candidate and at last, the final version. I work as quick as possible, because we need this library, too :).
Despite the library, I write the documentation at the same time, but it is a bit delayed. Currently, I write only the Polish version and it will be translated into English later (but still before the final release). But going back to the topic... I've done some research and added compileId to my local code. Moreover, I found a small bug in a rarely used feature :). In the weekend, I'll release OPT 1.1.4 with these updates, because I have to do some necessary tests and update the manual. BTW. I have these files from Zend Framework + OPT connection. My code is not complicated: bootstrap.php
Code:
<?php define('OPT_DIR', BOOT_LOCATION.'library/ext/opt/'); define('OPF_DIR', BOOT_LOCATION.'library/ext/opf/'); define('DIR_TPLCC', BOOT_LOCATION.BOOT_APPNAME.'/data/tpl_compile/'); define('DIR_TPL_CACHE', BOOT_LOCATION.BOOT_APPNAME.'/data/tpl_cache/'); // I include the library manually. require(OPT_DIR.'opt.class.php'); require(OPF_DIR.'opf.class.php'); ... // OPT $view = new My_View; $view -> setScriptPath(NULL); $view -> setI18n($translate); Zend_Registry::set('view', $view); ... ?> My/View.php
Code:
<?php class My_View implements Zend_View_Interface { const ERROR = 0; const INFO = 1; private $_tpl; private $templates; private $renderer = NULL; private $overall = true; private $title; private $navigation = array(); public function __construct() { $config = Zend_Registry::get('config'); $this -> _tpl = new optClass; $this -> _tpl -> compile = DIR_TPLCC; $this -> _tpl -> cache = DIR_TPL_CACHE; $this -> _tpl -> xmlsyntaxMode = true; $this -> _tpl -> gzipCompression = false; $this -> templates = array(); } // end __construct(); public function getEngine() { return $this -> _tpl; } // end getEngine(); public function setScriptPath($name) { if(is_null($name)) { $this -> _tpl -> root = BOOT_LOCATION.BOOT_APPNAME.'/views/'; $this -> _tpl -> compile = DIR_TPLCC; } else { $this -> _tpl -> root = BOOT_LOCATION.BOOT_APPNAME.'/views/'.$name.'/'; $this -> _tpl -> compile = DIR_TPLCC.$name.'/'; } } // end setScriptPath(); public function __set($key, $value) { $this -> _tpl -> assign($key, $value); } // end __set(); public function __get($key) { return $this -> _tpl -> data[$key]; } // end __get(); public function __isset($key) { return isset($this -> _tpl -> data[$key]); } // end __isset(); public function __unset($key) { unset($this -> _tpl -> data[$key]); } // end __unset(); public function assign($name, $value = NULL) { $this -> _tpl -> assign($name, $value); } // end assign(); public function clearVars() { $this -> _tpl -> data = array(); } // end clearVars(); public function render($name) { $this -> templates = array(0 => $name); $session = Zend_Registry::get('session'); $session -> save(); $this -> display(); die(); } // end render(); public function setI18n(ioptI18n $i18n) { $this -> _tpl -> setObjectI18n($i18n); } // end setI18n(); public function addNavigation($name, $address) { $this -> navigation[] = array('name' => $name, 'address' => $address); } // end addNavigation(); public function addPages($pages) { $translate = Zend_Registry::get('translate'); $this -> _tpl -> assign('which', $translate -> putApply('global', 'pageStats', $pages->getActive(), $pages->getSize())); $this -> _tpl -> assign('pages', $pages); } // end addPages(); public function systemPrepare() { $data = Zend_Registry::get('data'); if(!is_null($this -> renderer)) { $renderer = My::loadRenderer($this -> renderer); } else { $renderer = My::loadRenderer($data->domain['hash']); } $renderer -> systemPrepare($this); $this -> renderer = $renderer; } // end systemPrepare(); public function display() { $config = Zend_Registry::get('config'); $data = Zend_Registry::get('data'); $this -> _tpl -> charset = 'utf-8'; if($config -> terenzzia -> debug) { $this -> _tpl -> httpHeaders(OPT_HTML); } else { $this -> _tpl -> httpHeaders(OPT_HTML); } $this -> renderer -> prepare($this); $this -> _tpl -> assign('address', $config -> website -> address); $this -> _tpl -> assign('media', $config -> website -> media); $this -> _tpl -> assign('navigation', $this -> navigation); $this -> _tpl -> assign('title', $this -> title.' - '.$data->domain['title']); $session = Zend_Registry::get('session'); $session -> save(); $this -> _tpl -> setMasterTemplate('master.tpl'); if($this -> overall) { $this -> _tpl -> parse('overall_header.tpl'); } foreach($this -> templates as $tpl) { $this -> _tpl -> parse($tpl); } if($this -> overall) { $this -> _tpl -> parse('overall_footer.tpl'); } } // end display(); public function setTemplate($tpl) { $this -> templates[] = $tpl; } // end setTemplate(); public function setTitle($title) { $this -> title = $title; } // end setTitle(); public function setOverall($overall) { $this -> overall = $overall; } // end setOverall(); public function setRenderer($renderer) { $this -> renderer = $renderer; } // end setRenderer(); public function message($type, $message, $redirect = '') { if($type == Terenzzia_View::ERROR) { $this -> error = true; } else { $this -> error = false; } $this -> message = $message; $this -> redirect = $redirect; $this -> render('message.tpl'); } // end message(); public function question($message, $redirect) { $opf = Zend_Registry::get('opf'); $val = Zend_Registry::get('validator'); if($val -> map('ans', OPF_GET, new opfStandardContainer( new opfConstraint(MAP_TYPE, TYPE_STRING), new opfConstraint(MAP_MATCHTO, '/yes|no/') ))) { if($val -> ans == 'yes') { return true; } return false; } $router = Zend_Registry::get('router'); $this -> message = $message; $redirect['ans'] = 'yes'; $this -> urlYes = $router -> createURL($redirect); $redirect['ans'] = 'no'; $this -> urlNo = $router -> createURL($redirect); $this -> render('question.tpl'); } // end question(); } // end My_View; ?> As you see, all the path-related issues are done in one method: setScriptPath(). Writing your own handler for OPT is not necessary (in fact, the basic thing you have to do is to load the library and create an object), but it helps in some issues. All the paths are defined in bootstrap.php file as constants, so that it's easy to manage them. |
||
|
8
on: March 26, 2008, 12:02:13 PM
|
||
| Started by wimg - Last post by wimg | ||
|
Is OPT2 close to release date ?
The main issue is that we have multiple template directories, but we prefer to have 1 compile and 1 cache directory. since we have multiple index.tpl files, they are compiled under the same name, so they don't overwrite eachother if one file is newer than the other. This is the reason we want to specify a compile_id, so we can differentiate between the different index.tpl files by using an md5 of the directory as compile_id. The memcache implementation is not a priority for us at this point. We use memcache for a range of other things, so we thought it could have been useful, but template caching on disk is fast enough at this point. |
||
|
9
on: March 25, 2008, 07:05:43 PM
|
||
| Started by wimg - Last post by Zyx | ||
|
In OPT 1, the caching is strictly integrated with the parser. In order to write your own handler, you must replace the cacheProcess(), cacheWrite(), isCached() and cacheReset() methods. The description:
- isCached() - it takes the filename and optionally the ID. Its purpose is to check, whether the template is cached. It returns true or false. - cacheProcess() - if the template is cached, it reads its and displays. Otherwise it runs the output buffering. - cacheWrite() - it takes two parameters: the compiled template filename and the information whether the cache has some dynamic parts or not. It captures the parser output and saves it to the file. Beware of the dynamic parts. You have to read the file $this->compile.$compiled.'.dyn' and unserialize its content. It contains all the PHP code for the dynamic parts used by this template. You have to mingle them with the static content. The best idea is to copy the original code and just replace the parts that save everything to disk :). In OPT 2, the output caching is already done as a separate class, so there's no problem to replace it. But the compiled templates are still hardcoded to be stored on the HDD. When it comes to the "compile_id" -> OK, I'll add it. However, in OPT 1, you should have no problem with mixing the compiled and cached templates in one directory, because the library generates quite different names for each type. |
||
|
10
on: March 25, 2008, 03:53:06 AM
|
||
| Started by Przemek - Last post by Przemek | ||
|
Witam ponownie :)
Nie potrzebuję tego jak najszybciej. To w zasadzie taki pomysł na przyszłość. Dostosowałem sobie OPD do moich potrzeb, jednak modyfikowanie takich "gotowych" biblotek czasem może wyjść bokiem i dlatego zaproponowałem taką możliwość. Mam w sumie jeszcze dwie małe zagwostki powiązane ze sobą, które jeśli uznasz za stosowne może znajdą rozwiązanie w przyszłości. Pierwsza to tworzenie pustych plików cache dla zapytań, które nie zwróciły wyników. To jest jak najbardziej poprawne, jednak moim zdaniem użyteczna były by flaga/parametr, która wyłącza zapis takiego pustego kesza na to jedno najbliższe zapytanie. Druga to brak możliwości określenia różnych katalogów dla plików z keszem. Obie te kwiestie wyszły na świat przy testach obciążenia aplikacji. Gdzie najbardziej po garach dostawała macierz. Do tego spadała szybkość odczytu z dysków powyżej 20k plików keszy w jednym katalogu przy systemie plików EXT3. Jeśli mijam się z aktualnym stanem, to przepraszam ponieważ dość dawno temu przeglądałem OPD. Pozdrawiam. -- Przemysław Kmiecik |
||