官术网_书友最值得收藏!

Updating an existing page

Updating pages is similar to creating them in that you must first pass in an associative array containing all of the data that you wish to update on the page.

Getting ready

In this recipe, we will be modifying a page with the path of /about. We created that page in the previous recipe, but if it does not exist on your system, please adapt the code to your needs.

How to do it...

In this example, we will update the name of the About page. The steps are as follows:

  1. First, we need to load the Page object by its path.
    $page = Page::getByPath('/about');
  2. Create an associative array with the data that you wish to update.
    $data = array(
      'cName' => 'About Our Company'
    );
  3. Pass the data array into the $page object's update function.
    $page->update($data);
  4. Output a success message and exit the process.
    echo 'done!';
    exit;

How it works...

The update function updates the necessary tables in the database with the newly specified information. concrete5 will also rescan all permissions for this page and all of the related page paths. When the function is complete, the on_page_update event is fired, which you can write custom code to listen to and perform custom actions when a page is updated. Listening to system events is covered in a later chapter.

There's more...

Just like creating a page, you will need to pass an associative array to the update() function in order to update an existing page. You can use all of the fields specified in the previous recipe for adding a page, in addition to these other optional fields.

See also

  • The Creating a page type recipe
主站蜘蛛池模板: 邢台市| 沅江市| 柳江县| 霍林郭勒市| 临潭县| 略阳县| 门源| 阳西县| 兴宁市| 灵山县| 盖州市| 兴隆县| 白银市| 丹凤县| 浮梁县| 恭城| 太湖县| 隆尧县| 孟津县| 阿拉善左旗| 大兴区| 沙坪坝区| 沿河| 大渡口区| 滦平县| 新昌县| 桓仁| 榆树市| 夏河县| 昂仁县| 河间市| 林甸县| 长沙市| 关岭| 教育| 锡林郭勒盟| 闻喜县| 屏山县| 铁力市| 康乐县| 洪洞县|