0
votes

At the moment I have a module which can upload a file, extract it, reads some files and stores it in a database. Since I’m just a PHP developer and not a Drupal developer I’m not common with Content Types , Views and other Drupal stuff. I just want to display some things from the database to multiple pages and edit some things (not everything).

Doing it in PHP would be as easy as putting a brief in an envelope, but in Drupal it’s like you are putting a wheelchair in that envelope.

Do I have to define a content type for it?

Is it easy if I don’t use content types and having permissions controlled manually?

Supposing that I have to define a content type. My database has 5 tables. Should I define 5 different content types?

2

2 Answers

2
votes

You don't have to do it the Drupal way, if you need some Drupal things to work on you data too. I also have developed a module. It accesses a database, displays data from it, then an authorized user can update data and my module will save it. But these will not be nodes. Unless you need (for example) some hooks that run on nodes to run on your content, just use your PHP knowledge to create the content for the page.

You use hook_menu to define the paths that will display your pages. For example in my code (detail_pages module) the queries get two parameters in the path like example.com/strain/3/4, I define it like as follows, and I used php calls to database in my detail_page($arg1, $arg2) function definition.

function detail_pages_menu() {
  $items = array();
  $items['strain/%/%'] = array(
      'title' => t('Strain Detail Page'),
      //'page callback' => 'strain_form',
      'page callback' => 'detail_page',//'drupal_get_form',
      //'page arguments' => array('strain_detail_form'),
      'page arguments' => array(1,2),
      'access callback' => TRUE,
      'access arguments' => array('access content'),
      'description' => t('Detail Page'),
      'type' => MENU_NORMAL_ITEM,
  );
....

To answer your specific questions

Do I have to define a content type for it?

No. You can use page render array, or even add direct html to pages in PHP.

Is it easy if I don’t use content types and having permissions controlled manually?

Yes. In the above example I wrote, this line is for permissions: 'access callback' => TRUE this allows everybody to view. You can assign a function in place of TRUE, to return a boolean to represent if user it authorized to view that page.

Supposing that I have to define a content type. My database has 5 tables. Should I define 5 different content types?

Especially if you need a nice database structure, you may want to avoid using nodes and defining content types. Drupal creates a table for what would be a column logically keyed by node ID. So you have many unnecessary tables...

0
votes

There are a lot of ways to achieve what you want. From your description, I perceive that you want to show some information on some pages (don't really know what you meant with "edit some things").

  1. You could have a block (=defined area on multiple pages) In Drupal, you can use rules or PHP to control, which pages (e.g. on content type "Page") the block will appear.
  2. Content type with custom node structure Similar to page.tpl.php and node.tpl.php (might confuse extensions here, it's been a while) that define the structure of certain parts a theme consists of, you can have your content-type-node show whatever information you want using PHP, HTML and CSS. (Like a wrapper for all objects of that content type)
  3. Panels Panels are used to split pages. Your menu items could point to individual panels, where e.g. the upper part of the page is a static "Page" (=node of that content type) and the lower part is another "Page", which contains PHP code to display your information.

In all three options, you can show personalized data, meaning, that you have global variables that tell you the user id, name, role, etc. to load specific data from the DB and present it accordingly.

Conclusion: Content types make everything easier to organize, but if you only have one instance (=node) of that type/structure, you can just put your code in a "Page".

Feel free to ask for more details.