XF 2.1 add route filter via php

tom3

Active member
i would like to use a php script to add different route filters, which works pretty well. the filter is taken over into the database as well as into the acp, but the page to be called always says that it doesn't exist? have i missed something?

my sql statement:
PHP:
$q = $db->query('INSERT INTO xf_route_filter (prefix, find_route, replace_route, enabled, user_id) VALUES ("resources", "resources/authors/'.$user[0]["user_id"].'/", "'.$_POST["url_value"].'/", 1, '.$user[0]["user_id"].')');
 
seems like disabling and enabling it through acp will make it work. tried to disable/activate it through sql statement but that doesn't seem to work
 
  1. You are not escaping the input aka causing SQL injection; To fix that use prepared statements.
  2. Route filter has an entity ready so you could fetch an entity, So you can use the entity manager to set the values safely and at the same time it will rebuild route filters cache so you don't have to manually enable/disable routes in ACP
  3. Extend the XF\Entity\RouteFilter's structure
  4. Use \XF::visitor() to get the current visitor instead of weird $user you got there
 
  1. You are not escaping the input aka causing SQL injection; To fix that use prepared statements.
  2. Route filter has an entity ready so you could fetch an entity, So you can use the entity manager to set the values safely and at the same time it will rebuild route filters cache so you don't have to manually enable/disable routes in ACP
  3. Extend the XF\Entity\RouteFilter's structure
  4. Use \XF::visitor() to get the current visitor instead of weird $user you got there
well, thank you but my php experience is not good enough to understand a word 🥶
 
Why are you manually inserting the data using a query?

Why can't you use the UI in the ACP?
 
Top Bottom