Phalcon--model (model)

Source: Internet
Author: User
Tags vars

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?
    1. <span style= "color: #FF0000;" > $this->hasmany (' id ', ' mp\pri\models\rolesusers ', ' Roleid ', Array (' Alias ' = ' rolesusers '));
    2. $this->hasmany (' id ', ' mp\pri\models\rolesmenus ', ' Roleid ', Array (' Alias ' = ' Rolesmenus '));</span>

Phalcon setting allows dynamic updates of data: (When initializing)

[Plain]View Plaincopyprint?
    1. $this->usedynamicupdate (TRUE);

To set the soft delete tag in PHALOCN: (When initializing)

[Plain]View Plaincopyprint?
  1. Use Phalcon\mvc\model\behavior\softdelete;
  2. $this->addbehavior (New Softdelete (
  3. Array
  4. ' Field ' = ' delsign ',
  5. ' Value ' = systemenums::D elsign_yes,
  6. )
  7. ) );
  8. $res = Roles::findfirst ($where)->delete ();
  9. When deciding whether to delete the success or not
  10. if (empty ($res))
  11. {//delete Error
  12. }
  13. Else
  14. {//delete Success
  15. }

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?
  1. $id = $this->request->getpost (' id ');
  2. if (isset ( $id) && FALSE! = $id)
  3. {
  4. $where = Array (
  5. ' conditions ' = ' delsign=:d el:and id=:optid: ',
  6. ' bind ' = = Array ( ' del ' = = systemenums::D elsign_no,' optid ' = $id),
  7. );
  8. $cache = Cache::findfirst ( $where);
  9. $cache->delsign = systemenums::D elsign_yes;
  10. $cache->modtime = Timeutils::getfulltime ();
  11. $cache->title = ' Login ';
  12. $cache->action = ' loadding ';
  13. $cache->seconds = 100;
  14. $cache->module_name = ' appmgr ';
  15. }
  16. Else
  17. {//add
  18. $cache = new cache ();
  19. $cache->title = ' Roles ';
  20. $cache->module_name = ' pri ';
  21. $cache->controller = ' Roles ';
  22. $cache->action = ' list ';
  23. $cache->seconds = 20;
  24. $cache->comment = ' Add Test ';
  25. $cache->createtime = Timeutils::getfulltime ();
  26. $cache->modtime = Timeutils::getfulltime ();
  27. $cache->delsign = systemenums::D elsign_no;
  28. }
  29. if (! $cache->save ()) {  
  30. foreach ($cache->getmessages () as $message) {
  31. echo "Message:", $message->getmessage ();
  32. echo "Field:", $message->getfield ();
  33. echo "Type:", $message-getType ();
  34. }
  35. }
  36. Else
  37. {
  38. echo ' No Error ';
  39. }
  40. exit;

Update data with PHQL:

[PHP]View Plaincopyprint?
  1. $query = $this->modelsmanager->createquery ( ' update \mp\sys\models\cache set title =:tit:,modtime=:time  : Where id =: ID: ');
  2. $res = $query->execute (array (
  3. ' tit ' = $cache _name,
  4. ' id ' = $id,
  5. ' time ' = Timeutils::getfulltime (),
  6. ));

/////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////

The 1.jquery method operates the IFRAME parent element:

[JavaScript]View Plaincopyprint?
    1. <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?
    1. <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?
    1. <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?
    1. <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?
      1. <span style="FONT-SIZE:14PX;" >window.parent.func ();</span>

Phalcon--model (model)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.