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

  • concrete5 Cookbook
  • David Strack
  • 250字
  • 2021-08-13 16:16:03

Loading a file by its ID

The most common interaction with files for most concrete5 developers is loading files and interacting with them. To do this, we must load a file by its ID. The code in this recipe can be placed wherever you need to load a file and retrieve or modify its attributes.

Getting ready

We will need to know the ID of the file that we are loading. In this recipe, we will load a file with the ID of 17. If your concrete5 site does not have a file with an ID of 17, upload a new file to the file manager and change the ID in this recipe to match the ID of the newly uploaded file. You can get the ID of a file by visiting the file manager, clicking on a file, and choosing Properties.

How to do it...

Have a look at the following steps:

  1. Open /config/site_post.php in your code editor, or place this code, wherever it is appropriate in your own application.
  2. Declare the ID of the file to load and be sure to set this to something relevant for your system:
    $fileId = 17;
  3. Load the file:
    $file = File::getByID($fileId);
  4. Dump the contents of the file variable:
    my_debug($file);

How it works...

concrete5 will use this function to load the relevant file from the database, based on the numeric ID that you passed in. The static getByID function will return a fully loaded file object that you can work further with.

主站蜘蛛池模板: 紫阳县| 沂源县| 通化县| 任丘市| 赣榆县| 久治县| 宁波市| 杭锦后旗| 读书| 义马市| 舒兰市| 敖汉旗| 邓州市| 平远县| 二手房| 龙井市| 海丰县| 夏河县| 安阳县| 日喀则市| 双鸭山市| 镇沅| 松桃| 安康市| 万源市| 前郭尔| 花莲市| 万山特区| 海宁市| 建阳市| 呼和浩特市| 长春市| 丰原市| 富川| 鄯善县| 斗六市| 北宁市| 苏尼特右旗| 沁源县| 当雄县| 城口县|