jControllerDaoCrudDfk

Extends \jController

a base class for crud controllers, for DAO which have a primary key based on two fields, a "static" field (a field that we know the value and which is a criteria to to select all viewed record), and a "dynamic" field (the value of the field is created by the user or autoincremented)

A controller is used to implement one or many actions, one method for each action.

package

jelix

subpackage

controllers

since 1.1

Methods

__construct

__construct(\jRequest $request) 
inherited

Arguments

$request

\jRequest

the current request object

overload this method if you wan to do additionnal things after the creation of a record. For example, you can handle here the uploaded files. If you do such handling, set the uploadsDirectory property to false, to prevent the default behavior on uploaded files in the controller.

_afterCreate(\jFormsBase $form, mixed $id, \jResponseHtml $resp) 

Arguments

$form

\jFormsBase

the form object

$id

mixed

the new id of the inserted record

$resp

\jResponseHtml

the response

overload this method if you wan to do additionnal things after the update of a record. For example, you can handle here the uploaded files. If you do such handling, set the uploadsDirectory property to false, to prevent the default behavior on uploaded files in the controller.

_afterUpdate(\jFormsBase $form, mixed $id, \jResponseHtml $resp) 

Arguments

$form

\jFormsBase

the form object

$id

mixed

the new id of the updated record

$resp

\jResponseHtml

the response

overload this method if you wan to do additionnal things on the dao generated by the jFormsBase::prepareDaoFromControls method

_beforeSaveCreate(\jFormsBase $form, \jDaoRecordBase $form_daorec) 

Arguments

$form

\jFormsBase

the form

$form_daorec

\jDaoRecordBase

overload this method if you wan to do additionnal things on the dao generated by the jFormsBase::prepareDaoFromControls method

_beforeSaveUpdate(\jFormsBase $form, \jDaoRecordBase $form_daorec, mixed $id) 

Arguments

$form

\jFormsBase

the form

$form_daorec

\jDaoRecordBase

$id

mixed

the new id of the updated record

you can do your own data check of a form by overloading this method.

_checkData(string $spk, \jFormsBase $form, boolean $calltype) : boolean

You can also do some other things. It is called only if the $form->check() is ok. and before the save of the data.

Arguments

$spk

string

the static value of the primary key of the record

$form

\jFormsBase

the current form

$calltype

boolean

true for an update, false for a create

Response

boolean

true if it is ok.

overload this method if you wan to do additionnal things on the response and on the edit template during the create action.

_create(\jFormsBase $form, \jResponseHtml $resp, \jtpl $tpl) 

Arguments

$form

\jFormsBase

the form

$resp

\jResponseHtml

the response

$tpl

\jtpl

the template to display the edit form

overload this method if you want to do additionnal things before the deletion of a record

_delete(mixed $spk, mixed $dpk, \jResponseHtml $resp) : boolean

Arguments

$spk

mixed

the static value of the primary key of the record to delete

$dpk

mixed

the dynamic value of the primary key of the record to delete

$resp

\jResponseHtml

the response

Response

boolean

true if the record can be deleted

overload this method if you wan to do additionnal things on the response and on the edit template during the editupdate action.

_editUpdate(\jFormsBase $form, \jResponseHtml $resp, \jtpl $tpl) 

Arguments

$form

\jFormsBase

the form

$resp

\jResponseHtml

the response

$tpl

\jtpl

the template to display the edit form

returned the selector of the action corresponding of the given method of the current controller.

_getAction(string $method) : string

Arguments

$method

string

name of one of method of this controller

Response

string

an action selector

_getPk

_getPk( $spk,  $dpk,  $dao = null) 

Arguments

$spk

$dpk

$dao

Returned a simple html response to display CRUD contents. You can override this method to return a personnalized response

_getResponse() : \jResponseHtml

Response

\jResponseHtml

the response

overload this method if you wan to do additionnal things on the response and on the list template during the index action.

_index(\jResponseHtml $resp, \jtpl $tpl) 

Arguments

$resp

\jResponseHtml

the response

$tpl

\jtpl

the template to display the record list

overload this method if you wan to do additionnal conditions to the index's select during the index action.

_indexSetConditions(\jDaoConditions $cond) 

Arguments

$cond

\jDaoConditions

the conditions

_isPkAutoIncrement

_isPkAutoIncrement( $dao = null) 

Arguments

$dao

overload this method if you want to do additionnal during the precreate action

_preCreate(\jFormsBase $form) 

Arguments

$form

\jFormsBase

the form

overload this method if you want to do additionnal things during preupdate action

_preUpdate(\jFormsBase $form) 

Arguments

$form

\jFormsBase

the form object

overload this method if you want to do additionnal things on the response and on the view template during the view action.

_view(\jFormsBase $form, \jResponseHtml $resp, \jtpl $tpl) 

Arguments

$form

\jFormsBase

the form

$resp

\jResponseHtml

the response

$tpl

\jtpl

the template to display the form content

same as param(), but convert the value to a boolean value. If it isn't a numerical value, return null.

boolParam(string $parName, mixed $parDefaultValue = null, boolean $useDefaultIfEmpty = false) : boolean
inherited

Arguments

$parName

string

the name of the request parameter

$parDefaultValue

mixed

the default returned value if the parameter doesn't exists

$useDefaultIfEmpty

boolean

true: says to return the default value the value is ""

Response

boolean

the request parameter value

display a form to create a record

create() 

delete a record

delete() 

displays a forms to edit an existing record. The form should be prepared with the preupdate before, so a refresh of the page won't cause a reset of the form

editupdate() 

same as param(), but convert the value to a float value. If it isn't a numerical value, return null.

floatParam(string $parName, mixed $parDefaultValue = null, boolean $useDefaultIfEmpty = false) : float
inherited

Arguments

$parName

string

the name of the request parameter

$parDefaultValue

mixed

the default returned value if the parameter doesn't exists

$useDefaultIfEmpty

boolean

true: says to return the default value the value is ""

Response

float

the request parameter value

get a response object.

getResponse(string $name = '', boolean $useOriginal = false) : \jResponse|\jResponseHtml|\jResponseRedirect|\jResponseJson
inherited

Arguments

$name

string

the name of the response type (ex: "html")

$useOriginal

boolean

true:don't use the response object redefined by the application

Response

\jResponse|\jResponseHtml|\jResponseRedirect|\jResponseJson

the response object

list all records

index() 

same as param(), but convert the value to an integer value. If it isn't a numerical value, return null.

intParam(string $parName, mixed $parDefaultValue = null, boolean $useDefaultIfEmpty = false) : integer
inherited

Arguments

$parName

string

the name of the request parameter

$parDefaultValue

mixed

the default returned value if the parameter doesn't exists

$useDefaultIfEmpty

boolean

true: says to return the default value the value is ""

Response

integer

the request parameter value

Gets the value of a request parameter. If not defined, gets its default value.

param(string $parName, mixed $parDefaultValue = null, boolean $useDefaultIfEmpty = false) : mixed
inherited

Arguments

$parName

string

the name of the request parameter

$parDefaultValue

mixed

the default returned value if the parameter doesn't exists

$useDefaultIfEmpty

boolean

true: says to return the default value if the parameter value is ""

Response

mixed

the request parameter value

params

params() : array
inherited

Response

array

all request parameters

prepare a form to create a record.

precreate() 

prepare a form in order to edit an existing record, and redirect to the editupdate action

preupdate() 

save data of a form in a new record

savecreate() 

save data of a form in a new record

saveupdate() 

displays a record

view() 

Properties

name of the request parameter and of the field in the dao, for the dynamic primary key

dpkName : 

Type(s)

name of the request parameter and of the field in the dao, for the static primary key

spkName : 

Type(s)

selector of the dao to use for the crud.

dao : string

It should be filled by child controller.

var

Type(s)

string

selector of the form to use to edit and display a record It should be filled by child controller.

form : string
var

Type(s)

string

list of properties to show in the list page if empty list (default), it shows all properties.

propertiesForList : array

this property is only usefull when you use the default "list" template

var

Type(s)

array

list of properties which serve to order the record list.

propertiesForRecordsOrder : array

if empty list (default), the list is in a natural order. keys are properties name, and values are "asc" or "desc".

var

Type(s)

array

template to display the list of records

listTemplate : string
var

Type(s)

string

template to display the form

editTemplate : string
var

Type(s)

string

template to display a record

viewTemplate : string
var

Type(s)

string

number of record to display in the list page

listPageSize : integer
var

Type(s)

integer

the template variable name to display a CRUD content in the main template of the html response

templateAssign : string
var

Type(s)

string

name of the parameter which contains the page offset, for the index action

offsetParameterName : string
var

Type(s)

string

id for the "pseudo" form used to show a record. You can change it if the default one corresponds to a possible id in your dao.

pseudoFormId : string
var

Type(s)

string

full path to the directory where uploaded files will be stored automatically by jForms.

uploadsDirectory : string|false

Set it to false if you want to handle yourself the uploaded files. Set it with an empty string if you want to stored files in the default var/uploads directory.

var

Type(s)

string|false

the jDb profile to use with the dao

dbProfile : 

Type(s)

parameters for plugins of the coordinator

pluginParams : array
inherited

this array should contains all parameters needed by installed plugins for each action, see the documentation of each plugins to know this parameters. keys : name of an action or * for parameters to all action values : array that contains all plugin parameters

var

Type(s)

array

sensitive parameters

sensitiveParameters : 
inherited

List of names of parameters that can have sensitive values like password etc. This list is used by the logger for example, to replace values by a dummy value. See also sensitiveParameters into error_handling section of the configuration.

since

Type(s)

the request object

request : \jRequest
inherited
var

Type(s)

\jRequest