symfony1

Symfony task - memory leak

和自甴很熟 提交于 2019-12-01 11:49:27
I wrote a symfony task to fill a database of sample data. Here's a sample piece of code: gc_enable(); Propel::disableInstancePooling(); public function test() { for($i = 0; $i < 10000; $i++) { $this->doIt($i); } } public function doIt($i) { $user = new User(); $user->setUsername('user' . $i . "@example.com"); $user->setPassword('test'); $user->setFirstName('firstname' . $i); $user->setLastName('surname' . rand(0, 1000)); $user->save(); $user->clearAllReferences(true); $user = null; gc_collect_cycles(); } How can I limit the use of memory? j0k You have some good tips in an other thread on SO .

Symfony 1.4 improve doctrine save() method

China☆狼群 提交于 2019-12-01 10:58:36
问题 I have 500 entries in my db. In my backend I have action. For example: public function executeMyAction(sfWebRequest $request) { // Get some data from table $templates = Doctrine_Core::getTable('SeoTemplates')->findOneByEntity('training'); //Get data from other table(500 items) $trainings = Doctrine::getTable('Training')->getTraining(); // Make some operations with data foreach ($trainings as $training) { $training->setSomeValue1('some_data'); $training->setSomeValue2('some_data'); $training-

Symfony Doctrine Models for Entity Without Primary Keys

。_饼干妹妹 提交于 2019-12-01 08:28:30
I'm working with a legacy database while re-building the web application. I want to use Symfony2.x which obviously has Doctrine as ORM. I've around 50 (mysql) tables which has NO Primary Keys. When I try to generate models, it does not let me do and throw an exception with "No Primary Key on ... table". Do I must have Primary Keys on tables to use Doctrine or is there any way around it? Any help would be great. Thanks. Doctrine requires every entity class to have an identifier/primary key. Take a look at this page: http://www.doctrine-project.org/docs/orm/2.0/en/reference/basic-mapping.html

How to use MySQL functions in Propel

限于喜欢 提交于 2019-12-01 05:56:37
I want to select records that are 1 month old or newer. The query is: SELECT * FROM foobar WHERE created_at > DATE_SUB(curdate(), INTERVAL 1 MONTH) Using Propel in Symfony, I do: $c = new Criteria $c->add(FoobarPeer::CREATED_AT, "DATE_SUB(curdate(), INTERVAL 1 MONTH)", Criteria::GREATER_THAN); What Propel generates is: SELECT * FROM foobar WHERE created_at > 'DATE_SUB(curdate(), INTERVAL 1 MONTH)' - in other words, it puts the MySQL function in single quotes, which makes it a (meaningless) string and I get no records. What I've done for now is: $c->add(FoobarPeer::CREATED_AT, "created_at >

Symfony: email address as request parameter

喜欢而已 提交于 2019-12-01 03:41:33
I'm having some issues with passing an email address in a url to a symfony app. The url looks like example.com/unsubscribe/email/me@example.com It will always result in a sfError404Exception , except when the period is removed. After doing some googling around, the only solution I've yet seen is that htaccess is bypassing the url because of the period present. However, when I add the suggested fix to htaccess, like so: # we skip all files with .something RewriteCond %{REQUEST_URI} \..+$ RewriteCond %{REQUEST_URI} !@.+ #skip email address RewriteCond %{REQUEST_URI} \.epl$ RewriteCond %{REQUEST

How to use MySQL functions in Propel

为君一笑 提交于 2019-12-01 03:07:55
问题 I want to select records that are 1 month old or newer. The query is: SELECT * FROM foobar WHERE created_at > DATE_SUB(curdate(), INTERVAL 1 MONTH) Using Propel in Symfony, I do: $c = new Criteria $c->add(FoobarPeer::CREATED_AT, "DATE_SUB(curdate(), INTERVAL 1 MONTH)", Criteria::GREATER_THAN); What Propel generates is: SELECT * FROM foobar WHERE created_at > 'DATE_SUB(curdate(), INTERVAL 1 MONTH)' - in other words, it puts the MySQL function in single quotes, which makes it a (meaningless)

How to query NOT NULL with Doctrine?

℡╲_俬逩灬. 提交于 2019-12-01 02:29:21
I have table Test: Test: id | name 1 | aaa 2 | 3 | ccc 4 | aaa 5 | 6 | ddd I want result where name is NOT NULL: aaa ccc aaa ddd How can i get with: Doctrine_Core::getTable('Test')->findBy('name', NOTNULL??) <-doesnt working and in model with: $this->createQuery('u') ->where('name = ?', NOTNULL ???) <- doesnt working ->execute(); Try this: $this->createQuery('u') ->where('name IS NOT NULL') ->execute(); which is standard SQL syntax. Doctrine doesn't convert Null values into proper sql. Do it in Doctrine way, from query builder and Expr class. $qb = $entityManager->createQueryBuilder(); $result

How to get Symfony session variable in model?

醉酒当歌 提交于 2019-12-01 01:16:56
How can I pass session variable in symfony model without using sfContext::getInstance() ? Maerlyn The recommended way is called dependency injection, and works like this: you create a setUser() method in your model file, that saves the given parameter to a private property: class Foo { private $_user; public function setUser(myUser $user) { $this->_user = $user; } // ... later: public function save(Doctrine_Connection $conn = null) { // use $this->_user to whatever you need } } This looks clumsy, because it is. But without you answering the question what are you trying to do? I cannot give an

Best way to get request object from within Symfony forms?

故事扮演 提交于 2019-12-01 00:20:48
I use Symfony and Doctrine to generate forms for my CMSes. Lately I've been customizing them by setting default values based on specific URL parameters. For example, I have two models: PollQuestion and PollChoice . PollChoice has a relation to PollQuestion by means of a poll_question_id field. The PollChoice form has a dropdown that lists all the available PollQuestion s that the PollChoice can be attached to. I also have two routes: pollchoices/new and poll/:poll_id/choice/new . Both routes display the PollChoiceForm , but by using the 2nd route you would automatically see the PollQuestion

integrating Wordpress with Symfony

谁都会走 提交于 2019-12-01 00:08:22
I have a site built with Symfony 1.2. I'm trying to integrate Wordpress 2.8.4 into it to power my blog. I followed the instructions at http://www.theodo.fr/blog/2009/03/integrate-wordpress-into-symfony/ , including the 2 steps in the comments at http://www.theodo.fr/blog/2009/03/integrate-wordpress-into-symfony/comment-page-1/#comment-573 . My actions.class.php file looks like this: <?php class sfWordpressActions extends sfActions { public function executeIndex(sfWebRequest $request) { // Don't load symfony's I18N $standard_helpers = sfConfig::get('sf_standard_helpers'); $standard_helpers =