Model:
Table-to-table relationships:
HasOne one-to-one ($fields, $referenceModel, $referencedFields: field in the current table, corresponding relationship model, corresponding to the word field of the table in the relational model)
Hasmany one-to-many ($fields, $referenceModel, $referencedFields: Fields in the current table, corresponding relationship models, corresponding to the word fields of the table in the relational model)
Hasmanytomany Many-to-many
Belongsto (belonging to) ($fields, $referenceModel, $referencedFields: Fields in the current table, corresponding relationship models, corresponding to the word fields of the table in the relational model)
If the namespace exists in the project, add the alias parameter array to the corresponding relationship (' Alias ' = ' namespace ')
[Plain]View Plaincopyprint?
- <span style= "color: #FF0000;" > $this->hasmany (' id ', ' mp\pri\models\rolesusers ', ' Roleid ', Array (' Alias ' = ' rolesusers '));
- $this->hasmany (' id ', ' mp\pri\models\rolesmenus ', ' Roleid ', Array (' Alias ' = ' Rolesmenus '));</span>
Phalcon setting allows dynamic updates of data: (When initializing)
[Plain]View Plaincopyprint?
- $this->usedynamicupdate (TRUE);
To set the soft delete tag in PHALOCN: (When initializing)
[Plain]View Plaincopyprint?
- Use Phalcon\mvc\model\behavior\softdelete;
- $this->addbehavior (New Softdelete (
- Array
- ' Field ' = ' delsign ',
- ' Value ' = systemenums::D elsign_yes,
- )
- ) );
- $res = Roles::findfirst ($where)->delete ();
- When deciding whether to delete the success or not
- if (empty ($res))
- {//delete Error
- }
- Else
- {//delete Success
- }
Project multi-module and exists named: (Cross-module fetch data)
Because a namespace problem exists for a class, if it is saved to an object, the data will not be available to the session when the data is fetched------workaround save the data in the session
Phalcon Add/Update data:
[PHP]View Plaincopyprint?
- $id = $this->request->getpost (' id ');
- if (isset ( $id) && FALSE! = $id)
- {
- $where = Array (
- ' conditions ' = ' delsign=:d el:and id=:optid: ',
- ' bind ' = = Array ( ' del ' = = systemenums::D elsign_no,' optid ' = $id),
- );
- $cache = Cache::findfirst ( $where);
- $cache->delsign = systemenums::D elsign_yes;
- $cache->modtime = Timeutils::getfulltime ();
- $cache->title = ' Login ';
- $cache->action = ' loadding ';
- $cache->seconds = 100;
- $cache->module_name = ' appmgr ';
- }
- Else
- {//add
- $cache = new cache ();
- $cache->title = ' Roles ';
- $cache->module_name = ' pri ';
- $cache->controller = ' Roles ';
- $cache->action = ' list ';
- $cache->seconds = 20;
- $cache->comment = ' Add Test ';
- $cache->createtime = Timeutils::getfulltime ();
- $cache->modtime = Timeutils::getfulltime ();
- $cache->delsign = systemenums::D elsign_no;
- }
- if (! $cache->save ()) {
- foreach ($cache->getmessages () as $message) {
- echo "Message:", $message->getmessage ();
- echo "Field:", $message->getfield ();
- echo "Type:", $message-getType ();
- }
- }
- Else
- {
- echo ' No Error ';
- }
- exit;
Update data with PHQL:
[PHP]View Plaincopyprint?
- $query = $this->modelsmanager->createquery ( ' update \mp\sys\models\cache set title =:tit:,modtime=:time : Where id =: ID: ');
- $res = $query->execute (array (
- ' tit ' = $cache _name,
- ' id ' = $id,
- ' time ' = Timeutils::getfulltime (),
- ));
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////
The 1.jquery method operates the IFRAME parent element:
[JavaScript]View Plaincopyprint?
- <span style="FONT-SIZE:14PX;" >$ ("#rolesCtl", parent.document). Find ( ' button '). Trigger ( ' click ');</span>
2. jquery Gets the elements of the IFRAME child page on the parent page:
[JavaScript]View Plaincopyprint?
- <span style="FONT-SIZE:14PX;" >$ ("#objid", Document.frames (' Iframename '). Document) </span>
3.js Gets the parent page element code in the IFRAME sub-page as follows:
[JavaScript]View Plaincopyprint?
- <span style="FONT-SIZE:14PX;" >window.parent.document.getelementbyidx_x ("Element id");</span>
4.js gets the IFRAME child page element on the parent page:
[JavaScript]View Plaincopyprint?
- <span style="FONT-SIZE:14PX;" >window.frames["iframe_id"].document.getelementbyidx_x ("element ID");</span>
5. Call the parent class function inside the subclass IFRAME:
[JavaScript]View Plaincopyprint?
- <span style="FONT-SIZE:14PX;" >window.parent.func ();</span>
Phalcon--model (model)