Charlie
Charlie

Reputation: 476

Setting up first schema.yml for Symfony 1.4

I'm trying to set up Symfony 1.4. I'm not new to MVC but this is my first attempt at Symfony. I've been following the documentation on symfony-project.org/reference/1_4 and I have a "Hello, World!" page.

I moved on to the next step -- database.

I did this (don't worry. localhost only :) ):

./symfony configure:database "mysql:host=localhost;dbname=myblog" myblog myblog

Then I put this in my config/doctrine/schema.yml file:

Article:
  actAs: [Sluggable, Timestampable]
  columns:
    title:
      type: string(255)
      notnull: true
    content:
      type: clob
    status: string(255)
    author_id: integer
    category_id: integer
    published_at: timestamp
  relations:
    Author:
      foreignAlias: Articles
    Category:
      foreignAlias: Articles
    Tags:
      class: Tag
      refClass: ArticleTag
      foreignAlias: Articles
Author:
  columns:
    first_name: string(20)
    last_name: string(20)
    email: string(255)
    active: boolean
Category:
  columns:
    name: string(255)
Tag:
  columns:
    name: string(255)
ArticleTag:
  columns:
    article_id:
      type: integer
      primary: true
    tag_id:
      type: integer
      primary: true
  relations:
    Article:
      onDelete: CASCADE
    Tag:
      onDelete: CASCADE

But I'm getting this:

charlie@mystery:~/sfproject$ ./symfony doctrine:build --all-classes
>> doctrine  generating model classes
>> file+     /tmp/doctrine_schema_30022.yml
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseArticleTag.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseCategory.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseArticle.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseAuthor.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseTag.class.php
>> autoload  Resetting application autoloaders
>> file-     /home/charlie/sfproject/cache/frontend/dev/config/config_autoload.yml.php
>> doctrine  generating form classes
PHP Fatal error:  Class 'columns' not found in /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php on line 25

Fatal error: Class 'columns' not found in /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php on line 25
PHP Fatal error:  Call to a member function evictAll() on a non-object in /home/charlie/sfproject/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239

Fatal error: Call to a member function evictAll() on a non-object in /home/charlie/sfproject/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239

I tried several different example files for my schema.ywl, so I don't think it's flawed. I must have missed a step.

Something's not right, but I'm absolutely stumped. Any help will be very appreciated!

Edit My original config/doctrine/schema.yml was:

Posts:
  actAs:
    Timestampable: ~
    columns:
      title: string(255)
      body: clob

Edit 2 Per Mike's request, I edited the file to be this:

Article:
  actAs: { Timestampable: ~ }
  columns:
    title:
      type: string(255)
      notnull: true
    content:
      type: clob
    status: string(255)
    author_id: integer
    category_id: integer
    published_at: timestamp
  relations:
    Author:
      foreignAlias: Articles
    Category:
      foreignAlias: Articles
    Tags:
      class: Tag
      refClass: ArticleTag
      foreignAlias: Articles
Author:
  columns:
    first_name: string(20)
    last_name: string(20)
    email: string(255)
    active: boolean
Category:
  columns:
    name: string(255)
Tag:
  columns:
    name: string(255)
ArticleTag:
  columns:
    article_id:
      type: integer
      primary: true
    tag_id:
      type: integer
      primary: true
  relations:
    Article:
      onDelete: CASCADE
    Tag:
      onDelete: CASCADE

The error is:

charlie@mystery:~/sfproject$ ./symfony doctrine:build --all-classes
>> doctrine  generating model classes
>> file+     /tmp/doctrine_schema_79366.yml
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseArticleTag.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BasePosts.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseCategory.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseArticle.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseAuthor.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseTag.class.php
>> autoload  Resetting application autoloaders
>> doctrine  generating form classes
PHP Fatal error:  Class 'columns' not found in /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php on line 25

Fatal error: Class 'columns' not found in /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php on line 25
PHP Fatal error:  Call to a member function evictAll() on a non-object in /home/charlie/sfproject/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239

Fatal error: Call to a member function evictAll() on a non-object in /home/charlie/sfproject/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239
charlie@mystery:~/sfproject$ 

Edit For Mike's manual build suggestion, I get the same error on doctrine:build-filters and doctrine:build-forms:

charlie@mystery:~/sfproject$ php symfony doctrine:build-model
>> doctrine  generating model classes
>> file+     /tmp/doctrine_schema_91741.yml
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseArticleTag.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BasePosts.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseCategory.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseArticle.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseAuthor.class.php
>> tokens    /home/charlie/sfproject/lib/model/doctrine/base/BaseTag.class.php
>> autoload  Resetting application autoloaders
>> file-     /home/charlie/sfproject/cache/frontend/dev/config/config_autoload.yml.php
charlie@mystery:~/sfproject$ php symfony doctrine:build-filters
>> doctrine  generating filter form classes
PHP Fatal error:  Class 'columns' not found in /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php on line 25

Fatal error: Class 'columns' not found in /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php on line 25
PHP Fatal error:  Call to a member function evictAll() on a non-object in /home/charlie/sfproject/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239

Fatal error: Call to a member function evictAll() on a non-object in /home/charlie/sfproject/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239
charlie@mystery:~/sfproject$ php symfony doctrine:build-forms
>> doctrine  generating form classes
PHP Fatal error:  Class 'columns' not found in /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php on line 25

Fatal error: Class 'columns' not found in /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php on line 25
PHP Fatal error:  Call to a member function evictAll() on a non-object in /home/charlie/sfproject/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239

Fatal error: Call to a member function evictAll() on a non-object in /home/charlie/sfproject/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection.php on line 1239
charlie@mystery:~/sfproject$ php symfony cc
>> cache     Clearing cache type "all" for "frontend" app and "test" env
>> file+     /home/charlie/sfproject/data/frontend_test-cli.lck
>> chmod 777 /home/charlie/sfproject/data/frontend_test-cli.lck
>> file-     /home/charlie/sfproject/cache/frontend/test/config/config_config_handlers.yml.php
>> file-     /home/charlie/sfproject/cache/frontend/test/config/config_app.yml.php
>> file-     /home/charlie/sfproject/cache/frontend/test/config/config_settings.yml.php
>> file-     /home/charlie/sfproject/data/frontend_test-cli.lck
>> cache     Clearing cache type "all" for "frontend" app and "dev" env
>> file+     /home/charlie/sfproject/data/frontend_dev-cli.lck
>> chmod 777 /home/charlie/sfproject/data/frontend_dev-cli.lck
>> file-     /home/charlie/sfproject/cache/frontend/dev/config/config_autoload.yml.php
>> file-     /home/charlie/sfproject/cache/frontend/dev/config/config_config_handlers.yml.php
>> file-     /home/charlie/sfproject/cache/frontend/dev/config/config_databases.yml.php
>> file-     /home/charlie/sfproject/cache/frontend/dev/config/config_app.yml.php
>> file-     /home/charlie/sfproject/cache/frontend/dev/config/config_settings.yml.php
>> file-     /home/charlie/sfproject/data/frontend_dev-cli.lck
>> cache     Clearing cache type "all" for "frontend" app and "prod" env
>> file+     /home/charlie/sfproject/data/frontend_prod-cli.lck
>> chmod 777 /home/charlie/sfproject/data/frontend_prod-cli.lck
>> file-     /home/charlie/sfproject/cache/frontend/prod/config/config_config_handlers.yml.php
>> file-     /home/charlie/sfproject/cache/frontend/prod/config/config_app.yml.php
>> file-     /home/charlie/sfproject/cache/frontend/prod/config/config_settings.yml.php
>> file-     /home/charlie/sfproject/data/frontend_prod-cli.lck
charlie@mystery:~/sfproject$ 

Upvotes: 0

Views: 4953

Answers (2)

user1207727
user1207727

Reputation: 1553

It looks like your problem lies in the classes generated with your old schema versions. Take a look at the first error:

PHP Fatal error:  Class 'columns' not found in /home/charlie/sfproject/lib/model/doctrine/base/BasePost.class.php on line 25

It's talking about the classes created before you renamed Post to Article (and it looks like you tried once with Posts). When you remove or rename models in the schema symfony will not remove the old class files for you, but it does provide a command to run which will find any orphan classes and prompt you to confirm their removal. The command is:

./symfony doctrine:clean-model-files

Use it to get rid of the old leftover classes and then, along with Mike's solution, you might just be in business.

Upvotes: 0

Mike Purcell
Mike Purcell

Reputation: 19979

Your new schema looks good, your original schema was bad.

This:

Posts:
  actAs:
    Timestampable: ~
    columns:
      title: string(255)
      body: clob

Should be:

Posts:
  actAs:
    Timestampable: ~
  columns:
    title: string(255)
    body: clob

With the previous snippet, columns was at the same level as actAs which is why it's choking on trying to create a 'columns' class.

-- Edit --

Try running the build manually (should be able to swap out doctrine with propel if using propel):

php symfony doctrine:build-model
php symfony doctrine:build-filters
php symfony doctrine:build-forms
php symfony cc

Upvotes: 1

Related Questions