Welcome to the Geeks & God Static Archive. Read more »

killed my site with my first "view"...

Joined: 11/18/2007

I am posting this in the hope that someone may have run into this previously, and they can say "oh!! you just need to do such-and-such..." I will keep looking into this in the meantime till I work out what what I did...

I was creating my very first view, with the views module. I selected the "add" tab, and filled in the details on the initial fields, like title, URL etc. I selected the checkbox on the "page" section, and I also selected the "block" section as well. I did not add ANYTHING else - I left all the other fields blank, which may seem strange, but, there you go...

I published the block to one of my sidebars, and the the site totally barfed and would not load (ever again...). I reloaded from a previous backup, and tried to reproduce the problem.

If I simply click the "page" box, and don't publish any block, and then go to the URL, I get the same error that I got before, namely:
Fatal error: Cannot redeclare dateformat() (previously declared in /home/...../public_html/includes/common.inc(1347) : eval()'d code:8) in /home/...../public_html/includes/common.inc(1347) : eval()'d code on line 6

I have tested this same thing on a clean Drupal install, and I dont get the error, so obviously its a module or such thing which is not playing nicely. I will try and isolate this by gradually turning off all my modules, but it sure scared me that I was able to totally trash my site simply by creating a view... backups are nice :)

Anyway, if any fellow G&G drupalers reading this have seen the same thing, and the solution is "obvious", please let me know, thanks!
Cheers,
Pete

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
eval()

It's saying something about eval()'d code. Do you have any arguments? Any argument handling code?

I'd need to know more details about the view to help you find the problem.

Matt Farina
Geeks and God Co-Host
www.innovatingtomorrow.net
www.mattfarina.com

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com

Joined: 11/18/2007
same php function name used in different nodes

I know what I did... Its obvious now, but still really dangerous...

I had previously created a page, using some PHP code which I had written for a previous site, and I had simply inserted this code into a page (after enabling php as the input format).

The actual code is irrelevant. It is syntactically correct, and contains a number of functions, the first of which is called "dateformat()". (and even the function name is irrelevant, as you will see...)

I subsequently created a second page, using the same PHP code, including the same functions obviously, but with some minor changes later in the script.

I could display either of these two pages separately, by going to their respective URLs, and the results were exactly as expected - the PHP code was evaluated and the correct HTML was generated.

When I called up the "view" however, it simply pulled up all of the possible nodes, including both pages containing PHP code. It looks like it simply cats all the code together and then executes it - which is why my function "dateformat()" got declared/evaluated twice; once in the first node, and then again when the second node was processed.

That was the issue - declaring the same function name twice.

BTW the same thing happens if I don't use the views module at all, but simply "promote" both these pages to the front page - the site will crash.

This tells me that I need to be very careful about the use of PHP in drupal nodes. Specifically, a function defined in a node should have a unique name - unique to that node and every other node in the site, to avoid being redeclared as a result of being

  1. promoted to the front page
  2. aggregated as part of a view
  3. aggregated some other way

This makes it more difficult to re-use PHP code which has been written for specific tasks. It also would suggest that some coordination is needed between different contributors if they were writing PHP - you would only need to have two different authors using the same name for one of their functions and you could run into problems.

Is this "working as designed", or am I doing something really silly as a drupal/PHP newbie???

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
General Coding Rule

When you are developing using a CMS or Framework a general rule is to not have the functionality in the content. This means keep the PHP out of the nodes as much as possible.

If you need to have special pages and are writing them in PHP create modules. If there are certain functions you want to call on occasion in nodes create a helper module containing those functions. Having them in one place will cut down on code duplication. I would keep these situations to a minimum. Thinking about this architecturally, there should be rare circumstances where PHP is in the nodes.

Think about the separation of layers. One of the text fields shouldn't really contain the logic in a particular programming language. That's one of the reasons for modules like the views filter. It keeps the code out of the data.

Matt Farina
Geeks and God Co-Host
www.innovatingtomorrow.net
www.mattfarina.com

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com

Joined: 11/18/2007
modules are the way to go

Thanks Matt - I didn't realise that modules could be used for this, but that's the answer! I have now run through the drupal tutorial on modules, and this is certainly the way that I'll implement this.

(incidentally my PHP code is doing a database lookup from a mysql database external to drupal, and pulling in data which is displayed on a page. This lets me display our TV broadcast schedule dynamically on the drupal site, using a separate "episodes" database. If you go to www.sneesby.com.au/content/lifesource-month you will see what I'm talking about. NB this content will eventually move to a different site but this is where I'm developing it at the moment.)

Final question before I "go quiet" for a while and start re-coding this with modules: You refer to a "helper module". Is this the same thing as a regular "module" or is there a difference?

Truly appreciate your help in this forum and throughout the site!
Pete

G&G Podcast Host
Matt Farina's picture
Joined: 06/01/2006
Modules The Same

A module is a module is a module. It's all the same thing, technically speaking, drupal. I know this can be confusing since other systems have different types of modules/extensions for different situations.

When I call something a helper module I mean a module built to help something else. It's the way you are using the module and nothing special technically.

Here's an example:
http://drupal.org/project/drupalorg
http://cvs.drupal.org/viewvc.py/drupal/contributio...

Matt Farina
Geeks and God Co-Host
www.innovatingtomorrow.net
www.mattfarina.com

Matt Farina
Geeks and God Former Co-Host
www.mattfarina.com

G&G Moderator
shrop's picture
Joined: 07/16/2007
helper module

Heard about this on the Drupal Dev email list. You can create a blank module when creating new sites. This module can hold all of the functions that you need to support that site and cannot stand on their own to make up a complete module by themselves. When you said help module, this is the kind of thing I was thinking about. Seem like a great idea. I have started doing this as needed.

Thanks!
Shrop

Mark Shropshire "shrop"
Geeks & God Forums Moderator
http://geeksandgod.com/users/shrop