Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> MVC jak to ugryźć
Gibcio2008
post 21.01.2019, 20:35:43
Post #1





Grupa: Zarejestrowani
Postów: 54
Pomógł: 0
Dołączył: 26.10.2008

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


Na początek pokażę pliki

index.php
  1. <?php
  2. require_once "Controller.php";
  3. require_once "Loader.php";
  4.  
  5. $Controller = new Controller();
  6. ?>


Controller.php

  1. <?php
  2. class Controller
  3. {
  4. public static $instance;
  5.  
  6. function __construct()
  7. {
  8. self::$instance = $this;
  9.  
  10. $this->loader = new Loader();
  11. }
  12.  
  13. public function get_instance()
  14. {
  15. return self::$instance;
  16. }
  17. }
  18. ?>


Loader.php

  1. <?php
  2. class Loader
  3. {
  4. public function GetFile($path, $data = '')
  5. {
  6. $file = file_get_contents($path);
  7.  
  8. echo $file;
  9. }
  10. }
  11. ?>



Plik index.php z katalogu application

  1. <?php
  2. class Index extends Controller
  3. {
  4. function __construct()
  5. {
  6. parent::__construct();
  7. }
  8.  
  9. public function Index()
  10. {
  11. $data = array
  12. (
  13. 'A' => 'a',
  14. 'B' => $this->loader->GetFile("template/Test.php")
  15. );
  16.  
  17. $this->loader->GetFile("template/main.php", $data);
  18. }
  19. }
  20. ?>


Zawartość pliku main.php

  1. Jakiś tekst
  2. {B}


Moje pytanie brzmi jak podmienić w pliku main.php {B} na zawartość pliku Test.php, próbuję na wszystkie sposoby i przez str_replace i przez przeg_replace i za każdym razem wychodzi jakiś błąd, między innym Catchable fatal error: Object of class Loader could not be converted to string in, proszę o pomoc.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Tomplus
post 22.01.2019, 06:51:43
Post #2





Grupa: Zarejestrowani
Postów: 1 834
Pomógł: 225
Dołączył: 20.03.2005
Skąd: Będzin

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


No nie wiem w czym problem, skoro na stronie jest nawet przykład użycia:

  1. class Loader
  2. {
  3. public function GetFile($path, $data = '')
  4. {
  5. $file = file_get_contents($path);
  6. $convert = new \Treto\ConvertStrings();
  7. echo $convert -> interpolate($file, $data,'{}');
  8. }
  9. }
  10.  


Go to the top of the page
+Quote Post

Posty w temacie


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: 19.04.2024 - 00:05