Entity creating with PHP?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zubo
    Junior Member
    • Jun 2016
    • 4

    Entity creating with PHP?

    When I used manual "ORM (How to Manage Entities)" I managed to write little code for creating entity with 2 parameters:
    <?
    include ("bootstrap.php");

    use\application\Espo\Core\ORM\Entity;
    use\application\Espo\Controllers;
    use\application\Espo\Services;
    use\application\PDO;
    use\application\Espo\Core\Utils\Config;
    use\application\Espo\Core\ORM\EntityManager;

    $entityManager = $this->getEntityManager();
    $call1 = $entityManager->getEntity('Call');
    $call1->set('name', 'Test Call');
    $call1->set('status', 'Completed');
    $entityManager->saveEntity($call1);
    ?>

    I got same error every time I'm trying to process it
    Fatal error: Using $this when not in object context in /var/www/admin/www/server_name/test.php

    How to define "$this"? Documentation have nothing about it
  • yuri
    Member
    • Mar 2014
    • 8627

    #2
    Create entryPoint in application/Espo/EntryPoints

    it will be available by url entryPoint=entryPointName
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • Zubo
      Junior Member
      • Jun 2016
      • 4

      #3
      Originally posted by yurikuzn
      Create entryPoint in application/Espo/EntryPoints

      it will be available by url entryPoint=entryPointName
      http://server_name/?entryPoint=Call shows me error "404 Page Not Found"

      Do I need to create new file in EntryPoints folder? Also, can I find manuals to create new classes and entities programmatically?

      What do I need to create and edit entities by PHP or JS code? Sorry for domb question, but I new in EspoCRM and want to learn.

      I have a page "http://server_name/#Call" with button "Create Call", but I have to create new enities with GET-query
      Last edited by Zubo; 06-30-2016, 05:02 AM.

      Comment

      • tarasm
        Super Moderator
        • Mar 2014
        • 573

        #4
        Create a file application/Espo/Modules/YOUR_MODULE/EntryPoints/CallEntryPoint.php
        PHP Code:
        class CallEntryPoint extends \Espo\Core\EntryPoints\Base
        {
            public function run()
            {
                $entityManager = $this->getEntityManager();
            }
        } 
        
        http://YUOR_DOMAIN/?entryPoint=CallEntryPoint
        Last edited by tarasm; 07-01-2016, 07:57 AM.
        Job Offers and Requests

        Comment

        • Zubo
          Junior Member
          • Jun 2016
          • 4

          #5
          Originally posted by tarasm
          Create a file application/Espo/Modules/YOUR_MODULE/EntryPoints/CallEntryPoint.php
          PHP Code:
          class CallEntryPoint extends \Espo\Core\EntryPoints\Base
          {
          public function run()
          {
          $entityManager = $this->getEntityManager();
          }
          } 
          
          http://YUOR_DOMAIN/?entryPoint=CallEntryPoint
          Thanks! Now I managed to create new entites programmatically by GET-queries

          But... how to create whole new "class" like "class Lead extends \Espo\Core\Entities\Person"...

          Where to write field names and classes? What files I have to create?

          Comment

          Working...