Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [PHP]php i smarty
eminiasty
post 22.08.2017, 19:46:29
Post #1





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


Chcialem zaimplementowac sobie system szablonow smarty w swoim projekcie.

Wywolywany na index:
  1. require_once($MAINPATH.'/smarty/Smarty.class.php');
  2. $tpl = new Smarty; // 2
  3. $tpl -> template_dir = $MAINPATH.'/panel/templates/';
  4. $tpl -> compile_dir = $MAINPATH.'/panel/templates_c/';
  5. Kotry to ma dostep do wszystkich pod stron.


Nazwy szablonowe zmienilem na tpl :
  1. require_once($MAINPATH.'/templates/panel/head.tpl');


Problem jest w tym, że teraz w pliku head.tpl nie dziala mi np taki kod:

  1. <link rel="stylesheet" href="<?php echo site_url(); ?>static/css/panel.css?ver={random in=1 out=10} ">


Natomiast gdy zrobie rand() , kod normalnie dziala. Chyba w smarty nie powinno byc tagow php uzywanych? Co zrobic by sstem szablonow zaczol dzialac

Ten post edytował eminiasty 22.08.2017, 20:09:14
Go to the top of the page
+Quote Post
nospor
post 23.08.2017, 08:43:36
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Przeciez w dokumentacji smarty masz wyraznie opisane czy mozesz uzywac kodu php w srodku czy nie. I jesli mozesz to jak...

A po drugie po grzyba brniesz w to badziewie?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 16:55:17
Post #3





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


Z wykrozystaniem CodeIgniter:

  1. require_once( APPPATH.'/third_party/smarty/libs/Smarty.class.php' );

O co chodzi z ta sciezka?

  1. Message: require_once(C:\xampp\htdocs\xxx\application\/third_party/smarty/libs/Smarty.class.php): failed to open stream: No such file or directory

nawet w przykladzie jest cos takiego:

http://www.coolphptools.com/codeigniter-smarty


Od czegoś trzeba zacząć..
Go to the top of the page
+Quote Post
nospor
post 23.08.2017, 17:01:32
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Czy to
\/
w sciezce nie daje ci do myslenia?


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 17:02:05
Post #5





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


probowalem uzyc realpath na APPPATH ale to nic nie dalo, nie mam pomyslu na to
Go to the top of the page
+Quote Post
nospor
post 23.08.2017, 17:03:09
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




require_once( APPPATH.'third_party\smarty\libs\Smarty.class.php' );


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 17:07:53
Post #7





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


to nic nie zmienia, a pliki sa fizycznie w tej lokalizacji
Go to the top of the page
+Quote Post
nospor
post 23.08.2017, 17:11:02
Post #8





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




require_once( APPPATH.'third_party\\smarty\\libs\\Smarty.class.php' );


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 17:19:52
Post #9





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


nie dziala, moze to jakis blad w xampie(korzystam z tego programu jako serwera)?
Go to the top of the page
+Quote Post
nospor
post 23.08.2017, 17:21:07
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Pokaz jaki masz teraz dokladnie komunikat bledu


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 17:24:50
Post #11





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


1.
  1. A PHP Error was encountered
  2.  
  3. Severity: Warning
  4.  
  5. Message: require_once(C:\xampp\htdocs\xxx\application\third_party\smarty\libs\Smarty.class.php): failed to open stream: No such file or directory
  6.  
  7. Filename: libraries/Smartie.php
  8.  
  9. Line Number: 13
  10.  
  11. Backtrace:
  12.  
  13. File: C:\xampp\htdocs\xxx\application\libraries\Smartie.php
  14. Line: 13
  15. Function: _error_handler
  16.  
  17. File: C:\xampp\htdocs\xxx\application\libraries\Smartie.php
  18. Line: 13
  19. Function: require_once
  20.  
  21. File: C:\xampp\htdocs\xxx\application\controllers\Welcome.php
  22. Line: 8
  23. Function: __construct
  24.  
  25. File: C:\xampp\htdocs\xxx\index.php
  26. Line: 315
  27. Function: require_once


2.
  1. Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs\xxx\application\third_party\smarty\libs\Smarty.class.php' (include_path='\xampp\php\PEAR') in C:\xampp\htdocs\xxx\application\libraries\Smartie.php on line 13
  2. A PHP Error was encountered
  3.  
  4. Severity: Compile Error
  5.  
  6. Message: require_once(): Failed opening required 'C:\xampp\htdocs\xxx\application\third_party\smarty\libs\Smarty.class.php' (include_path='\xampp\php\PEAR')
  7.  
  8. Filename: libraries/Smartie.php
  9.  
  10. Line Number: 13
  11.  
  12. Backtrace:
Go to the top of the page
+Quote Post
Pyton_000
post 23.08.2017, 18:53:19
Post #12





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

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


Czy aby na pewno masz ten plik w `C:\xampp\htdocs\xxx\application\third_party\smarty\libs\` ?
Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 20:26:00
Post #13





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


tak
Go to the top of the page
+Quote Post
Pyton_000
post 23.08.2017, 20:58:14
Post #14





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

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


Wg. błędu nie masz. Albo źle patrzysz.
Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 21:02:28
Post #15





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


problem rozwiazany, przeinstalowalem pear w xampie i zakualizowalem php , nie wiem co to mialo wspolnego ale zaczelo dzialac

Stworzylem szablon, niby jest ok, gdyz dump zwraca zawartosc:

  1. {$result|var_dump}


  1. array(1) { ["result"]=> array(2) { [0]=> object(stdClass)#25 (8) { ["id"]=> string(1) "1" ["name"]=> string(7) "Moduły" ["description"]=> string(38) "Moduł dodania nowych funkcjonalności" ["number"]=> string(3) "000" ["file_start"]=> string(11) "modules.php" ["position"]=> string(1) "0" ["active"]=> string(1) "1" ["dateAdd"]=> string(19) "2017-08-19 17:08:10" } [1]=> object(stdClass)#26 (8) { ["id"]=> string(1) "9" ["name"]=> string(4) "Test" ["description"]=> string(7) "Testowy" ["number"]=> string(3) "001" ["file_start"]=> string(9) "index.php" ["position"]=> string(1) "0" ["active"]=> string(1) "1" ["dateAdd"]=> string(19)


ale, gdy chce zrobic z tego pętle to w niej już jest null?
  1. {if $result|@count != 0}
  2. <table>
  3. <tr>
  4. <th>ID</th>
  5. </tr>
  6. {foreach from=$result item=item}
  7.  
  8. <tr>
  9. <td>{$item.id}</td>
  10. <td>{$item.name}</td>
  11. <td>{$item.number}</td>
  12.  
  13. </tr>
  14. {/foreach}
  15. </table>
  16. {/if}


  1. np. {$item.name|var_dump}
z dokumentacji wynika ze to prawidlowa forma wyswietlania danych, wiec o co chodzi?
Go to the top of the page
+Quote Post
trueblue
post 23.08.2017, 21:29:23
Post #16





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


{$item->id}

?


--------------------
Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 21:38:06
Post #17





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


{$item.id|var_dump} - zwraca null
{$item->id|var_dump} - zwraca null

Ten post edytował eminiasty 23.08.2017, 21:38:43
Go to the top of the page
+Quote Post
trueblue
post 23.08.2017, 21:47:32
Post #18





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Musisz iterować po $result['result'], a nie $result.


--------------------
Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 21:56:32
Post #19





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


oO działa, ale dlaczego tak?
w przykładach jest zupełnie co innego, np tu:

  1. {* The header block is output every five rows *}
  2. <table>
  3. {foreach from=$items key=myId item=i name=foo}
  4. {if $smarty.foreach.foo.index % 5 == 0}
  5. <tr><th>Title</th></tr>
  6. {/if}
  7. <tr><td>{$i.label}</td></tr>
  8. {/foreach}
  9. </table>


-raz ze używają kropki
-dwa ze nie ma odniesienia do tablicy w ten sposob?

Można jakimś sposobem przekazywać tu samo $result zamiast $result['result']?
Go to the top of the page
+Quote Post
trueblue
post 23.08.2017, 21:57:14
Post #20





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Dlatego, że pierwszy element tablicy ma indeks o nazwie result, a po drugie elementami tej zagnieżdżonej tablicy są obiekty stdClass, a więc tak (->) trzeba się odwoływać.
Jakbyś nazwał swoją tablicę $tablica, to wtedy nie byłoby takiej konsternacji, bo odwoływałbyś się poprzez $tablica['result'].

Te dane są z json_decode? Jeśli tak, to parsuj je do postaci tablicy asocjacyjnej (dokumentacja), wtedy będziesz mógł odwoływać się poprzez kropkę albo poprzez [].

Ten post edytował trueblue 23.08.2017, 21:58:05


--------------------
Go to the top of the page
+Quote Post
eminiasty
post 23.08.2017, 22:15:29
Post #21





Grupa: Zarejestrowani
Postów: 267
Pomógł: 0
Dołączył: 11.09.2015

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


W tym momencie jest tylko tak:
model:
  1. function oSelect()
  2. {
  3. $this->db->select('*');
  4. $query = $this->db->get('modules');
  5. return $query->result();
  6. }


controler:

  1. public function index()
  2. {
  3. $data['modules'] = $this->model_test->oSelect();
  4. $this->smarty->assign('modules', $data);
  5. $this->smarty->view('header.tpl');
  6. }


Sprobowałem tak:

  1. function oSelect()
  2. {
  3. $this->db->select('*');
  4. $this->db->from('modules');
  5. $query = $this->db->get();
  6. return json_encode($query->result());
  7. }



lub tak:

  1. public function index()
  2. {
  3. $data['modules'] = json_encode($this->model_test->oSelect());
  4. $this->smarty->assign('modules', $data);
  5. $this->smarty->view('header.tpl');
  6. }


chodz nie wiem ktore miejsce jest lepsze, oba sposoby nie zadzialaly
Go to the top of the page
+Quote Post
nospor
post 24.08.2017, 10:15:10
Post #22





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Staraj sie rozumiec co do ciebie pisza. trueblue zalozyl ze masz dane z JSON bo nie podales jak je generujesz. On nie kazal ci ich zamieniac na JSON...


Po co tworzysz tablice tylko po to by wlozyc tam modules? Tylko sam sobie komplikujesz zycie


  1. $this->smarty->assign('modules', $this->model_test->oSelect());

I juz. Teraz jeszcze raz podejrzyj sobie w smarty co tam masz


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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: 14.08.2025 - 06:26