title: Magento 2 insert data into database
body: <p>I recently created a module in Magento 2. Now I get the data from the database in front-end phtml file.The code is given below.</p>
  
  <pre><code> try
  {
      $question = $this-&gt;_objectManager-&gt;create('Magecomp\Firstmodule\Model\Firstmodule');
      $question-&gt;setTitle('SimpleQuestion');
      $question-&gt;save();
  }
  catch(Exception $e)
  {
       echo $e-&gt;getMessage();
  }
  </code></pre>
  
  <p>But I get following Error :</p>
  
  <pre><code> Notice: Undefined property: Magecomp\FirstModule\Block\FirstModule::$_objectManager in C:\xampp\htdocs\magento2\lib\internal\Magento\Framework\View\TemplateEngine\Php.php on line 113
  </code></pre>
  
  <p>Please help me to get the object of model and then insert data into table.</p>