Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZF] błąd na stronie - controller się wykonule ale wywala błąd
krzyszbi
post 31.05.2007, 15:18:17
Post #1





Grupa: Zarejestrowani
Postów: 251
Pomógł: 13
Dołączył: 15.09.2005

Ostrzeżenie: (0%)
-----


wietam
jako ze juz teoretycznie mamy wersje 1.0 choć co prawda jeszcze nie stabilna ale już coś więc pisze bo natrafiłem na jak dla mnie dziwny problem i nie mogę sobie z nim poradzić
a mianowicie mam plik bootstrap taki
  1. <?php
  2. function getmicrotime() { list($usec, $sec) = explode(' ',microtime()); return ((float)$usec + (float)$sec); }
  3. $time_start = getmicrotime();
  4. ini_set ('include_path', './lib/');
  5. define('LOCATION', 'http://localhost/');
  6. require_once './lib/Zend/Loader.php';
  7. Zend_Loader::loadClass('Zend_Controller_Front');
  8. Zend_Loader::loadClass('Zend_Db');
  9. Zend_Loader::loadClass('Zend_Registry');
  10. Zend_Loader::loadClass('Zend_Session');
  11. Zend_Loader::loadClass('Zend_Auth');
  12. Zend_Session::start();
  13. define('OPT_DIR', './lib/others/opt/');
  14. require(OPT_DIR.'opt.class.php');
  15. Zend_Registry::set('db', Zend_Db::factory('PDO_Mysql', array ('host'=>'localhost','username'=>'user','password'=>'*****','dbname'=>'baza')));
  16. Zend_Registry::set('tpl', new optClass);
  17. Zend_Loader::loadClass('Zend_Cache');
  18. Zend_Registry::set('cache', Zend_Cache::factory('Core', 'File',array('lifeTime' => 86400,'automaticSerialization' => true), array('cacheDir' => './cache/')));
  19. $controller = Zend_Controller_Front::getInstance();
  20. $controller -> throwExceptions(true);
  21. $controller -> run(
  22. 'default'  => './app/default/controllers/',
  23. 'admin'  => './app/admin/controllers',
  24. 'Admin'  => './app/admin/controllers'
  25. ));
  26. $time_end = getmicrotime();
  27. $time = round($time_end - $time_start, 4);
  28. echo '<!--Skrypt wykonany w czasie: '.$time.' sekundy-->';
  29. ?>

taki sam pliki pod ZF 0.93B ładnie działa i nic nie wyrzuca
indexcontroller
  1. <?php
  2. class IndexController extends Zend_Controller_Action{
  3. private $db;
  4. private $tpl;
  5. public function init(){
  6. $this -> db = Zend_Registry::get('db');
  7. $this -> tpl = Zend_Registry::get('tpl');
  8. $this -> tpl -> root = './templates/templates/';
  9. $this -> tpl -> compile = './templates/templates_c/';
  10. $this -> tpl -> assign('location', LOCATION);
  11. }
  12. public function indexAction(){
  13. $this->start();
  14. }
  15. private function Start(){
  16. $auth = Zend_Auth::getInstance();
  17. //echo'<pre>'.print_r($auth->getIdentity(),1).'</pre>';
  18. $this -> tpl -> assign('user', $auth->getIdentity() -> username);
  19. $this -> tpl -> parse('index.tpl');
  20. }
  21. public function noRouteAction(){
  22. $this->_redirect('/');
  23. }
  24. private function assign($data, $tamplate,$patch){
  25. $this -> tpl -> root = './templates/templates/'.$patch;
  26. $this -> tpl -> compile = './templates/templates_c/'.$patch;
  27. $this -> tpl -> trace = 1;
  28. foreach($data as $key=>$val){
  29. $this -> tpl -> assign($key, (!empty($val) ? $val : 'NULL'));
  30. }
  31. $this -> tpl -> assign('location', LOCATION);
  32. return $this -> tpl -> fetch($tamplate);
  33. }
  34. }
  35. ?>

no i teraz nie wiem czemu pod pokazaną stroną mam wyrzucony wyjątek ( $controller -> throwExceptions(true); ) o takiej treści
Kod
Fatal error: Uncaught exception 'Zend_View_Exception' with message 'script 'index/index.phtml' not found in path' in D:\serwer\www\lib\Zend\View\Abstract.php:853 Stack trace: #0 D:\serwer\www\lib\Zend\View\Abstract.php(764): Zend_View_Abstract->_script('index/index.pht...') #1 D:\serwer\www\lib\Zend\Controller\Action\Helper\ViewRenderer.php(702): Zend_View_Abstract->render('index/index.pht...') #2 D:\serwer\www\lib\Zend\Controller\Action\Helper\ViewRenderer.php(723): Zend_Controller_Action_Helper_ViewRenderer->renderScript('index/index.pht...', NULL) #3 D:\serwer\www\lib\Zend\Controller\Action\Helper\ViewRenderer.php(770): Zend_Controller_Action_Helper_ViewRenderer->render() #4 D:\serwer\www\lib\Zend\Controller\Action\HelperBroker.php(160): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() #5 D:\serwer\www\lib\Zend\Controller\Action.php(504): Zend_Controller_Action_HelperBroker->notifyPostDispatch() #6 D:\serwer\www\lib\Zend\Controller\Dispatcher\Standard.php(230): Zend_Con in D:\serwer\www\lib\Zend\View\Abstract.php on line 853

wiem wyjątki sobie wyrzucam ale on o tak się nie powinien pojawić Zend_View nie używam nie podoba mi się wole OPT tak samo z helperami nie ładuje nie używam zadnego bo to jest postawione specjalnie do testów
jeśli będzie throwExceptions(false) to dostaje taki błąd
Kod
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)' in D:\serwer\www\lib\Zend\Controller\Dispatcher\Standard.php:189 Stack trace: #0 D:\serwer\www\lib\Zend\Controller\Front.php(889): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 D:\serwer\www\lib\Zend\Controller\Front.php(229): Zend_Controller_Front->dispatch() #2 D:\serwer\www\index.php(27): Zend_Controller_Front::run(Array) #3 {main} thrown in D:\serwer\www\lib\Zend\Controller\Dispatcher\Standard.php on line 189

choć strona się wygeneruje to ja i tak pod spodem dostaje jak nie jested to drugi komunikat i juz nie wiem poprostu zgłupiałem szukałem dziś cały dzień co jest ale się nie doszukałem sad.gif
może ktoś już doszedł co jest nie tak tutaj questionmark.gif
jesli tak to bedzie wdzięczny za podzielenie sie rozwiązaniem sugestią co robie źle


--------------------
Everything should be made as simple as possible, but not simpler. - A.Eainstein
Go to the top of the page
+Quote Post
wolditm
post 31.05.2007, 17:02:49
Post #2





Grupa: Zarejestrowani
Postów: 31
Pomógł: 2
Dołączył: 20.07.2005

Ostrzeżenie: (0%)
-----


Ostatnio miałem podobny problem, sam tez używam OPT, dlatego zrób tak:
Kod
$controller -> throwExceptions(true)->setParam( 'noViewRenderer', true );

w wersji 1.0.0rc1 dodali nowy helper który automatycznie ładuje Zend_View; wiecej w manualu

Ten post edytował wolditm 31.05.2007, 17:06:59


--------------------
Wspomnienia
Go to the top of the page
+Quote Post
ARJ
post 31.05.2007, 20:51:17
Post #3





Grupa: Zarejestrowani
Postów: 453
Pomógł: 22
Dołączył: 20.09.2004
Skąd: Kraków - NH -

Ostrzeżenie: (0%)
-----


tak przy okazji bo widzę, że używasz ZF z OPT więc zarzucę swoim rozwiązaniem, może komuś się przyda.
  1. <?php
  2. define('OPT_DIR', 'OPT/');
  3. require_once('Zend/View/Interface.php');
  4. require_once('OPT/opt.class.php');
  5.  
  6. class Application_OPT implements Zend_View_Interface {
  7.  
  8. protected $_OPT;
  9.  
  10. public function __construct($tmplPatch = null, $params = array()){
  11. $this->_OPT = new optClass();
  12. if($tmplPatch !== null){
  13. $this->setScriptPatch($tmplPatch);
  14. }
  15.  
  16. foreach($params as $key => $value){
  17. $this->_OPT->$key = $value;
  18. }
  19. }
  20.  
  21. public function getEngine(){
  22. return $this->_OPT;
  23. }
  24.  
  25. public function setScriptPath($path){
  26. if (is_readable($path)) {
  27. $this->_OPT->root = $path;
  28. return;
  29. }
  30. }
  31.  
  32. public function __set($key, $value){
  33. $this->_OPT->assign($key,$value);
  34. }
  35.  
  36. public function __get($key){
  37. return $this->_OPT->data[$key];
  38. }
  39.  
  40. public function __isset($key){
  41. return array_key_exists($key, $this->_OPT->data);
  42. }
  43.  
  44. public function __unset($key){
  45. unset($this->_OPT->data[$key]);
  46. }
  47.  
  48. public function assign($spec, $value = null)
  49. {
  50. if (is_array($spec)) {
  51. $this->_OPT->assign($spec);
  52. return;
  53. }
  54.  
  55. $this->_OPT->assign($spec, $value);
  56. }
  57.  
  58. public function clearVars(){
  59. foreach($this->_OPT->data as $key => $value){
  60. unset($this->_OPT->data[$key]);
  61. }
  62. }
  63.  
  64. public function render($name){
  65. $this->_OPT->parse($name);
  66. }
  67.  
  68. public function setDefaultI18n($lang){
  69. $this->_OPT->setDefaultI18n($lang);
  70. }
  71.  
  72. public function setCustomI18n($lbp, $obj, $name){
  73. $this->_OPT->setCustomI18n($lbp, $obj, $name);
  74. }
  75. }
  76. ?>

kod należy wrzucić do pliku application/OPT.php, a samą bibliotekę opt do library/opt.
przykładowe użycie:
  1. <?php
  2. $view = new Application_OPT(null, array('compile'=>'cache/'));
  3. $view->setScriptPath('./templates/'.$config->template.'/');
  4. $view->title = $config->title;
  5. ?>

testowane pod zf 0.9.0


--------------------
Warsztat: Windows 7 Pro 64bit | Apache 2.2 | PHP 5.2 | MySQL 5.0 | PHPmyadmin 2.6.4
Go to the top of the page
+Quote Post
fridek
post 31.05.2007, 23:55:14
Post #4





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 19.12.2006

Ostrzeżenie: (0%)
-----


Cytat(wolditm @ 31.05.2007, 18:02:49 ) *
Ostatnio miałem podobny problem, sam tez używam OPT, dlatego zrób tak:
Kod
$controller -> throwExceptions(true)->setParam( 'noViewRenderer', true );

w wersji 1.0.0rc1 dodali nowy helper który automatycznie ładuje Zend_View; wiecej w manualu



Nawiasem mówiąc samo:
Kod
$controller->setParam( 'noViewRenderer', true );

w zupełności wystarcza. Wręcz odradzałbym zostawianie throwExceptions(true) po zakończeniu projektu, w końcu ta funkcja została stworzona do debugowania.
Moim zdaniem pomysł z domyślnym view jest zupełnie chybiony - przecież większość osób korzysta z jakiegoś systemu szablonów, a to rozwiązanie tylko to utrudnia.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.07.2025 - 01:06