Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> 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
Tomplus
post 21.01.2019, 21:09:11
Post #2





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

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


Spróbuj tą bibliotekę:

https://github.com/Tomirad/ConvertStrings

Go to the top of the page
+Quote Post
Gibcio2008
post 21.01.2019, 21:45:24
Post #3





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

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


Tylko proszę powiedz jak ją podpiąć, bo zielonego pojęcia nie mam
Go to the top of the page
+Quote Post
Pyton_000
post 21.01.2019, 21:52:14
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


@Gibcio2008 a co ty chcesz zrobić? Bo mnie się wydaje że ten Twój loader to raczej zamiast file_get_contents powinien mieć po prostu `require_once`
Go to the top of the page
+Quote Post
Gibcio2008
post 21.01.2019, 22:03:10
Post #5





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

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


Chodzi mi głównie o to żeby z tablicy w Pliku 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. ?>


Wartości wprowadzić w pliku main.php za odpowiednie znaczniki np.

[B] lub {B} - żeby była zawartość z $this->loader->GetFile("template/Test.php")

  1. Jakiś tekst
  2. [B]
Go to the top of the page
+Quote Post
markonix
post 22.01.2019, 01:01:07
Post #6





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

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


https://github.com/bobthecow/mustache.php


--------------------
Go to the top of the page
+Quote Post
Tomplus
post 22.01.2019, 06:51:43
Post #7





Grupa: Zarejestrowani
Postów: 1 828
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
Gibcio2008
post 22.01.2019, 12:24:46
Post #8





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

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


Poradziłem sobie wystarczyło pobawić się w buforowanie
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: 28.03.2024 - 19:05