wegorz23 Posted November 7, 2018 Posted November 7, 2018 Hello, I created my own hook. This hook has the task of entering the value into the database. My code looks like this : //<?php /* To prevent PHP errors (extending class does not exist) revealing path */ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) ) { exit; } class hook57 extends _HOOK_CLASS_ { /** * Process create/edit form * * @param array $values Values from form * @return void */ public function processForm( $values ) { if(static::$customDatabaseId == 30) { $values['field_157'] = 1; } parent::processForm( $values ); } } But when I add a record, I get an error : IPS \ Db \ Exception (1366) Incorrect integer value: '' for column 'field_157' at row 1 Why is this happening?
bfarber Posted November 8, 2018 Posted November 8, 2018 You need to make the hook extend the actual records class that it needs to work with, or else static::$customDatabaseId won't be set. So, for example, if you are working against database ID #3, then you would extend \IPS\cms\Records3. This class is automatically created (via eval()) from applications/cms/Application.php right at the top of the file in the spl_autoload_register() definition for reference. There is a different class for each database (there is also \Comment3, Review3, Categories3, RecordsTopicSync3, CommentTopicSync3, and Fields3 with the database ID 3 example here for reference).
wegorz23 Posted November 9, 2018 Author Posted November 9, 2018 @bfarber When I extends class to \IPS\cms\RecordsMYID , it does not work at all. I tried to use var_dump(), but it is not displayed. Earlier with extends class \IPS\cms\Records, var_dump worked.
wegorz23 Posted November 9, 2018 Author Posted November 9, 2018 Ok I resolved this problem. It turned out that the permissions to write this this field in ACP were off.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.