 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
11-01-2008, 12:54 PM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Posts: 133
Thanks: 6
|
Template Class Issues
Hey,
Okay, so, we have a template class (wrote from scratch) but the issue lies in the if statement parsing, the issue there is that if there's an if statement within an if statement (html if statement as in {if name='blah'}content{/endif} etc..) then the second if statement will get prematurely cut off, i think it's due to the regex on line 143. Any ideas anybody?
Code: [nvm]
Thanks!
Last edited by WinSrev : 11-03-2008 at 05:55 AM.
|
|
|
11-01-2008, 01:24 PM
|
#2 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
First thing that crosses my mind, is why you mix PHP5 with PHP4?
PHP Code:
//PHP4 var $output;
//PHP5 public function newTemplate($templateFile) { // ... }
__________________
|
|
|
|
11-01-2008, 01:27 PM
|
#3 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Posts: 133
Thanks: 6
|
Well, var is in PHP5 aswell you know? that's not the issue at all and what you said doesn't make sense.
|
|
|
11-01-2008, 02:13 PM
|
#4 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Quote:
Note: The PHP 4 method of declaring a variable with the var keyword is still supported for compatibility reasons (as a synonym for the public keyword). In PHP 5 before 5.1.3, its usage would generate an E_STRICT warning.
|
From PHP: Visibility - Manual
var is just an alias for public, but it would make more sense to use visibility keywords to keep your code consistent, as you have used them elsewhere.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
11-01-2008, 02:27 PM
|
#5 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Posts: 133
Thanks: 6
|
Hmm, okay, i admit that's a flaw with the script but, not that severe.
|
|
|
11-01-2008, 03:09 PM
|
#6 (permalink)
|
|
The Addict
Join Date: Jun 2008
Posts: 335
Thanks: 2
|
I'm not addressing the if statement issue because I feel that the template class needs to be rewritten. it needs a cache system, especially if the site will be large and have lots of forums/topics. Parsing LARGE quantities of data repeatedly would put a strain on the site's loading time.
|
|
|
|
11-01-2008, 03:14 PM
|
#7 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
I didn't say that it was a FLAW with that part. It was just a question, because TO ME it's weird to see them mixed. Sure it WORKS, but it's weird.
And I mean, if you use public function, then why not public $var ?
And about that, in this case you should use private $output which would actually be better.
__________________
|
|
|
|
11-01-2008, 03:19 PM
|
#8 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Posts: 133
Thanks: 6
|
Okay, Enfernikus: So, whenever you write any system, the first lines of code you write are for a cache system? That's pretty weird.
Tanax: Okay, yes, i agree with what you're saying and i will make sure i go through all the files and make changes as appropriate. Thanks.
Any ideas on the if statement issue though? Thanks
|
|
|
11-01-2008, 03:41 PM
|
#9 (permalink)
|
|
The Addict
Join Date: Jun 2008
Posts: 335
Thanks: 2
|
I do write my first lines of code with caching in mind, when ever doing any parsing or database related things.
|
|
|
|
11-01-2008, 05:20 PM
|
#10 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Posts: 133
Thanks: 6
|
It's quite hard to cache something that doesn't work properly anyway, so, anychance of going back on topic please? thanks.
|
|
|
|
The Following User Says Thank You to WinSrev For This Useful Post:
|
|
11-02-2008, 12:08 PM
|
#11 (permalink)
|
|
The Wanderer
Join Date: Oct 2008
Posts: 9
Thanks: 0
|
Why do you want a template class if php is a template engine on it's own?
|
|
|
|
11-02-2008, 01:17 PM
|
#12 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Posts: 133
Thanks: 6
|
What are you even talking about?
|
|
|
11-02-2008, 03:40 PM
|
#13 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Quote:
Originally Posted by kjarli
Why do you want a template class if php is a template engine on it's own?
|
mate, you are totally of topic ;P
|
|
|
|
11-02-2008, 08:42 PM
|
#14 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Quote:
Originally Posted by codefreek
mate, you are totally of topic ;P
|
Not really, whats wrong with something like this:
PHP Code:
<?php class template { private $aVarStack = array(); private $szTplFile; public function __construct($szTplFile) { $this->szTplFile = $szTplFile; } public function __set($szKey, $mValue) { $this->aVarStack[$szKey] = $mValue; } public function __get($szKey) { if(!array_key_exists($szKey, $this->aVarStack)) { throw new Exception($szKey . 'is an invalid template variable'); } return $this->aVarStack[$szKey]; } public function display() { include $this->szTplFile . '.phtml'; } }
Now the tpl file:
PHP Code:
<h1><?php echo $this->header; ?></h1> <p><?php echo $this->content; ?></p>
And now the driver:
PHP Code:
<?php require('template.php'); try { $tmp = new template('template'); $tmp->header = 'this is a header'; $tmp->content = 'This is some content'; $tmp->display(); } catch(Exception $e) { echo 'Error in template: ', $e->getMessage(); }
Its not perfect but at least you don't need to waste the time parsing tpl files for special tokens and then injecting data into them, after all ZendFramework seems to be ok with it.
For if statements/loops etc just use PHP:
PHP Code:
<html> ... <?php if($name == 'Sam'):?> <p>Do something here for Sam?</p> <?php endif;?>
... </html>
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
|
The Following User Says Thank You to sketchMedia For This Useful Post:
|
|
11-03-2008, 05:55 AM
|
#15 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Posts: 133
Thanks: 6
|
Okay, you're an idiot, it's offical, the reason people use template classes it to keep php and html seperate, with open source software someone could download a template with malicious php code in and they wouldn't know any different. All everyone in this topic has done is overlooked the problem, you're finding ways around it instead of finding a solution.
Can a moderator please close this topic? the people on this forum are incredibly stupid.
|
|
|
11-03-2008, 09:34 AM
|
#16 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
|
I'll agree that the folks posting in this topic haven't directly commented on the original question. Some good points have been raised but they're not really related to what WinSrev's looking for, feel free to discuss those ideas (code consistency, caching, templating appropaches) in other topics but not here.
If anyone does have any comments on parsing the {if} blocks the they're very much welcome.
P.S. WinSrev, please don't get upset if people can't stick to the topic at hand or take wider viewpoints than asked for. That's no reason to label the members of an entire forum as "incredibly stupid", however frustrating it is to have a question repeatedly ignored.
|
|
|
|
11-03-2008, 09:45 AM
|
#17 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Ok heres your solution: Smarty : Template Engine
I dont suppose you know of the old phrase: JFGI. I'll let you work that out O' clever one.
Quote:
|
the reason people use template classes it to keep php and html seperate
|
And to add yet another language adding confusion, Im a PHP developer not a Smarty developer. It also adds more unnecessary parsing for the PHP engine to do and dont bring caching into the equasion because its easy enough without a templating language.
Quote:
|
with open source software someone could download a template with malicious php code in and they wouldn't know any different
|
If that is the real reason for templating languages, go tell WordPress, ZendFramework and many more systems that use more or less this approach of templates
If you had been a little nicer and less actually flaming me like a petty forum troll then I may have had a friendly debate with you on the subject, but currently I'd rather you grow up first.
Ok, I'm done with you, I suggest you learn some manners before posting anything related to this forum, this isn't behavior people have in community and it isn't the attitude that I am willing to tolerate.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
Last edited by sketchMedia : 11-03-2008 at 10:24 AM.
|
|
|
|
11-03-2008, 06:23 PM
|
#18 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
JFGI = Just Fucking Google It.
If you don't find your answers here, just search for it yourself. I mean, if you're so lazy you can't even search for it, then don't get angry and upset when you don't get any response to the problem in here.
__________________
|
|
|
|
11-04-2008, 10:59 AM
|
#19 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Posts: 133
Thanks: 6
|
Of course, because i had no idea google exist, i'm not sure how to use a search engine, can someone please advise me? thanks. And Smarty isn't the answer, what a fucking stupid thing to say.
(that was sarcasm)
Can a moderator lock this topic please? thanks.
|
|
|
11-04-2008, 03:12 PM
|
#20 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Quote:
Of course, because i had no idea google exist, i'm not sure how to use a search engine, can someone please advise me? thanks. And Smarty isn't the answer, what a fucking stupid thing to say.
(that was sarcasm)
|
So smarty is the answer then, and not a 'f**king' stupid thing to say, I'm glad I was able to help.
Would be a good idea to read: TalkPHP - Rules before making any further posts, specifically these rules perhaps:
Quote:
- No profanities to be used in your posts. Although these will be starred out, it does look rather immature nonetheless.
- Debates are welcomed, however, do not reduce the debate to a personal level where personal insults are thrown about.
|
I regard 'Okay, you're an idiot, it's offical' as a personal attack.
Stop being so infantile.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|