hessbbq Posted October 29, 2012 Share Posted October 29, 2012 Here is a very tiny program(3 files) has embedded with Smarty template engine. Anyone knows how to remove Smarty completely? Complete source files as in attachment. index.php <?php require("comm/Smarty.class.php"); require_once("get_data.php"); require_once("books.php"); $book = new bo_books(); $book->apply_discount(); $smarty = new Smarty; $smarty->assign("book",$book); $smarty->display('index.tpl'); ?> get_data.php <?php class books { //public public $title = array(); public $image = array(); public $author = array(); public $description = array(); public $year = array (); public $price = array(); // private private $filename = "data.txt"; //class constructor function __construct() { //get the lines as an array $i=-1; $lines = file($this->filename); // strip "\n" at the end of each array // get each variable in an array foreach ( $lines as $line) { if (strlen($line) > 2) { $line = rtrim($line); list($what, $content) = explode("=> ", $line."=> => => "); if ($what == "Title") { $i++; $this->title[$i]=$content; } elseif ($what == "Image") { $this->image[$i]=$content; } elseif ($what == "Author") { $this->author[$i]=$content; } elseif ($what == "Description") { $this->description[$i]=$content; } elseif ($what == "Year") { $this->year[$i]=$content; } elseif ($what == "Price") { $this->price[$i]=$content; }; }; }; } // end constructor } // end GetData ?> books.php <?php class bo_books { //public public $title = array(); public $image = array(); public $author = array(); public $description = array(); public $year = array (); public $price = array(); public $discount = array(); public $discounted = array(); //private protected $DataObject; function __construct() { $this->DataObject = new books(); } public function apply_discount() { $this->title = $this->DataObject->title; $this->image = $this->DataObject->image; $this->author = $this->DataObject->author; $this->description = $this->DataObject->description; $this->year = $this->DataObject->year; $this->price = $this->DataObject->price; $j = 0; foreach($this->year as $year) { if ($this->year[$j] == '2004') $this->discount[$j] = '20'; elseif ($this->year[$j] == '2005') $this->discount[$j] = '10'; $this->discounted[$j] = intval($this->price[$j] * (100 - $this->discount[$j]) ) / 100 ; $j++; }; } // end function apply_discount() } // end class bo_books ?> data.txt Title=> Building Websites with VB.NET and DotNetNuke 3.0 Image=> 1904811272.jpg Author=> Daniel N. Egan Description=> A practical guide to creating and maintaining your own website with DotNetNuke, the free, open source evolution of Microsoft's IBuySpy Portal Year=> 2005 Price=> 39.99 Title=> SSL VPN : Understanding, evaluating and planning secure, web-based remote access Image=> 1904811078.jpg Author=> Joseph Steinberg, Tim Speed, Simon Jenner Description=> A comprehensive overview of SSL VPN technologies and design strategies Year=> 2005 Price=> 49.99 Title=> Windows Server 2003 Active Directory Design and Implementation=> Creating, Migrating, and Merging Networks Image=> 1904811086.jpg Author=> John Savill Description=> A unique, scenario-based approach to selecting and implementing the best Active Directory design for your environment Year=> 2005 Price=> 59.99 Title=> Building Websites with the ASP.NET Community Starter Kit Image=> 1904811000.jpg Author=> Cristian Darie, K. Scott Allen Description=> A comprehensive guide to understanding, implementing, and extending the powerful and freely available application from Microsoft Year=> 2004 Price=> 44.99 1_Smarty_mycode.zip Quote Link to comment https://forums.phpfreaks.com/topic/270026-smarty-guru-please~~-remove-template/ Share on other sites More sharing options...
OOP Posted October 29, 2012 Share Posted October 29, 2012 (edited) Hi there, In order to remove the smarty engine code, just remove the below lines from the file index.php // This line is needed in order to include the smarty engine class[/color] require("comm/Smarty.class.php"); // In here, you are creating a new smarty engine object and asking it // to display the books list using the template "index.tpl" $smarty = new Smarty; $smarty->assign("book",$book); $smarty->display('index.tpl'); But you need to edit the code inside "index.tpl" and remove any reference to smarty inside it, I mean use pure PHP to display the book list. I hope that answers your question Edited October 29, 2012 by OOP Quote Link to comment https://forums.phpfreaks.com/topic/270026-smarty-guru-please~~-remove-template/#findComment-1388391 Share on other sites More sharing options...
hessbbq Posted October 29, 2012 Author Share Posted October 29, 2012 (edited) That's what I'm trying to do. Rewrite the code into pure PHP completely but failed. I must missed something or made some mistakes by myself. Since there nothing wrong with the code. Here's complete source code. Previous one missing some pics and Smarty core. http://www6.mimima.c...ref=FGHkNoDtmB Edited October 29, 2012 by hessbbq Quote Link to comment https://forums.phpfreaks.com/topic/270026-smarty-guru-please~~-remove-template/#findComment-1388460 Share on other sites More sharing options...
OOP Posted October 30, 2012 Share Posted October 30, 2012 Okay, I just spent few minutes trying to rewrite your code. Please find the attached modified scripts. Should you need any further clarification, please let me know Best regards BooksLoader.zip Quote Link to comment https://forums.phpfreaks.com/topic/270026-smarty-guru-please~~-remove-template/#findComment-1388642 Share on other sites More sharing options...
Christian F. Posted October 30, 2012 Share Posted October 30, 2012 You're way too kind, OOP. Way too kind. Quote Link to comment https://forums.phpfreaks.com/topic/270026-smarty-guru-please~~-remove-template/#findComment-1388675 Share on other sites More sharing options...
OOP Posted October 30, 2012 Share Posted October 30, 2012 That is my problem, Christian . Being too kind Quote Link to comment https://forums.phpfreaks.com/topic/270026-smarty-guru-please~~-remove-template/#findComment-1388686 Share on other sites More sharing options...
hessbbq Posted October 30, 2012 Author Share Posted October 30, 2012 Okay, I just spent few minutes trying to rewrite your code. Please find the attached modified scripts. Should you need any further clarification, please let me know Best regards WOW~~ YOU‘RE THE MAN!!! YOU ROCK!!! Quote Link to comment https://forums.phpfreaks.com/topic/270026-smarty-guru-please~~-remove-template/#findComment-1388746 Share on other sites More sharing options...
OOP Posted October 31, 2012 Share Posted October 31, 2012 Hey, I hope that what you were looking for Quote Link to comment https://forums.phpfreaks.com/topic/270026-smarty-guru-please~~-remove-template/#findComment-1388943 Share on other sites More sharing options...
hessbbq Posted November 2, 2012 Author Share Posted November 2, 2012 Here's another version of fixed. Just in case if anyone feel interested. http://www6.mimima.com/link.php?ref=q10jkvq9Xt Quote Link to comment https://forums.phpfreaks.com/topic/270026-smarty-guru-please~~-remove-template/#findComment-1389532 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.