1

So i wrote a few simple classes to handle login, password hashing and query handling. They've all been tested and work... HOWEVER!

I placed these classes inside a template, let's call it /classes

When i used php's include "" and require "" it caused server errors.

I then resorted to using EE syntax to embed the classes template

{embed="/path_to/classes"}

So that only worked half way. The code below will work fine in classes template alone, but NOT if classes is embedded and the code below is ran on the parent template.

 $createPassword = new protectPassword;
 $securePassword = $createPassword->makePassword($passwrd);

So i guess my questions are, am i doing something wrong in EE, or does EE just not like / allow such things?

Any help is much appreciated! Thanks!

2
  • Thanks guys Peter & Derek. I guess i'll just stick to procedural php. Writing up plugins, modules or extensions is totally unnecessary. My hope was to keep the code lean and clean. Thanks again! – ipixel Sep 26 '13 at 20:15
  • 2
    Just my 2¢ - writing a plugin that contains your PHP code is far "leaner and cleaner" than loading your templates with raw PHP. – Derek Hogue Sep 26 '13 at 21:03
2

I'm afraid you're approaching EE in the wrong way. it's not a good idea to mash-up EE, templates and PHP in the way you're describing.

embeds {embed="template_group/template"} are for templates only - not including any file you want.

You mentioned EE1, you can download the docs from Ellis Labs website, or view online here: http://ee1docs.com/development/index.html. I'd highly recommend you read the developer documentation which goes into creating classes for plugins, modules and extensions. These can then be accessed via tags from the frontend instead of using PHP in the templates. Also look at other examples and learn from them - Devot-ee has lot's to choose from and you may find there's something that already does what you need (don't forget to filter by EE1).

Using CodeIgniter and ExpressionEngine code in the right will give you lot's of power to tap into their own classes and methods.

If you're starting out in EE or have inherited a site that uses EE1, I'd highly recommend upgrading and moving to EE2.

1

Putting anything beyond the simplest procedural PHP inside your templates is not a good idea, and will doubtless lead to headaches.

I strongly suggest you write an add-on to house your custom code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.