<p>Nevermind. <a href="https://github.com/clearbold/craftimport" rel="nofollow">Clearbold's Craft Import</a> plugin has the starting code for it.</p>

<pre class="lang-php prettyprint-override"><code>// new entry
$entry = new EntryModel();
$entry-&gt;sectionId = 1;
$entry-&gt;typeId    = 12;
$entry-&gt;authorId  = 123;
$entry-&gt;enabled   = true;
$entry-&gt;getContent()-&gt;title = "Here goes my title!";

// new matrix and matrix block
$block = array();
$block['new1'] = array(
    'type' =&gt; 'body',
    'enabled' =&gt; true,
    'fields' =&gt; array(
        'text' =&gt; 'Here goes my article.'
    )
);

// add content to entry including created matrix
$entry-&gt;setContentFromPost(array(
    'description' =&gt; "And of course the description...",
    'matriz' =&gt; $block,
));

// save entry
$success = craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

CC BY-SA 3.0
2016-08-10T20:09:42.010Z
2016-08-10T20:09:42.010Z
cballenar
<p>I'm working on importing a database and I was looking at some of the available import plugins. However I am unable to figure out how to import a body field (just a string) into a Matrix block. </p>

<h3>Old database entry structure (non-Crafty)</h3>

<ul>
<li>title</li>
<li>description</li>
<li>body</li>
</ul>

<h3>New database entry structure (Crafty)</h3>

<ul>
<li>title</li>
<li>description</li>
<li>matrix [body, image, gallery, etc]</li>
</ul>

<p>Does anyone have experience with this? Any advice?</p>

<matrix><plugins><database><import>
Import body field into a matrix text block
# Import body field into a matrix text block

(Asked by: username_0 on 2016-08-10)

I'm working on importing a database and I was looking at some of the available import plugins. However I am unable to figure out how to import a body field (just a string) into a Matrix block.

### Old database entry structure (non-Crafty)

* title
* description
* body

### New database entry structure (Crafty)

* title
* description
* matrix [body, image, gallery, etc]

Does anyone have experience with this? Any advice?

**Tags:** matrix, plugins, database, import


---

## 1 answers

### Answer by username_0 on 2016-08-10. Score: 3

Nevermind. Clearbold's Craft Import plugin has the starting code for it.
// new entry
$entry = new EntryModel();
$entry->sectionId = 1;
$entry->typeId    = 12;
$entry->authorId  = 123;
$entry->enabled   = true;
$entry->getContent()->title = "Here goes my title!";

// new matrix and matrix block
$block = array();
$block['new1'] = array(
    'type' => 'body',
    'enabled' => true,
    'fields' => array(
        'text' => 'Here goes my article.'
    )
);

// add content to entry including created matrix
$entry->setContentFromPost(array(
    'description' => "And of course the description...",
    'matriz' => $block,
));

// save entry
$success = craft()->entries->saveEntry($entry);


---

