Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Definiowanie składowej poprzez objekt klasy
Raven1122
post
Post #1





Grupa: Zarejestrowani
Postów: 369
Pomógł: 2
Dołączył: 1.11.2010

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


Witam,

Mam pytanie, jak przekazać do klasy View składową, np.:

$this->view->title = 'Strona główna';

, a potem

wykorzystać tą składową w klasie View, np.:

echo $this->title;


Kawałki mojego kodu:

Klasa View

  1. <?php
  2.  
  3. class View {
  4.  
  5. function __construct() {
  6.  
  7. }
  8.  
  9. public function render($name){
  10. require BASE_URL.'views\\'.$name.'.php';
  11. }
  12.  
  13. }


Klasa nadrzędna kontrolera(każdy kontroler ją przedłuża):
  1. <?php
  2.  
  3.  
  4. class Controller {
  5.  
  6. function __construct() {
  7. $this->view = new View();
  8. }
  9.  
  10. }


i kontroller np. strony głównej

  1. <?php
  2.  
  3. class Index extends Controller{
  4.  
  5. function __construct() {
  6. parent::__construct();
  7. }
  8.  
  9. function index(){
  10. $this->view->render('index\index');
  11. $this->view->title = 'Strona główna';
  12. }
  13.  
  14. }
  15.  
  16. ?>


No i View strony głównej:
  1. <?php
  2.  
  3. require 'public/templates/header.php';
  4. ?>
  5. <hr />
  6. <?php
  7. echo $this->title;
  8. ?>
  9. <hr />
  10. <?php
  11. require 'public/templates/footer.php';
  12. ?>
  13.  


Po uruchomieniu strony głównej uzyskuje:

Notice: Undefined property: View::$title in D:\wamp\www\MVC\views\index\index.php on line 7

Proszę o pomoc (IMG:style_emoticons/default/smile.gif)
Z góry dziękuje.

Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 26.09.2025 - 00:57