Po krótkce opisze o co chodzi w Sitemap. Mapa strony jest generowana z bazy danych, tak samo jak główne menu. Dlatego nie przeszktałcałam zbytnio tego. Póki miałam zwykły kontroler który nie dziedziczy części wyglądu strony po kontrolerze template było wszytko ok. I mapa się generowała. A teraz gdy postanowiłam dodać template i tam wrzucić powtarzające się rzeczy, wtedy już mi błąd wywala.

Nie wiem skąd się bierze ten błąd, wg. mnie robię wszytko poprawnie.. No ale cóż widocznie nie do końca. sad.gif

wywala mi taki błąd: /application/controllers/sitemap.php [20]: Attempt to assign property of non-object.

adres strony:amehobpoezja.pl
adres gdzie jest błąd:amehobpoezja.pl/sitemap

views/sitemap.php
  1. <?foreach($menu as $item):?>
  2. <ul>
  3. <li> <a href="<?=url::base()?>arty/pokaz/<?=$item->id_kat?>/<?=$item->nazwa?>"><?=$item->nazwa?></a>
  4. <?$podmenu = Menu::pobierzPodMenu($item->id_kat)?>
  5. <?if( $podmenu->count() > 0 ):?>
  6. <ul>
  7. <?foreach( $podmenu as $subitem):?>
  8. <li><a href="<?=url::base()?>arty/pokaz/<?=$subitem->id_kat?>/<?=$subitem->nazwa?>"><?=$subitem->nazwa?></a></li>
  9. <?endforeach?>
  10. </ul>
  11. <?endif?>
  12. </li>
  13. </ul>
  14. <?endforeach?>
  15.  


controllers/sitemap.php
  1. <?php defined('SYSPATH') OR die('No direct access allowed.');
  2.  
  3. class Sitemap_Controller extends Template_Controller
  4. {
  5. function __construct() {
  6. parent::__construct();
  7. }
  8.  
  9. public $menu = array();
  10. public function pokaz() {
  11.  
  12. $this->body->menu_boczne = new View('box/menu_boczne_bez_kat');
  13. $this->body->glowny_box = new View('sitemap');
  14. $this->body->glowny_box->sitemap = $this->menu;
  15. $this->body->glowny_box->sitemap->menu = Menu::pobierzMenu();
  16. }
  17. }
  18. ?>

a tutaj controllers/template.php

  1.  
  2. <?php defined('SYSPATH') OR die('No direct access allowed.');
  3.  
  4. abstract class Template_Controller extends Controller {
  5.  
  6. public $template = 'main';
  7. public $auto_render = TRUE;
  8. public $session;
  9. public $css = array();
  10. public $js = array();
  11. public $title = '';
  12. public $keywords = '';
  13. public $description = '';
  14. public $kod;
  15. public $body;
  16. public $menu = array();
  17. public $footer;
  18.  
  19. public function __construct()
  20. {
  21. parent::__construct();
  22.  
  23. $this->session = Session::instance();
  24. $this->css = array( url::base().'css/glowny_div.css',
  25. url::base().'css/menu_boczne.css',
  26. url::base().'css/menu_srodkowe.css',
  27. url::base().'css/sitemap.css',
  28. url::base().'css/style.css',
  29. url::base().'css/social_icons.css');
  30.  
  31. $this->js = array( url::base().'js/ddaccordion.js',
  32. url::base().'js/dddropdownpanel.js',
  33. url::base().'js/jquery-1.3.2.min.js',
  34. url::base().'js/jquery.validate.js',
  35. url::base().'js/menu_srodkowe.js');
  36.  
  37. $this->title = 'amehobpoezja';
  38. $this->keywords = 'amehob, poezja, wiersze, ksiązki, liryka, białe';
  39. $this->description = 'amehobpoezja.pl - Portal poświęcony poezji';
  40. $this->kod = new Captcha();
  41. $this->template = new View($this->template);
  42. $this->body = new View('body');
  43. $this->header = new View('header');
  44. $this->menu_glowne = new View('menu/glowne');
  45. $this->footer = new View('stopka');
  46.  
  47. if ($this->auto_render == TRUE)
  48. {Event::add('system.post_controller', array($this, '_render'));}}
  49.  
  50. public function _render()
  51. {if ($this->auto_render == TRUE)
  52. {$this->template->title = stripslashes(str_replace('"',"'",$this->title));
  53. $this->template->keywords = $this->keywords;
  54. $this->template->description = $this->description;
  55. $this->template->css = $this->css;
  56. $this->template->java = $this->js;
  57. $this->template->body = $this->body;
  58. $this->template->body->header = $this->header;
  59. $this->template->body->header->menu_glowne = $this->menu_glowne;
  60. $this->template->body->header->menu_glowne->menu = $this->menu;
  61. $this->template->body->header->menu_glowne->menu = Menu::pobierzMenu();
  62. $this->template->body->footer = $this->footer;
  63. $this->template->render(TRUE);}}}


już znaleziona została odpowiedź.

  1. $this->body
  2. ->set('menu_boczne', View::factory('box/menu_boczne_bez_kat'))
  3. ->bind('glowny_box', $sitemap);
  4.  
  5. $sitemap = View::factory('sitemap')
  6. ->set('menu', Menu::pobierzMenu());
  7.  
  8. //to to samo co:
  9. //$this->body->menu_boczne = new View('box/menu_boczne_bez_kat');
  10. //$this->body->glowny_box = new View('sitemap');
  11. //$this->body->glowny_box->menu = Menu::pobierzMenu();



obie odpowiedzi są poprawne smile.gif

temat do zamknięcia smile.gif