Extends Grand



( ZN >= 4.3.7

Grand Extension was made by planning on the model files. Objective To provide you to develop more practical model libraries by reducing the database methods to the table level. Almost DB :: , dbForge :: and DBTool :: most of which are located in the libraries method. Under this heading will be shown how to expand the Grand.

 

 

# Section Headings


# Creating a Grand Model File
# Methods with Grand Library

 

 

# Creating Grand Model File


The class name of your model files that you will expand with Grand should be used with the name of the corresponding table. If your table name conflicts with the name of one of the existing libraries, you can bring the Grand final element at the end of the model class name. Or you can specify the name of the tab associated with the  constant. If you want to make different connection settings, you can do it with a fixed array. Now create a sample Grand Model file.const table = 'tablo_adi'const connection = []

Fixed Configuration
String table = __CLASS__ If the class name is different from the table name, this constant table name must be given. Predefined class name is accepted.
Array connection = [] If the table is in a different database and connection settings need to be made, this must be fixed.
Use of
File:  Models / Example.php
<?php
class Example extends GrandModel
{
    // Eğer sınıf adı ile tablo adı farklı ise
    // const table = 'TabloAdi'; ile farklı bir
    // tablo adı belirtebilirsiniz.
    const table = 'Examples';
} 

Note that if the table name is different, you can specify the table name with the  table constant  . If this is not fixed, the table name will  be set to Example  .

If you want to connect to a different database, you can use a fixed array.const connection = []

File:  Models / UserGrand.php
<?php
class UserGrand extends GrandModel
{
    const table      = 'Example';

    const connection = 
    [
        'database' => 'otherDatabase',
        'user'     => 'MyDB',
        'password' => '1234'
    ];
}

If the name of the table conflicts with a class name, it is recommended that you use the Grand final element in the end .

File: Models / UserGrand.php
class UserGrand extends GrandModel
{

}

You can also define internal pre-export model files.

File:  Models / UserGrand.php
class InternalUserGrand extends GrandModel
{

}

In the above usage, the table name will be treated as  "user" .

 

 

# Methods coming with Grand Library


The Grand Library DB ::, DBForge :: and DBTool :: methods are used. These methods will not be re-sampled because they are exemplified in the Database Library section. An example will be given of how to use it only with the model library.

Bool create ( Array $ data , $ extra = NULL )
Bool insert ( Array $ data )
Int insertıd ()
this duplicateCheck ( ... $ args )
this duplicateCheckUpdated ( ... $ args )
this select ( ... $ select )
Bool updateColumnName ( Array $ data , String $ value )
Bool update ( Array $ data , String $ column , String $ value )
Bool deleteColumnName ( String $ value )
Bool delete ( String $ column , String $ value )
Object rowcolumnn tool ()
Object resultcolumnn tool ()
Mixed row ( $ printable = false )
Mixed result ( String $ type = 'object' )
Array columns ()
Int totalcolumns ()
Bool increment ( $ columns , Int $ increment = 1 )
Bool decrement ( $ columns , Int $ decrement = 1 )
Mixed status ( String $ type = 'row' )
Int totalrows ( Boolean $ status = false )
this where ( $ column , String $ value = NULL , String $ logical = NULL )
this whereGroup ( ... $ args )
this having ( $ column , String $ value = NULL , String $ logical = NULL )
this havingGroup ( ... $ args )
this innerJoin ( String $ table , String $ otherColumn , String $ operator = '=' )
this outerJoin ( String $ table , String $ otherColumn , String $ operator = '=' )
this leftJoin ( String $ table , String $ otherColumn , String $ operator = '=' )
this rightJoin ( String $ table , String $ otherColumn , String $ operator = '=' )
this orderBy ( $ condition , String $ type = NULL )
this groupBy ( ... $ args )
this limit ( $ start = 0 , Int $ limit = 0 )
String pagination ( String $ url = NULL , Array $ settings = [] , Bool $ output = true )
Bool rename ( String $ newName )
Bool addColumn ( Array $ column )
Bool modifyColumn ( Array $ column )
Bool renameColumn ( Array $ column )
Bool dropColumn ( $ column )
String optimize()
String repair ()
String backup ( String $ fileName = NULL , String $ path = STORAGE_DIR)
Bool drop ()
Bool truncate ()
String error ()

 

 

# Create ( ZN> = 5.3.72 )


If  we assume that we create a model class like the InternalUserGrand model created above, we can use the above methods with this library. You can use the columns as a method. With this usage, the first parameter of the create () method is now used as the second parameter of the same method .

Parameters
Array $ data Table column and value information.
Array $ extras Expressions to add at the end of the table creation process.
return Bool
Use of
Create Model File:  Models / UserGrand.php
<?php
class InternalUserGrand extends GrandModel
{

}
File: Controllers / ExampleController.php
UserGrand::id([DB::int(11), DB::primaryKey(), DB::autoIncrement()])
         ->name([DB::varchar(255), DB::null()])
         ->address([DB::text()])
         ->create(DB::encoding())
CREATE TABLE user
(
    id INT ( 11 ) PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR ( 255 ) NULL ,
    address TEXT
)
CHARACTER SET utf8 COLLATE utf8_general_ci;

 

 

# Insert ( ZN >= 5.3.7 )


Used to insert data into a table. Columns to be added data can also be used as a method. The following example is about this usage.

Parameters
Array $ data Included.
return Bool
Use of
UserGrand::name('ZN Framework')->address('Istanbul')->insert();

output(UserGrand::result());
0 => object
(
        id => string '1' (length = 3 )
        name => string "ZN Framework ' (length = 14 )
        address => string ' Istanbul / Turkey ' (length = 17 )
)
Auto Match

If the incoming data hide or See and if the forum input names are used as column names, a much simpler insert operation can be done as follows.

UserGrand::insert('post');

 

 

# InsertID ( ZN> = 4.0.1 )


Returns the ID of the last inserted data.

Parameters
void
return Int
Use of
UserGrand::insert
([
    'name'    => 'ZN Framework',
    'address' => 'Istanbul/Turkey'
]);

output(UserGrand::insertID());
one

 

 

# DuplicateCheck ( ZN >= 4.0.1 )


If there is the same individual data previously inserted, it will not be added again.

Parameters
String ... $ args = NULL It is specified which columns to check. If no column is specified, all columns are checked.
return this
Use of
UserGrand::duplicateCheck()->insert
([
    'name'    => 'ZN Framework',
    'address' => 'Istanbul/Turkey'
]);

output(UserGrand::result());
0 => object
(
        id => string '1' (length = 3 )
        name => string "ZN Framework ' (length = 14 )
        address => string ' Istanbul / Turkey ' (length = 17 )
)

 

 

# DuplicateCheckUpdate ( ZN >= 4.3.7 )


If there is the same individual data previously inserted, it will not be added again. It will update instead.

Parameters
String ... $ args = NULL It is specified which columns to check. If no column is specified, all columns are checked.
return this
Use of
UserGrand::duplicateCheckUpdate()->insert
([
    'name'    => 'ZN Framework',
    'address' => 'Istanbul'
]);

output(UserGrand::result());
0 => object
(
        id => string '1' (length = 3 )
        name => string "ZN Framework ' (length = 14 )
        address => string ' Istanbul ' (length = 17 )
)

 

 

# Select ( ZN> = 4.0.1 )


Used to decide which columns appear in query results.

Parameters
String ... $ columns Which columns are requested. If this parameter is not specified, all columns are listed.
return this
Use of
$result = UserGrand::select('id', 'name')->result();

output($result);
0 => object
(
        id => string '1' (length = 3 )
        name => string "ZN Framework ' (length = 14 )
)

 

 

# UpdateColumnName ( ZN >= 4.5.1 )


The table is used to update the data according to the column suffix.

Parameters

Array $ data Updated to be exported.
scaler $ Value Column value.
return Bool
Use of
UserGrand::updateId
([
    'name'    => 'ZERONEED',
    'address' => 'Istanbul/Turkey'
], 1);

 

 

# Update ( ZN >= 5.3.7 )


Tabloda is used to update any data. Columns to be updated data can also be used as a method. The following example is about this usage.

Parameters
Array $ data Updated to be exported.
String $ columna Column name.
scaler $ Value Column value.
return Bool
Use of
UserGrand::name('ZN')->address('Istanbul/Turkey')->updateName('ZN Framework');

output(UserGrand::result());
0 => object
(
        id => string '1' (length = 3 )
        name => string "ZN" (length = 10 )
        address => string 'Istanbul / Turkey' (length = 17 )
)
Auto Match

If the incoming data hide or See and if the forum input names are used as column names, a much simpler update operation can be done as follows.

UserGrand::update('post');

 

 

# DeleteColumnName ( ZN> = 4.5.1 )


It is used to delete data according to the column suffix in the table.

Parameters
String $ Value Column value.
return Bool
Use of
UserGrand::deleteId(1);

 

 

# Delete ( ZN> = 4.0.1 )


Tabloda is used to delete any data.

Parameters
String $ columna Which column.
scaler $ Value Column value
return Bool
Use of
UserGrand::delete('id', 1);

output(UserGrand::result());
empty

 

 

# RowColumnName ( ZN >= 4.4.7 )


It is used to record 1 line according to the name of any column in the table .

Parameters
String $ Value Column value.
return Object
Use of
output( UserGrand::rowId(1) );
output( UserGrand::rowName('example') );
output( UserGrand::rowEmail('example@example.com') );

 

 

# ResultColumnName ( ZN> = 4.4.7 )


It is used to retrieve records according to the name of any column in the table.

Parameters
String $ Value Column value.
return Object
Use of
output( UserGrand::resultId(1) );
output( UserGrand::resultName('example') );
output( UserGrand::resultEmail('example@example.com') );

 

 

# AddColumn ( ZN >= 5.3.7 )


The table is used to insert the column. StandardAddColumn ()Methodological columns may also be used. It is possible to attach the column with the method name. You only need to specify the name of the column to be added to the method name and the properties of the parameter.

Parameters
Array $ columna Column and column properties to be added.
return this
Use
UserGrand::address([DB::text()])->date([DB::datetime()]);

 

 

# ModifyColumn ( ZN >= 5.3.7 )


Used to update column properties in the table. It is also possible to update the column with the method name. All you have to do is specify the name of the column to be updated and the properties of the parameter to be updated. If there are no columns to update, it will add.

Parameters
Array $ columna Column and column properties to be updated.
return this
Use
UserGrand::address([DB::varchar(500)])->date([DB::timestamp()]);

 

 

# RenameColumn ( ZN >= 5.3.7 )


It is used to update the column name in the table. It is also possible to update the column name with the method name. All you have to do is specify the name of the column to be updated and the properties of the parameter to be updated.

Parameters
Array $ columna Column name and column properties to be updated.
return this
Use
UserGrand::date(['adddate', DB::timestamp()]);

 

 

# DropColumn ( ZN >= 5.3.7 )


Tablodan is used to wipe the column. The method is also possible without the name column and the column. You only need to NULLspecify the name of the column to delete in the name of the method you need to do.

Parameters
String $ columna Column name to be erased.
return Bool
Use
UserGrand::address(NULL)->adddate(NULL);