Welcome Guest, Not a member yet? Register   Sign In
Combine CodeIgniter with Smarty
#11

[eluser]Lone[/eluser]
I haven't been a big fan of template engines as well - as long as you get the seperation correct with your html and php (like the use of 'views' in CI) then there isn't much requirement for them.

You still have to learn the template engines way of doing a loop and if statements etc. - I feel you might as well learn some basic php instead of some of templating language at times.
#12

[eluser]Rick Jolly[/eluser]
[quote author="Edemilson Lima" date="1200796320"]
Smarty cache is not a real cache. It could be if it produces pure HTML code like CI, not PHP code to be interpreted.[/quote]
Please stop spreading misinformation. Smarty supports cache.
http://www.smarty.net/manual/en/caching.php

Fact: Smarty compiles into pure php and has a cache feature.
#13

[eluser]Edemilson Lima[/eluser]
Quote:Please stop spreading misinformation. Smarty supports cache.

I didn't tell it does not have cache.

Quote:Fact: Smarty compiles into pure php and has a cache feature.

"Technical Note: The files in the $cache_dir are named similar to the template name. Although they end in the .php extention, they are not intended to be directly executable."

That is the problem. While CI executes the PHP scripts just once and writes the resulting HTML content to the cache, Smarty compiles the templates and produces a new PHP code that will be re-interpreted again by the PHP engine, not just sent to the browser. Do you understand the difference?
#14

[eluser]Rick Jolly[/eluser]
[quote author="Edemilson Lima" date="1200897166"]
"Technical Note: The files in the $cache_dir are named similar to the template name. Although they end in the .php extention, they are not intended to be directly executable."

That is the problem. While CI executes the PHP scripts just once and writes the resulting HTML content to the cache, Smarty compiles the templates and produces a new PHP code that will be re-interpreted again by the PHP engine, not just sent to the browser. Do you understand the difference?[/quote]

No. Both CI and Smarty write cache files that don't contain php. The quote you referenced above points out that although the cache file has a .php extension, it isn't an executable php file. However, both CI and Smarty read the entire cache file and parse metadata from it. CI gets the timestamp from within the cache file, and Smarty gets some additional info.

Smarty's cache implementation is much more powerful than CI's. While CI only allows caching per page (all or nothing), Smarty allows partial caching.

Examples

CI cached file:
Code:
1200900241TS---><html>
<head>
<title>Smarty Test</title>
</head>
<body>
Text: Hello World!</body>
</html>

Smarty cached file:
Code:
129
a:4:{s:8:"template";a:1:{s:8:"test.php";b:1;}s:9:"timestamp";i:1200894979;s:7:"expires";i:1200898579;s:13:"cache_serials";a:0:{}}<html>
<head>
<title>Smarty Test</title>
</head>
<body>
Text: Hello World!
</body>
</html>

Smarty compiled file:
Code:
<?php /* Smarty version 2.6.18, created on 2008-01-20 21:56:19
         compiled from test.php */ ?>
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
Text: <?php echo $this->_tpl_vars['hello']; ?>
</body>
</html>

Smarty template file:
Code:
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
Text: {$hello}
</body>
</html>
#15

[eluser]Edemilson Lima[/eluser]
Quote:The quote you referenced above points out that although the cache file has a .php extension, it isn’t an executable php file.

"Although they end in the .php extention, they are not intended to be directly executable."

These files are PHP files and can be executable, but is not intended to be, because they are called by the template engine, under the right path. If somebody call them in the cache path, it will execute, but will not work.

Quote:both CI and Smarty read the entire cache file and parse metadata from it.

In this aspect they work pretty the same, altought Smarty have more features.

Quote:Smarty’s cache implementation is much more powerful than CI’s. While CI only allows caching per page (all or nothing), Smarty allows partial caching.

In this case, I agree it is better. I am not saying Smarty don't have its merits.

What I understood from your examples, is that Smarty takes the template file, produces a compiled PHP file and stores it in the template cache. Then it produces the cache file from it, right? Well, if it does, then it really have a cache like CI, with the rendered HTML. In this case, does it have two cache folders? One for PHP compiled files and another one for rendered HTML files? I have a web site with Smarty, but I never saw such rendered HTML files in the cache folder. May the Smarty version is too old, I don't know. The credits says it is 2.6.6.

"On the next call to display('index.tpl'), the cached copy will be used instead of rendering the template again."

As far I understand, Smarty have a template cache, not a content cache. May I am wrong, but in any case, it is better to write a view with pure PHP than write a template that will be parsed and then executed to produce the content cache. You will always gain performance if you cut off one step. Don't you? And also you will save a lot of server memory if you don't load a huge unnecessary library. Isn't that true?
#16

[eluser]Rick Jolly[/eluser]
[quote author="Edemilson Lima" date="1200936228"]...does it have two cache folders? One for PHP compiled files and another one for rendered HTML files?[/quote]
Exactly. Since caching is optional, the cache folder is optional.

[quote author="Edemilson Lima" date="1200936228"]
...in any case, is better to write a view with pure PHP than write a template that will be parsed and then executed to produce the content cache. You will always gain performance if you cut off one step. Don't you? And also you will save a lot of server memory if you don't load a huge unnecessary library. Isn't that true?[/quote]
Well, remember that the template is only parsed/compiled once. But it is true that in all cases the main Smarty class file is loaded causing a small performance hit and using some memory. I think that is the only argument against Smarty that holds water. But to say it's better to use php for the template isn't always true. Besides the small performance difference, there are other things to consider.
#17

[eluser]Seppo[/eluser]
Rick, in which cases you consider it´s better to use Smarty? I´ve been using for a couple of months and I can not find any situation that the code can be cleaner, faster or easier that just PHP... I just think I´ve "learning" a new "language" that did much less than the one I already know...
#18

[eluser]Rick Jolly[/eluser]
[quote author="Seppo" date="1200973481"]Rick, in which cases you consider it´s better to use Smarty? I´ve been using for a couple of months and I can not find any situation that the code can be cleaner, faster or easier that just PHP... I just think I´ve "learning" a new "language" that did much less than the one I already know...[/quote]
I'm not a big Smarty advocate, but for me the two reasons to use Smarty are:
1) to prevent anyone that can edit templates from adding harmful php if that is a concern
2) Smarty syntax is slightly more elegant

Didn't intend to stick up for Smarty, but to slam anything based on misinformation is unacceptable.
#19

[eluser]monkeymon[/eluser]
A PHP Error was encountered
Severity: Notice

Message: Undefined index: template_layout

Filename: controllers/default_controller.php

Line Number: 74

A PHP Error was encountered
Severity: Warning

Message: array_merge() [function.array-merge]: Argument #2 is not an array

Filename: controllers/default_controller.php

Line Number: 74

A PHP Error was encountered
Severity: Warning

Message: array_merge() [function.array-merge]: Argument #1 is not an array

Filename: controllers/default_controller.php

Line Number: 76

A PHP Error was encountered
Severity: Warning

Message: array_merge() [function.array-merge]: Argument #2 is not an array

Filename: controllers/home.php

Line Number: 49



i too having this error. but i cant seem to get it fix.
i've done the installation of the sql and change the config to load from db.
what else is to be done to carry on??
#20

[eluser]Unknown[/eluser]
pure nonsense. How a web developer team can work without a smarty.. withou helpers? withoud preformated debug, without HELPERS which will generate block of code for a man who will then work with html/css =) It's more greater to create a block of code wich can be generated out of something, then to use than to include some php mixed with html file.. in it. what if a technical designer doesn't know server-side language at all and all he want's is to see where css id's and class'es are. Smarty syntax is so basic that he understand it even without reading a manual, and php.. it's not his side btw. anyway when you'll work with a huge programmer team, you'll understand that smarty is a GOD. you can write your own engine, but just DON'T USE PHP for templeting.




Theme © iAndrew 2016 - Forum software by © MyBB