Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Dodanie nowego widoku do aplikacji.
Forum PHP.pl > Forum > Przedszkole
cykcykacz
Witam,
dostałem aplikację, w której nie wiem dlaczego ale nie widzi nowej dodanej akcji/widoku.
Dostaję taki komunikat "Action Helper by name xxxxxAction not found"
Pewnie chodzi o ścieżki route, ale nie wiem gdzie są zdefiniowane.
Plik index.php
  1. <?php
  2. define(ROOT_PATH, realpath(dirname(__FILE__) . '/..'));
  3.  
  4.  
  5. . PATH_SEPARATOR . ROOT_PATH . '/library'
  6. . PATH_SEPARATOR . ROOT_PATH . '/application/default/models/'
  7. );
  8.  
  9. require_once 'Zend/Loader/Autoloader.php';
  10.  
  11. $autoloader = Zend_Loader_Autoloader::getInstance();
  12. $autoloader->setFallbackAutoloader(true);
  13.  
  14. try {
  15. ini_set('memory_limit', '128M');
  16.  
  17. $frontend = array('master_file' => ROOT_PATH . '/config/route.ini', 'automatic_serialization' => true);
  18. $backend = array('cache_dir' => ROOT_PATH . '/temporary/cache/config');
  19. $cache = Zend_Cache::factory('File', 'File', $frontend, $backend);
  20.  
  21. if (!$config = $cache->load('route')) {
  22. $config = new Zend_Config_Ini(ROOT_PATH . '/config/route.ini', 'routes');
  23. $cache->save($config, 'route');
  24. }
  25.  
  26.  
  27. require_once 'Core/Controller/Plugin/Cache.php';
  28.  
  29. $router = new Core_Controller_Router_Rewrite();
  30. $router->addConfig($config, 'route');
  31.  
  32.  
  33. $fc = Zend_Controller_Front::getInstance();
  34. $fc->throwExceptions(true);
  35. $fc->setParam('noViewRenderer', true);
  36. $fc->setRouter($router);
  37. $fc->addModuleDirectory(ROOT_PATH . '/application');
  38. $fc->registerPlugin(new Core_Controller_Plugin_Locale());
  39. $fc->registerPlugin(new Core_Controller_Plugin_Runtime());
  40. $fc->registerPlugin(new Core_Controller_Plugin_Acl());
  41. $fc->registerPlugin(new Core_Controller_Plugin_Layout());
  42. $fc->dispatch();
  43. } catch (Exception $e) {
  44. echo $e->getMessage();
  45. }


route.ini
Kod
; ================= trasy statyczne ============================================
route.error403.type                = "Zend_Controller_Router_Route_Static"
route.error403.route               = "nie_masz_dostepu"
route.error403.defaults.module     = default
route.error403.defaults.controller = error
route.error403.defaults.action     = display
route.error403.defaults.code       = 403


Jeszcze są dwa takie pliczki:
rewrite.php
  1. final class Core_Controller_Router_Rewrite extends Zend_Controller_Router_Rewrite
  2. {
  3.  
  4. public function addDefaultRoutes()
  5. {
  6. if (!$this->hasRoute('default')) {
  7.  
  8. $dispatcher = $this->getFrontController()->getDispatcher();
  9. $request = $this->getFrontController()->getRequest();
  10.  
  11. $compat = new Core_Controller_Router_Route_Module(array(), $dispatcher, $request);
  12.  
  13. $this->_routes = array_merge(array('default' => $compat), $this->_routes);
  14. }
  15. }
  16. }

rote.php
  1. final class Core_Controller_Router_Route_Module extends Zend_Controller_Router_Route_Module
  2. {
  3.  
  4. protected $_languageKey = 'language';
  5.  
  6.  
  7. public function match($path)
  8. {
  9. $this->_setRequestKeys();
  10.  
  11. $values = array();
  12. $params = array();
  13. $path = trim($path, self::URI_DELIMITER);
  14.  
  15. if ($path != '') {
  16. $path = explode(self::URI_DELIMITER, $path);
  17.  
  18. if (ereg('^([a-z]{2})$', $path[0])) {
  19. $params[$this->_languageKey] = array_shift($path);
  20. }
  21.  
  22. if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
  23. $values[$this->_moduleKey] = array_shift($path);
  24. $this->_moduleValid = true;
  25. }
  26.  
  27. if (count($path) && !empty($path[0])) {
  28. $values[$this->_controllerKey] = array_shift($path);
  29. }
  30.  
  31. if (count($path) && !empty($path[0])) {
  32. $values[$this->_actionKey] = array_shift($path);
  33. }
  34.  
  35. if ($numSegs = count($path)) {
  36. for ($i = 0; $i < $numSegs; $i = $i + 2) {
  37. $key = urldecode($path[$i]);
  38. $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
  39. $params[$key] = $val;
  40. }
  41. }
  42. }
  43.  
  44. $this->_values = $values + $params;
  45.  
  46. return $this->_values + $this->_defaults;
  47. }
  48.  
  49. public function assemble($data = array(), $reset = false, $encode = false)
  50. {
  51. if (!$this->_keysSet) {
  52. $this->_setRequestKeys();
  53. }
  54.  
  55. $params = (!$reset) ? $this->_values : array();
  56.  
  57. foreach ($data as $key => $value) {
  58. if ($value !== null) {
  59. $params[$key] = $value;
  60. } elseif (isset($params[$key])) {
  61. unset($params[$key]);
  62. }
  63. }
  64.  
  65. $params += $this->_defaults;
  66.  
  67. $url = '';
  68.  
  69. $lang = $params[$this->_languageKey];
  70. unset($params[$this->_languageKey]);
  71.  
  72. if ($this->_moduleValid || array_key_exists($this->_moduleKey, $data)) {
  73. if ($params[$this->_moduleKey] != $this->_defaults[$this->_moduleKey]) {
  74. $module = $params[$this->_moduleKey];
  75. }
  76. }
  77. unset($params[$this->_moduleKey]);
  78.  
  79. $controller = $params[$this->_controllerKey];
  80. unset($params[$this->_controllerKey]);
  81.  
  82. $action = $params[$this->_actionKey];
  83. unset($params[$this->_actionKey]);
  84.  
  85. foreach ($params as $key => $value) {
  86. $url .= '/' . $key;
  87. $url .= '/' . $value;
  88. }
  89.  
  90. if (!empty($url) || $action !== $this->_defaults[$this->_actionKey]) {
  91. $url = '/' . $action . $url;
  92. }
  93.  
  94. if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) {
  95. $url = '/' . $controller . $url;
  96. }
  97.  
  98. if (isset($module)) {
  99. $url = '/' . $module . $url;
  100. }
  101.  
  102. if (isset($lang)) {
  103. $url = '/' . $lang . $url;
  104. }
  105.  
  106. return ltrim($url, self::URI_DELIMITER);
  107. }
melkorm
  1. $fc->setParam('noViewRenderer', true);


Możliwe że to jest powodem, spróbuj w akcji na końcu dać
  1. $this->render('nazwa_szablonu');


zresztą:
  1. Action Helper by name xxxxxAction not found


Nie odnosi się do widoku tylko do helpera widoku.

Może pokaż kod Twojej akcji i jakiejś przykładowej z aplikacji?
cykcykacz
Rejestracjacontroler.php
  1. final class RejestracjaController extends Core_Controller_Action
  2. {
  3. /**
  4.   * Rejestracja
  5.   */
  6. public function indexAction()
  7. {
  8. $this->render();
  9. }
  10.  
  11. /**
  12.   * Przypomnienie
  13.   */
  14. public function przypomnienieAction()
  15. {
  16. $this->render();
  17. }
  18.  
  19. /**
  20.   * ANkieter
  21.   */
  22. public function ankieterAction()
  23. {
  24. $this->render();
  25. }
  26.  
  27. /**
  28.   * Potwierdzenie rejestracji
  29.   */
  30. public function potwierdzAction()
  31. {
  32. $filter = new Zend_Filter();
  33. $filter->addFilter(new Zend_Filter_StripTags());
  34.  
  35. $kod = $filter->filter($this->_getParam('kod'));
  36.  
  37. $userTable = new User();
  38.  
  39. $kod = $userTable->getList('code', $kod, false, 1, 1);
  40.  
  41. if ($kod[0] !== null) {
  42. $user['use_password_change'] = '';
  43. $user['use_password'] = $kod[0]['use_password_change'];
  44. $user['use_code'] = '';
  45. $where = $userTable->getAdapter()->quoteInto('use_id = ?', $kod[0]['use_id']);
  46. $userTable->update($user, $where);
  47.  
  48. $this->view->komunikat = 'Hasło zostało zmienione';
  49. } else {
  50. $this->view->komunikat = 'Podany kod jest nieprawidłowy';
  51. }
  52.  
  53. $this->render();
  54. }
  55.  
  56. /**
  57.   * Sprawdzenie czy nazwa taka juz wystepuje
  58.   */
  59. public function sprawdzAction()
  60. {
  61. $filter = new Zend_Filter();
  62. $filter->addFilter(new Zend_Filter_StripTags());
  63.  
  64. $nazwa = $filter->filter($_POST['nazwa']);
  65.  
  66. $user = new User();
  67. $count = $user->count('name', $nazwa, false);
  68.  
  69. $kom = (($count == 0) ? 'ok' : '');
  70. echo $kom;
  71. }
  72.  
  73. /**
  74.   * Zapisanie konta
  75.   */
  76. public function zapiszAction()
  77. {
  78. $filter = new Zend_Filter();
  79. $filter->addFilter(new Zend_Filter_StripTags());
  80.  
  81. $nazwa = $filter->filter($_POST['nazwa']);
  82. $email = $filter->filter($_POST['email']);
  83. $ip = $filter->filter($_SERVER['REMOTE_ADDR']);
  84. $typ = $filter->filter($_POST['typ']);
  85. $haslo = $filter->filter($_POST['haslo']);
  86. $wiek = $filter->filter($_POST['wiek']);
  87. $plec = $filter->filter($_POST['plec']);
  88. $wyksztalcenie = $filter->filter($_POST['wyksztalcenie']);
  89. $region = $filter->filter($_POST['region']);
  90. $miasto = $filter->filter($_POST['miasto']);
  91. $branza = $filter->filter($_POST['branza']);
  92.  
  93. $table = new User();
  94. $user['use_name'] = $nazwa;
  95. $user['use_password'] = md5($haslo);
  96. $user['use_email'] = $email;
  97. $user['use_ip'] = $ip;
  98. $user['use_type'] = $typ;
  99. $user['use_account'] = 'enable';
  100. $user['use_date_registered'] = time();
  101.  
  102. if ($typ == 'a') {
  103. $user['use_wiek'] = $wiek;
  104. $user['use_plec'] = $plec;
  105. $user['use_wyksztalcenie'] = $wyksztalcenie;
  106. $user['use_region'] = $region;
  107. $user['use_miasto'] = $miasto;
  108. $user['use_branza'] = $branza;
  109. }
  110. $table->insert($user);
  111.  
  112. $smtpServer = 'mail.ankieter.pl';
  113. $username = 'biuro@ankieter.pl';
  114. $password = 'ankiet321';
  115.  
  116.  
  117. $config = array('ssl' => 'tls',
  118. 'port' => '587',
  119. 'auth' => 'login',
  120. 'username' => $username,
  121. 'password' => $password);
  122.  
  123. $transport = new Zend_Mail_Transport_Smtp($smtpServer, $config);
  124.  
  125. $tresc = $nazwa.', dziękujemy za zarejestrowanie się w naszym portalu.'."\r\n";
  126. $tresc .= ''."\r\n";
  127. $tresc .= 'Zapamiętaj swoje dane: '."\r\n";
  128. $tresc .= 'login: '.$nazwa."\r\n";
  129. $tresc .= 'hasło: '.$haslo."\r\n";
  130. $tresc .= ''."\r\n";
  131. $tresc .= 'Pamiętaj o Płatnościach. W przeciwnym razie Twoja ankieta zostanie usunięta po 3 dniach. Link do płatności: <a href="http://www.ankieter.pl/strona/pokaz/guid/platnosci/'.&quot;\r\n&quot;;" target="_blank">http://www.ankieter.pl/strona/pokaz/guid/p...r\n";</a>
  132.  
  133. $mail = new Zend_Mail('iso-8859-2');
  134. $mail->setFrom('biuro@ankieter.pl', 'Ankieter.pl');
  135. $mail->addTo($email, 'Server');
  136. $mail->setSubject('Portalu Ankieter.pl');
  137. $mail->setBodyText($tresc);
  138. $mail->send($transport);
  139.  
  140. $auth = Zend_Auth::getInstance();
  141. $adapter = new Core_Auth_Standard($nazwa, md5($haslo));
  142. $result = $auth->authenticate($adapter);
  143. $messages = $result->getMessages();
  144.  
  145. $status = $messages[0];
  146.  
  147. if ($status == 'Pomyślna autoryzacja') {
  148. $user = $auth->getIdentity();
  149.  
  150. // autologowanie
  151. setcookie('kautologin_name', $nazwa, time() + 7776000, '/');
  152. setcookie('kautologin_pass', $haslo, time() + 7776000, '/');
  153. }
  154.  
  155. if ($user = $this->authentication()) {
  156. if (is_object($user)) {
  157. return true;
  158. } else {
  159. return $user;
  160. }
  161. }
  162. }
  163.  
  164. /**
  165. * Wyslanie nowego hasla
  166. */
  167. public function nowehasloAction()
  168. {
  169. $filter = new Zend_Filter();
  170. $filter->addFilter(new Zend_Filter_StripTags());
  171.  
  172. $email = $filter->filter($_POST['email']);
  173. $haslo = $filter->filter($_POST['haslo']);
  174.  
  175. $userTable = new User();
  176.  
  177. $is_user = $userTable->getList('email', $email, false, 1, 1);
  178.  
  179. if ($is_user->current() !== null) {
  180. $user['use_password_change'] = md5($haslo);
  181. $user['use_code'] = substr(md5(md5($haslo)), 2, 10);
  182. $where = $userTable->getAdapter()->quoteInto('use_id = ?', $is_user[0]['use_id']);
  183. $userTable->update($user, $where);
  184.  
  185. $smtpServer = 'mail.ankieter.pl';
  186. $username = 'biuro@ankieter.pl';
  187. $password = 'ankiet321';
  188.  
  189.  
  190. $config = array('ssl' => 'tls',
  191. 'port' => '587',
  192. 'auth' => 'login',
  193. 'username' => $username,
  194. 'password' => $password);
  195.  
  196. $transport = new Zend_Mail_Transport_Smtp($smtpServer, $config);
  197.  
  198. $tresc = 'Witamy' . "<br><br>";
  199. $tresc .= 'Twój login: ' . $is_user->current()->use_name . "<br><br>";
  200. $tresc .= 'Aby aktywować nowe hasło kliknij w link: ';
  201. $tresc .= "<a href=\"http://". $_SERVER['SERVER_NAME'] . "/rejestracja/potwierdz/kod/" . $user['use_code'] . "\">";
  202. $tresc .= 'http://' . $_SERVER['SERVER_NAME'] . '/rejestracja/potwierdz/kod/' . $user['use_code'] . '</a>';
  203. $tresc .= "<br><br>";
  204. $tresc .= 'Zespół Ankieter.pl';
  205.  
  206. $mail = new Zend_Mail('iso-8859-2');
  207. $mail->setFrom('biuro@ankieter.pl', 'Ankieter.pl');
  208. $mail->addTo($email, 'Server');
  209. $mail->setSubject('Potwierdzenie zmiany hasła w portalu Ankieter.pl');
  210. $mail->setBodyHtml($tresc);
  211. $mail->send($transport);
  212.  
  213. $this->getResponse()->setBody('Nowe hasło zostało wysłane na podany e-mail, proszę odebrać poczte');
  214. } else {
  215. $this->getResponse()->setBody('Podany e-mail nie jest zapisany w naszej bazie');
  216. }
  217. }
  218. }


w katalogu z widokami sa 4 pliki:
Kod
ankieter.phtml
index.phtml
potwierdz.phtml
przypomnienie.phtml
melkorm
Przez tą opcję co poprzednio pokazałem musisz wykonać zawsze
  1. $this->redner();


Bo ta opcja wyłącza automatyczny rendering widoków, nazwa widoku = nazwa akcji czyli
akcja : indexAction
widok index.phtml (defaultowo jest .phtml)

Jeżeli chcesz inny skrypt niż nazwa akcji musisz przekazać jako parametr nazwę tak jak to pisałem w poprzednim poście.

  1. $this->getResponse()->setBody()


A to po prostu ustawia ciało contentu, tzn nadpisuje wink.gif

Sumując Twoja akcja musi wyglądać mniejwięcej tak:
  1. public function indexAction()
  2. {
  3. $this->render();
  4. }


Gdzie nazwa widoku to index.phtml w odpowiednim folderze, defaultowo:
Kod
views/scripts/nazwa_kontrolera/nazwa_widoku.phtml



PS.
To co wkleiłeś nie ma za wiele wspólnego z poprawnie napisaną aplikacją w ZF, szczególnie to echo w akcjach biggrin.gif
PS2.
Jeżeli nadal nie będzie działać to wklej strukturę katalogów + jak próbowałeś na pewno znajdziemy rozwiązanie.
cykcykacz
Mój błąd:
  1. public function platnosci()
  2. {
  3.  
  4.  
  5. $this->render();
  6.  
  7. }


Zapomniałem "Action"
Zamiast:
  1. public function platnosciAction()
  2. {
  3.  
  4.  
  5. $this->render();
  6.  
  7. }


Taka mała rzecz a sprawiła mi tyle kłopotu, żeby dojść do tego.

Wielkie dzięki melkorm za zainteresowanie.

Ps: Cały czas staram się zgłębiać Zenda i w nim robić strony.

Pozdrawiam.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.