Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> php smarty
atomp3
post
Post #1





Grupa: Zarejestrowani
Postów: 126
Pomógł: 1
Dołączył: 31.03.2006

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


Witam

na tej stronie napisałem posta: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=11001

Ponieważ nie chce mi sie przepisywać napisze krótko o co mi chodzi.

W pliku index.php steruje strona przez switch`a (kod w linku powyzej) -> wywoluje funkcje ktora nastepnie poprzez smarty wyswietla na index.tpl.

Jednak nie wiem czy robie to poprawnie i druga sprawa czy musze uzywac zmiennych globalnych w funkcjach? $db i $smarty? inaczej nie dzialaja.

Dzieki za wszelkie info. Szczerze to nie wiem jak to najlepiej ugryzc zeby bylo zgrabnie, chodzi mi o sterowanie strona z poziomu index.php wywolanie funkcji i wyswietlnie smarty na index.tpl
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
atomp3
post
Post #2





Grupa: Zarejestrowani
Postów: 126
Pomógł: 1
Dołączył: 31.03.2006

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


To mnie sie dzisiaj ciezko myśli (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) bo nie chce to działać

index.php

  1. <?php
  2. $news = new News;
  3.  
  4. require 'smarty/smarty.class.php'; 
  5. $smarty = new Smarty; //core smarty object
  6.  
  7.  
  8. switch ($_GET['action']) {
  9.  
  10.  case 'view' :
  11.  default : $news->viewNews();
  12.  
  13.  
  14.  }
  15. ?>



w functions.php

  1. <?php
  2. class News {
  3.  
  4.  
  5. // database object
  6. var $db;
  7.  
  8.  
  9. //konstruktor
  10. function News() {
  11.  
  12. $this -> db = new DbConnect("localhost","root","","catalog",$error_reporting=true,$persistent=false);
  13.  
  14.  
  15. }
  16.  
  17.  
  18.  
  19. function viewNews() {
  20.  
  21.  
  22. $this->db->query("SELECT * FROM logbook") or die($db->error());
  23.  
  24.  
  25. }
  26.  
  27. }
  28. ?>



za każdym razem Fatal error: Call to a member function on a non-object (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)


ok już wiem o co biega (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) może komuś to pomoże:

  1. <?php 
  2.  
  3. require './smarty/smarty.class.php';
  4. require './includes/classes/DBconnect.class.php'; 
  5.  
  6. class News_Smarty extends Smarty { 
  7. function News_Smarty() {
  8. $this->template_dir = 'templates/tmpl1';
  9. $this->compile_dir = 'templates_c';
  10. $this->config_dir = 'configs';
  11. $this->cache_dir = 'cache';
  12. }
  13. }
  14.  
  15.  
  16. class News {
  17.  
  18. var $tpl;
  19. var $sql;
  20. var $db;
  21.  
  22.  
  23. //constructor
  24. function News() {
  25. $this -> tpl =& new News_Smarty;
  26. $this -> sql =& new DbConnect("localhost","root","","catalog",$error_reporting=true,$persistent=false);
  27. $this -> sql -> open() or die($this -> sql ->error());
  28. }
  29.  
  30.  
  31. function viewNews() {
  32.  
  33. $db = $this -> sql;  
  34. $db -> query("SELECT * FROM product") or die($db->error());
  35.  
  36. $il=$db->numrows();
  37.  
  38.  for($i = 0; $i < $il; $i++) {
  39. $row=$db->fetcharray();
  40.  $data[] = $row;
  41.  }
  42.  
  43.  
  44. $this -> tpl -> assign('view', '1');  
  45. $this -> tpl -> assign('data', $data);
  46.  
  47. $this -> tpl -> display('index.tpl');
  48. }
  49.  
  50. }
  51.  
  52. ?>
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: 5.10.2025 - 07:17