Special Functions


A look at the functions used throughout Zera

Zera uses many special functions that should be taken into account.

Sess

Returns the session variable for the user. If the user deletes it's cookies, the information is lost.

$self->sess($var_name);

Assigns a value for the user's session variable.

$self->sess->($var_name, $new_value);

Database

This function is used to execute any SQL query on the database, most commonly used for inserting, update and delete operations. The $param1, $paramx… parameters are optional.

$self->dbh_do(“SQL”,{},$param1, $param2, $paramx);

This function returns the value of the specified field in the last inserted record. Use this function after any insert SQL query to get the recently insert auto increment id.

$self->last_insert(“$table_name”,”$field_name”);

This function returns one row of the query results in the form of an arrayref where each array value are the fields of the row.

$self->selectrow_arrayref(“SQL SELECT ”,{},$param1, $param2, $paramx);

Pretty similar to selectrow_array, but returns the results as a hash.

$self->selectrow_hashref(“SQL SELECT ”,{},$param1, $param2, $paramx);

You can read the data as an array of hashes.

$self->selectall_arrayref(“SQL”,{Slice=>{}},$param1, $param2, $paramx);

$self->selectall("SQL SELECT ", $param1, $param2, $paramx);

Messages

You can send messages to the user throught functions. Valid types are warning, info, danger, success.

$self->add_msg("$type", "$Message");

Saves a message that leter be shown to the user. $type corresponds to a Bootstrap color.

$self->get_msg();

Shows all the saved messages by add_msg in the form of Bootstrap alerts where the function <% msg %> is located in the HTML template.

Lists

Prints the form in a template named after its function.

my $list = Zera::List->new($self->{Zera},{
   sql => {
      select => "$select",
      from =>"$tables",
      order_by => "$order",
      where => $where,
      params => \@params,
      limit => "$limit",
   },
   link => {
      key => "$keyvalue",
      hidde_key_col => 1, #hidde or show key column
      location => '$location',
      transit_params => {},
   },
   debug => 1,
});
$list->get_data();

Selects the specified data from the database to show them as a list.

$list->columns_align(['left','left','center']);

Tells the alignment of the columns.

my $vars = {
   list => $list->print(),
};
return $self->render_template($vars);

Prints the list in a template named after its function.