Jump to content

Community

  • We are moving our Documentation to our new Guides area.

    As articles are moved they will be deleted. Please start following the new guides. We look forward to publishing all our new guides soon!

  • Sign in to follow this  

    Changes to the File System in 4.0.5+ (Affects themes, custom blocks and more)


    Matt

    For the IPS4.0.5 release, we changed how files are stored and loaded within the suite. Previously we stored the entire URL which was convenient but it made it problematic when you moved your community or tried to move images to another system such as Amazon S3.

    From 4.0.5 onwards, just the container and file name is stored in the database. This is much better for the database as it means you do not need to update your database when you change your URL and it's easier to move the files as there are no database changes to update.
    However, it does mean that you need to change how you display images in many cases.

    For example, if you had something like this:

    <strong>{$member->group['icon']}</strong>

    You'll notice that now it is just a broken image. You can use the new {file} tag to display it, like this:

    <strong>{file="$member->group['icon']" extension="core_Theme"}</strong>

    This will now display correctly. The extension parameter is mapped to the FileStorage extension found in /applications/{app}/extensions/core/FileStorage.

    So, for example, if you are managing gallery Images, the extension is gallery_Images. If you're managing Pages records, the extension is cms_Records.

    When writing code, you will need to be mindful of the changes. From IPS4.0.5 on newer, you will need to use code similar to this below:

    # Create and save (this is largely the same)
    $file = \IPS\File::create( 'core_Theme', 'file.txt', $contents );
    # Calling (string) on $file now returns just the container/file.txt e.g. (monthly_04_2015/file.txt)
    \IPS\Db::i()->insert( 'table', array( 'url' => (string) $file ) );
    
    # Load and show
    $row = \IPS\Db::i()->select( '*', 'table', array( 'file=?', 'file.txt' ) );
    # We now have the container/file.txt, but we need the full URL
    $url = \IPS\File::get( 'app_Extension', $row['url'] )->url;
    print "<a href='{$url}'>";

    The most important part to keep in mind is that (string) $file will now store just container/file.txt and you need to call \IPS\File::get( 'app_Extension', $row['url'] )->url to get the full URL.

    Sign in to follow this  


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...