Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By serdecue on
Hi, I want insert a new rows in node_access table, and I don't now what is the gid, and the number that I need to write in this column.
Anyone can help me??
Thx
Comments
It's an arbitrary value, it
It's an arbitrary value, it can be whatever it needs to be. But you should never be writing to this table directly. You should be using hook_node_access_records() to write to the table, and hook_node_grants() to determine whether access should be provided based on the values in that table. Read the documentation on those two hooks for more information.
I need write for my app
I try to make an android app and I need to write in this table because if I not write my post don't are visible in the forum. So if I write always in this column the value 4 for example it doesn't matter??
Thx and sorry for my bad English.
You should never write to
You should never write to this table. You should be implementing the hooks I showed you.
I don't explain
I think I don't explain well. I use the drupal date base in a android app, but I need to write in this table with mi java code for seeing the post in the forum, for this I need to know if I write for example 4 in the gid column is wrong or is fine.
Tyx and sorry for my bad english.
If you are using Drupal as a
If you are using Drupal as a base for an app, you should use the Services module, which exposes the Drupal API as a web service. You can then use node_save() to create a node (which will automatically call hook_node_access_records()) and node_load() to load a node (which will automatically call hook_node_grants()).
You should never write directly to the Drupal database. You should always use the Drupal API for this, otherwise you will slowly corrupt your database over time as you miss things that the API would write to the database without you knowing.