ATM using cli will generate some errors, here is how to solve them.
In order to create a module from cli you need to do something like this from the console:
php -f tbg_cli create_module MODULE_NAME
this will generate some errors like:
- Declaration of MODULE_NAME::_initialize() must be compatible with that of TBGModule::_initialize()
- this can be fixed by removing the parameter from _initialize in your class file (class/MODULE_NAME.class.php)
- also be sure to remove the setters in the init function, they are also depreciated
- Anotation @Table missing
- just add this before the class definition in your class file
/**
* @Table(name="TBGModulesTable")
*/
In order to be able to create tables you need to create (if it dose not exist) a folder named B2DB in your class folder and include the table definition there as a class.php file like so:
+class
+ B2DB
- MyTable.class.php
...
MyTable.class.php :
use b2db\Core,
b2db\Criteria,
b2db\Criterion;
/**
* @Table(name="my_table_name")
*/
class MyTable extends TBGB2DBTable{
const B2DB_TABLE_VERSION = 1;
const B2DBNAME = 'my_table_name';
const ID = 'my_table_name.id';
const TEXT = 'my_table_name.a_text_field';
const SCOPE = 'my_table_name.a_relate_field_to_scopes';
protected function _initialize()
{
parent::_setup(self::B2DBNAME, self::ID);
parent::_addText(self::TEXT);
parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
}
}
all the methods to add text,varchar,int, etc can be found in class Table (core/B2DB/Table.class.php)
No comments:
Post a Comment