Giter VIP home page Giter VIP logo

octobercms-plugin-import's Introduction

Import plugin

Helper plugin to simplify the import of data from php, yaml and xml files.

You need to create your own import class like this:

<?php namespace YourNamespace\YourPlugin\Classes;

use Utopigs\Import\Classes\Import as BaseImport;

class Import extends BaseImport
{
    public function __construct()
    {
        $this->path = base_path('import/');
    }

    public function importCategories()
    {
        $result = $this->loadImportFile('categories.yaml');

        $this->importModel('\YourNamespace\YourPlugin\Models\Category', $result);
    }

    public function importTags()
    {
        $result = $this->loadImportFile('tags.yaml');

        $this->importModel('\YourNamespace\YourPlugin\Models\Tag', $result);
    }

    public function importPosts()
    {
        $result = $this->loadImportFile('posts.yaml');

        $this->importModel('\YourNamespace\YourPlugin\Models\Post', $result, ['tags'], ['image']);
    }
}

Check the documentation in the plugin Utopigs\Import\Classes\Import class for information about the available parameters for this methods. If you need more advanced import options, you can copy the code in your own import class and modify it as needed.

In your website root folder you should have an 'import' folder with this content:

categories.yaml:

- title: 'Category 1'
- title: 'Category 2'

tags.yaml: - title: 'Tag 1' - title: 'Tag 2' - title: 'Tag 3' - title: 'Tag 4'

posts.yaml: - title: 'Post 1 title' text: >

Some html text

More text

category_id: 1 tags: [1,2,3] image: 'post1-picture.jpg' - title: 'Post 2 title' text: >

Some html text

More text

category_id: 2 tags: [1,2,3] image: 'post2-picture.jpg'

Then you can import your data like this:

$import = new \YourNamespace\YourPlugin\Classes\Import;
$import->importCategories();
$import->importTags();
$import->importPosts();

octobercms-plugin-import's People

Contributors

mariavilaro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.