I have used Symfony 2 and I have successfully configured FOSUserBundle.
My application works fine on windows machine in both Production and Development mode
But when I deployed it on Linux machine it works fine in Development mode but it gives a blank page in Production mode. When I check the error log file it has following error:
request.CRITICAL: Doctrine\ORM\Mapping\MappingException: Class \Entity\User is not a
valid entity or mapped super class. (uncaught exception)
request.CRITICAL: Exception thrown when handling an exception
(Doctrine\ORM\Mapping\MappingException: Class \Entity\User is not a valid entity or
mapped super class.) [] []
Have a look into my User Entity class :
/**
* #ORM\Entity(repositoryClass="\Repository\UserRepository")
* #ORM\Table(name="user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Column(type="string", length="255")
*
* #Assert\NotBlank(message="Please enter your name.", groups={"Registration", "Profile"})
* #Assert\MinLength(limit="3", message="The name is too short.", groups={"Registration", "Profile"})
* #Assert\MaxLength(limit="255", message="The name is too long.", groups={"Registration", "Profile"})
*/
protected $name;
/**
* #ORM\Column(type="date", length="255", nullable=true)
*
* #Assert\NotBlank(message="Please select your Date Of Birth.", groups={"Registration", "Profile"})
*/
protected $dob;
/**
* #ORM\Column(type="string", length="255")
*
* #Assert\NotBlank(message="Please select your Date Of Birth.", groups={"Registration", "Profile"})
*/
protected $gender;
/**
* Override $email so that we can apply custom validation.
*
* #Assert\Email(groups={"AppRegistration"})
*/
protected $email;
/**
* #var string $firstName
*
* #ORM\Column(name="first_name", type="string", length=20, nullable=true)
*/
protected $firstName;
/**
* #var string $lastName
*
* #ORM\Column(name="last_name", type="string", length=20, nullable=true)
*/
protected $lastName;
/**
* #var datetime $createdAt
*
* #ORM\Column(name="created_at", type="datetime", nullable=true)
*/
protected $createdAt;
/**
* #ORM\Column(type="string", length="255", nullable=true)
* #var string
*/
protected $facebookID;
/**
* #ORM\Column(type="string", length="255", nullable=true)
* #var string
*/
protected $twitterID;
/**
* #ORM\Column(type="string", length="255", nullable=true)
* #var string
*/
protected $twitter_username;
/**
* #ORM\Column(type="string", length="255", nullable=true)
* #var string
*/
protected $image_path;
/**
* #ORM\Column(name="home_town",type="string", length="255", nullable=true)
* #var string
*/
protected $homeTown;
/**
* #ORM\Column(name="location",type="string", length="255", nullable=true)
* #var string
*/
protected $location;
/**
* #ORM\Column(name="interest",type="string", length="255", nullable=true)
* #var string
*/
protected $interest;
/**
* #ORM\Column(name="friend",type="string", length="255", nullable=true)
* #var string
*/
protected $friend;
/**
* #var smallint $age
*
* #ORM\Column(name="age", type="smallint", nullable=true)
*/
protected $age;
/**
* #var string $country
* #ORM\ManyToOne(targetEntity="Country", inversedBy="user")
* #ORM\JoinColumn(name="country_id", referencedColumnName="id")
* #ORM\Column(name="country_id", type="string", length=25, nullable=true)
*/
protected $countryId;
/**
* #ORM\OneToMany(targetEntity="ProfileViewer", mappedBy="viewer")
*/
protected $viewers;
..................
I think you need to change the Entity named User to any other name, for example Users.
Because User is a reserved keyword in database. Change this and build the schema again. May be this is the mistake?
Related
So I have everything set but I still get:
No identifier/primary key specified for Entity
"Bisna\Application\Entity\Company". Every Entity must have an
identifier/primary key.
Entity:
<?php
namespace Bisna\Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Company
*
* #ORM\Table(name="companies")
* #ORM\Entity
*/
class Company{
/**
* #var integer $id
*
* #ORM\Id
* ORM\Column(name="id", type="integer", nullable=false)
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* #var string $industry
*
* #ORM\ManyToOne(targetEntity="CompanyIndustry", inversedBy="company_industry")
* #ORM\JoinColumn(name="industry_id", referencedColumnName="id", nullable=false)
*/
protected $industry;
/**
* #var string $billingAddress
*
* #ORM\ManyToOne(targetEntity="BillingAddress", inversedBy="billing_addresses")
* #ORM\JoinColumn(name="billing_address_id", referencedColumnName="id", nullable=false)
*/
protected $billingAddress;
/**
* #var string $companyName
*
* #ORM\Column(name="companyName", type="string", length=255, nullable=false)
*/
protected $companyName;
/**
* #var string $website
*
* #ORM\Column(name="website", type="string", length=255, nullable=true)
*/
protected $website;
/**
* #var string $address
*
* #ORM\Column(name="address", type="string", length=255, nullable=true)
*/
protected $address;
/**
* #var string $employeesNumber
*
* #ORM\Column(name="employees_number", type="string", length=255, nullable=true)
*/
protected $employeesNumber;
/**
* #var string $streetNumber
*
* #ORM\Column(name="street_number", type="string", length=255, nullable=true)
*/
protected $streetNumber;
/**
* #var string $street
*
* #ORM\Column(name="street", type="string", length=255, nullable=true)
*/
protected $street;
/**
* #var string $city
*
* #ORM\Column(name="city", type="string", length=255, nullable=false)
*/
protected $city;
/**
* #var string $cityVarname
*
* #ORM\Column(name="city_varname", type="string", length=255, nullable=true)
*/
protected $cityVarname;
/**
* #var string $state
*
* #ORM\Column(name="state", type="string", length=255, nullable=true)
*/
protected $state;
/**
* #var string $stateVarname
*
* #ORM\Column(name="state_varname", type="string", length=255, nullable=true)
*/
protected $stateVarname;
/**
* #var string $stateCode
*
* #ORM\Column(name="state_code", type="string", length=255, nullable=true)
*/
protected $stateCode;
/**
* #var string $postalCode
*
* #ORM\Column(name="postal_code", type="string", length=255, nullable=true)
*/
protected $postalCode;
/**
* #var string $country
*
* #ORM\Column(name="country", type="string", length=255, nullable=true)
*/
protected $country;
/**
* #var string $countryVarname
*
* #ORM\Column(name="country_varname", type="string", length=255, nullable=true)
*/
protected $countryVarname;
/**
* #var string $countryCode
*
* #ORM\Column(name="country_code", type="string", length=255, nullable=true)
*/
protected $countryCode;
/**
* #var string $latitude
*
* #ORM\Column(name="latitude", type="string", length=255, nullable=true)
*/
protected $latitude;
/**
* #var string $longitude
*
* #ORM\Column(name="longitude", type="string", length=255, nullable=true)
*/
protected $longitude;
/**
* #var string $email
*
* #ORM\Column(name="email", type="string", length=255, nullable=true)
*/
protected $email;
/**
* #var string $password
*
* #ORM\Column(name="password", type="string", length=255, nullable=true)
*/
protected $password;
/**
* #var string $firstname
*
* #ORM\Column(name="firstName", type="string", length=255, nullable=false)
*/
protected $firstname;
/**
* #var string $lastname
*
* #ORM\Column(name="lastName", type="string", length=255, nullable=false)
*/
protected $lastname;
/**
* #var Collection $jobs
*
* #ORM\OneToMany(targetEntity="CompanyJob", mappedBy="company", cascade={"persist", "remove"})
* #ORM\OrderBy({"created" = "ASC"})
*/
protected $jobs;
/**
* #var string $activationCode
*
* #ORM\Column(name="activationCode", type="string", length=255, nullable=true)
*/
protected $activationCode;
/**
* #var string $resetPasswordCode
*
* #ORM\Column(name="resetPasswordCode", type="string", length=255, nullable=true)
*/
protected $resetPasswordCode;
/**
* #var string $status ['activation', 'active', 'inactive']
*
* #ORM\Column(name="status", type="string", length=255, nullable=false)
*/
protected $status;
/**
* #var datetime $created
*
* #ORM\Column(name="created", type="datetime", nullable=false)
*/
protected $created;
/* .... */
}
I haven't made the tables yet, but still, I don't understand why I'm getting this error since I have everything. Any ideas?
Maybe it's because you missed a # before #ORM\Column annotation for $id property?
You should consider using Yaml doctrine mappings. It's a good way to separate entity from database columns definitions. And besides, your IDE should validate Yaml contents whereas it probably doesn't validate PHP comments as PHP code.
how i can to do this: I have OrderWork entity this for order and have relation manyToMany with Status entity. All work good, but i want have date for every saved and updated order.
* Order
*
* #ORM\Table(name="order_work")
* #ORM\Entity(repositoryClass="AppBundle\Repository\OrderWorkRepository")
*/
class OrderWork
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="Client", cascade={"persist"})
* #ORM\JoinColumn(name="client_id", referencedColumnName="id")
*/
private $client;
/**
* #var string
*
* #ORM\Column(name="orderNumber", type="string", length=255)
*/
private $orderNumber;
/**
* #var string
*
* #ORM\Column(name="orderCity", type="string", length=255)
*/
private $orderCity;
/**
* #var date
*
* #ORM\Column(name="date", type="string", length=255)
*/
private $date;
/**
* #var \DateTime
*
* #ORM\Column(name="orderDate", type="string", length=255, options={"default": NULL})
*/
private $orderDate;
/**
* #var \DateTime
*
* #ORM\Column(name="returnDate", type="string", length=255, nullable=true)
*/
private $returnDate;
/**
* #var string
*
* #ORM\Column(name="device", type="string", length=255)
*/
private $device;
/**
* #ORM\ManyToOne(targetEntity="SurrogatePhone", cascade={"persist"})
* #ORM\JoinColumn(name="surrogate_id", referencedColumnName="id")
*/
private $surrogatePhone;
/**
* #var int
*
* #ORM\Column(name="orderType", type="integer")
*/
public $orderType;
/**
* #ORM\ManyToMany(targetEntity="Status")
* #ORM\JoinTable(name="order_status",
* joinColumns={#ORM\JoinColumn(name="order_id", referencedColumnName="id", unique=false)},
* inverseJoinColumns={#ORM\JoinColumn(name="status_id", referencedColumnName="id", unique=false)}
* )
*/
private $status;
How better resolve this solution?
Define date in your constructor (for creating):
class OrderWork
{
//...
public function __construct()
{
$this->date = new DateTime();
}
}
And update date field when updating:
$orderWork->setDate(new DateTime());
$em->flush();
I'm quite new to Symfony and Doctrine so....
In my application i have the following entities:
class Company
/**
* #ORM\Id()
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #ORM\Column(name="name", type="string", length=255)
* #ORM\OneToMany(targetEntity="\UserBundle\Entity\User", mappedBy="company")
* #ORM\OneToMany(targetEntity="\AppBundle\Entity\Account", mappedBy="company")
*/
protected $name;
public function __construct()
{
$this->name = new ArrayCollection();
}
UserClass (FOSUserBundle):
class User extends BaseUser
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="firstname", type="string", length=255)
*/
protected $firstname;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
protected $name;
/**
* #ORM\ManyToOne(targetEntity="\AppBundle\Entity\Company")
* #ORM\JoinColumn(name="company_id", referencedColumnName="id")
*/
protected $company;
and Accounts:
class Account
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var integer
*
* #ORM\Column(name="num", type="integer")
*/
private $num;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* #ORM\ManyToOne(targetEntity="\AppBundle\Entity\Company")
* #ORM\JoinColumn(name="company_id", referencedColumnName="id")
*/
protected $company;
There are the following relations.
one company --> many users, many users --> one company;
one company --> many accounts; many accounts --> one company;
is it possible to generate the relations as i did by:
* #ORM\Column(name="name", type="string", length=255)
* #ORM\OneToMany(targetEntity="\UserBundle\Entity\User", mappedBy="company")
* #ORM\OneToMany(targetEntity="\AppBundle\Entity\Account", mappedBy="company")
--> two target entities?
thx for your help...
This is absolutely wrong. If you don't want any links from company to users and accounts then you can just omit this fields. And this relation will be unidirectional. You will have link to Company from both User and Account.
Just omit wrong mappings:
/**
* #ORM\Column(name="name", type="string", length=255)
*/
protected $name;
If you want to create link to users and accounts related to company you need to define fields for these ArrayCollections like that:
/**
* #ORM\OneToMany(targetEntity="\UserBundle\Entity\User", mappedBy="company")
*/
protected $users;
I was wondering if it was possible to configure a entity to automatically load data from another entity.
Ex.
/**
* accountsUsers
*
* #ORM\Table()
* #ORM\Entity
*/
class accountsUsers
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* #var string
*
* #ORM\Column(name="userid",type="integer")
*/
public $userid;
/**
* #var string
*
* #ORM\Column(name="roleid",type="integer")
*/
public $roleid;
/**
* #var string
* admin,adviser,etc
* #ORM\Column(name="roleType", type="string", length=255)
*/
public $roleType;
/**
* #var string
*
* #ORM\Column(name="firstname", type="string", length=255)
*/
public $firstname;
/**
* #var string
*
* #ORM\Column(name="lastname", type="string", length=255)
*/
public $lastname;
/**
* #var string
*
* #ORM\Column(name="company", type="string", length=255)
*/
public $company;
/**
* #var string
*
* #ORM\Column(name="url", type="string", length=255)
*/
public $url;
/**
* #var string
*
* #ORM\Column(name="phone", type="string", length=255)
*/
public $phone;
/**
* #var string
*
* #ORM\Column(name="phone2", type="string", length=255)
*/
public $phone2;
/**
* #var string
*
* #ORM\Column(name="address", type="string", length=255)
*/
public $address;
/**
* #var string
*
* #ORM\Column(name="address2", type="string", length=255)
*/
public $address2;
/**
* #var string
*
* #ORM\Column(name="city", type="string", length=255)
*/
public $city;
/**
* #var string
*
* #ORM\Column(name="state", type="string", length=255)
*/
public $state;
/**
* #var string
*
* #ORM\Column(name="zip", type="string", length=255)
*/
public $zip;
/**
* #var string
*
* #ORM\Column(name="email", type="string", length=255)
*/
public $email;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255)
*/
public $password;
}
AND
/**
* accounts
*
* #ORM\Table()
* #ORM\Entity
*/
class accounts
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* #var string
*
* #ORM\Column(name="partnerid", type="string", length=100)
*/
public $partnerid;
/**
* #var \DateTime
*
* #ORM\Column(name="subscribedate", type="date")
*/
public $subscribedate;
/**
* #var string
*
* #ORM\Column(name="connectionType", type="string", length=100)
*/
public $connectionType;
/**
* #var string
*
* #ORM\Column(name="recordkeeperTpaid", type="string", length=100)
*/
public $recordkeeperTpaid;
/**
* #var string
*
* #ORM\Column(name="recordkeeperAdviceProviderCd", type="string", length=100)
*/
public $recordkeeperAdviceProviderCd;
/**
* #var string
*
* #ORM\Column(name="recordkeeperUrl", type="string", length=200)
*/
public $recordkeeperUrl;
/**
* #var string
*
* #ORM\Column(name="recordkeeperUser", type="string", length=100)
*/
public $recordkeeperUser;
/**
* #var string
*
* #ORM\Column(name="recordkeeperPass", type="string", length=100)
*/
public $recordkeeperPass;
/**
* #var string
*
* #ORM\Column(name="recordkeeperPortfoliosAvailable", type="smallint")
*/
public $recordkeeperPortfoliosAvailable;
/**
* #var string
*
* #ORM\Column(name="recordkeeperRiskBasedFundsAvailable", type="smallint")
*/
public $recordkeeperRiskBasedFundsAvailable;
/**
* #var string
*
* #ORM\Column(name="investmentsMinScore", type="integer")
*/
public $investmentsMinScore;
/**
* #var string
*
* #ORM\Column(name="investmentsMaxScore", type="integer")
*/
public $investmentsMaxScore;
/**
* #var string
*
* #ORM\Column(name="ACAon", type="smallint")
*/
public $ACAon;
/**
* #var string
*
* #ORM\Column(name="MSTClientID", type="string", length = 100)
*/
public $MSTClientID;
}
Is it possible to set up accountsUsers to automatically load in all the accounts data when accountsUsers is accessed by findby, findbyone, etc. The relationship is accountsUsers.userid = accounts.id.
If not, how would I do this in a join using doctrine. I know how to do it using pure raw sql.
Ex. SELECT * FROM accounts a LEFT JOIN accountsUsers b ON a.id =
b.userid
It is not possible to load separate entities in one query (i.e. with a JOIN) just by using annotations. You'll have to define a custom query in your repository which instructs Doctrine, via DQL or QueryBuilder, to join with the related entities.
It was a big gotcha for me as well, but using fetch="EAGER" in the annotation defining the association doesn't actually use a JOIN to retrieve the result - it just issues 2 separate queries to pre-fill the relationship so that its first access does not trigger the lazy loading process.
See also this question for more information.
Symfony developed relations which give you the ability to define a property in entity files and relate it to other entity.
There are two ways.
First way:
In your case,
first you have to make a column in users table(for example name it account) and relate it to account.id column using foreign key's, then in App\Entity\Accounts you can define a property name $users and relate it to App\Entity\Users like code below:
/**
* #ORM\OneToMany(targetEntity="App\Entity\Users", mappedBy="account")
*/
private $users;
and one in App\Entity\Users
/**
* #ORM\ManyToOne(targetEntity="App\Entity\Accounts", inversedBy="users")
*/
private $Account;
like this whenever you get a object from App\Entity\Accounts
a key with the name users will return that have the information of all of this account users just the result:
SELECT * FROM accounts a LEFT JOIN accountsUsers b ON a.id = b.userid
will give you.
The second way is pretty easy just by using make:entity command
php bin/console make:entity
you can make a new column and make a relation for it, command will ask you about everything step by step and its pretty much so simple working with it that you don't need to read the document but if you need more information this is the link to read about it
https://symfony.com/doc/current/doctrine/associations.html#the-manytoone-onetomany-association
Does anyone have a clue why in the world I would be getting 20 minute page load times in dev in Symfony2? It just randomly happens to me. One day I will get fast load times, the next day I am twiddling my thumbs waiting for a page to load. What can I check/disable/enable/etc? Thanks!
Here is my latest page load:
Time: 298068 ms
Here is the Entity for PurchaseOrder
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="archived_po_number", type="string", length=50, nullable=true)
* #Common\Versioned
*/
private $archived_po_number;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=50, nullable=true)
* #Common\Versioned
*/
private $name;
/**
* #var string
*
* #ORM\Column(name="show_locations", type="string", length=1, nullable=true)
* #Common\Versioned
*/
private $show_locations;
/**
* #var integer
*
* #ORM\Column(name="freight", type="decimal", precision=10, scale=2, nullable=true)
* #Common\Versioned
*/
private $freight;
/**
* #var integer
*
* #ORM\Column(name="pallets", type="integer", nullable=true)
* #Common\Versioned
*/
private $pallets;
/**
* #var integer
*
* #ORM\Column(name="boxes", type="integer", nullable=true)
* #Common\Versioned
*/
private $boxes;
/**
* #var text
* #ORM\Column(name="internal_notes", type="text", nullable=true)
* #Common\Versioned
*/
private $internal_notes;
/**
* #var text
* #ORM\Column(name="sales_rep_notes", type="text", nullable=true)
* #Common\Versioned
*/
private $sales_rep_notes;
/**
* #var string
*
* #ORM\Column(name="custom_purchase_order_number", type="string", length=255, nullable=true)
* #Common\Versioned
*/
private $custom_purchase_order_number;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="purchase_order_class", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $purchase_order_class;
/**
* #ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="generated_by_location", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $generated_by_location;
/**
* #ORM\ManyToOne(targetEntity="WIC\InventoryLocationBundle\Entity\InventoryLocation", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="receive_location", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $receive_location;
/**
* #ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="company_name", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $company_name;
/**
* #ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="ship_to", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $ship_to;
/**
* #ORM\ManyToOne(targetEntity="WIC\WarehouseBundle\Entity\Warehouse", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="bill_to", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $bill_to;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="payment_terms", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $payment_terms;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="fob", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $fob;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="ship_via", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $ship_via;
/**
* #var datetime
*
* #ORM\Column(name="ship_by", type="datetime", nullable=true)
* #Common\Versioned
*/
private $ship_by;
/**
* #var datetime
*
* #ORM\Column(name="cancel_by", type="datetime", nullable=true)
* #Common\Versioned
*/
private $cancel_by;
/**
* #var datetime
*
* #ORM\Column(name="due_by", type="datetime", nullable=true)
* #Common\Versioned
*/
private $due_by;
/**
* #var string
*
* #ORM\Column(name="nbt", type="string", length=2, nullable=true)
* #Common\Versioned
*/
private $nbt;
/**
* #ORM\OneToMany(targetEntity="WIC\PurchaseOrderLineItemBundle\Entity\PurchaseOrderLineItem", mappedBy="purchaseOrder", cascade={"remove"}, fetch="EAGER")
*/
protected $purchaseOrderLineItem;
/**
* #ORM\OneToMany(targetEntity="WIC\PurchaseOrderBundle\Entity\PurchaseOrderCharge", mappedBy="purchaseOrder", cascade={"remove"}, fetch="EAGER")
*/
protected $purchaseOrderCharge;
/**
* #ORM\OneToMany(targetEntity="WIC\PurchaseOrderBundle\Entity\PurchaseOrderPayment", mappedBy="purchaseOrder", cascade={"remove"}, fetch="EAGER")
*/
protected $purchaseOrderPayment;
/**
* #ORM\ManyToOne(targetEntity="WIC\SupplierBundle\Entity\Supplier", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="supplier_id", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
protected $supplier;
/**
* #ORM\ManyToOne(targetEntity="WIC\CommonBundle\Entity\CustomOptions", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="status_id", referencedColumnName="id", nullable=true)
* #Common\Versioned
*/
private $status;
/**
* #ORM\ManyToOne(targetEntity="WIC\UserBundle\Entity\User")
* #ORM\JoinColumn(name="created_by", referencedColumnName="id")
* #Common\Blameable(on="create")
*/
private $createdBy;
/**
* #ORM\ManyToOne(targetEntity="WIC\UserBundle\Entity\User")
* #ORM\JoinColumn(name="updated_by", referencedColumnName="id")
* #Common\Blameable(on="update")
*/
private $updatedBy;
/**
* #ORM\ManyToOne(targetEntity="WIC\AccountBundle\Entity\Account", inversedBy="purchaseOrders")
* #ORM\JoinColumn(name="account_id", referencedColumnName="id", nullable=false)
* #Common\Versioned
* #Common\Blameable(on="create")
*/
protected $account;
/**
* #var datetime $created
*
* #Common\Timestampable(on="create")
* #ORM\Column(type="datetime")
*/
private $created;
/**
* #var datetime $updated
*
* #Common\Timestampable(on="update")
* #ORM\Column(type="datetime", nullable=true)
*/
private $updated;
/**
* #ORM\Column(name="deletedAt", type="datetime", nullable=true)
*/
private $deletedAt;
Here is my controller method listAction()
// verify access
if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
$classIdentity = new ObjectIdentity('class', 'WIC\\PurchaseOrderBundle\\Entity\\PurchaseOrder');
if (false === $this->get('security.context')->isGranted('VIEW', $classIdentity)) {
throw new AccessDeniedException('Only an admin user has access to this section...');
}
}
// get user's account
$account = $this->getUser()->getAccount();
$search_form = $this->createForm(new PurchaseOrderSearchType());
$em = $this->getDoctrine()->getManager();
if ($request->isMethod('POST')) {
$search_form->bind($request);
// if ($search_form->isValid()) {
$data = $search_form->getData();
$purchaseOrders = $em->getRepository('WICPurchaseOrderBundle:PurchaseOrder')->getListBy($data);
// }
} else {
if($this->get('request')->query->get('letter')){
}else{
}
// Set the up the pagination statement...
$em = $this->getDoctrine()->getManager();
$dql = "SELECT p FROM WIC\PurchaseOrderBundle\Entity\PurchaseOrder p WHERE p.account=:account_id ORDER BY p.created desc";
$query = $em->createQuery($dql);
$query->setParameters(array(
'account_id' => $account->getId(),
));
$paginator = $this->get('knp_paginator');
$paginatorObject = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1),25
);
// $purchaseOrders = $em->getRepository('WICPurchaseOrderBundle:PurchaseOrder')->findByAccount($account->getId(),array('id' => 'DESC'));
}
return array(
'heading' => 'Purchase Order',
'sidebarLeftTitle'=>'Purchase Order Menu',
'purchaseOrders' => $paginatorObject,
'search_form' => $search_form->createView(),
);
By default in app_dev.php you have the profiler bar, click on the timer and you will have a good start to debug (timeline with main/sub request, etc)
The issue was in the OneToMany relationship code where it says fetch="EAGER". This was pulling in all sorts of unnecessary associations and db queries. When I removed it, the db queries went down to 4 per page instead of 4000.
Are you using x-debug or any PHP level profiling? You've either got some form of recursion happening or one of the steps in the security\http\firewall process is taking a very long time to complete.
My suggestion would be
Look at your stack-trace and find anywhere there are highly repeated events around the security\http\firewall code and investigate if they exist
Quickly step through your code using x-debug, and find where the delay is occurring. With a few page reloads you should be able to step into the section which is causing the long page load times.
If you are using profiling, make sure your created files aren't ridiculously verbose. I've seen this long page load issue happen before due to profiling, where each page load would create a 20Gb+ profiling file.