Battling (My Own) Idiocy

a.k.a. do everything wrong the first time just to get it out of the way

sfDoctrineNestedSetPlugin

Posted by halestock on June 15, 2010

When I started this blog, my initial motivation was merely having a place to put some of my thoughts and solutions down. There were lots of times that I ran into problems with PHP or Symfony, and if I couldn’t find someone else’s solution, I just went ahead and trudged through it myself. And if my solutions could help others, all the better.

Apparently, there are a decent amount of others who have encountered the same problems as I have and have found my blog because of that (really, I’m still shocked that even a single other person has read this thing), and many of them have been asking for me to release my solution to working with Doctrine’s NestedSet as a plugin. Well, after real life came knocking and prevented me from adding anything new for the past few months, I figured I owe it to those who have been asking.

So, here’s the first release of sfDoctrineNestedSetPlugin.

Currently, it only contains the validator and widget I described previously, but if there is significant interest in additional functionality, I will certainly look at adding more. Please feel free to leave any feedback or let me know if you run into any issues.

Posted in Symfony | 4 Comments »

Forms for N:M Related Models With Additional Relationships

Posted by halestock on February 25, 2010

Although Symfony and Doctrine are very intuitive when it comes to detecting many-to-many(M:N) relationships and generating the relevant forms, there was one situation I encountered where I found myself looking for an alternative solution. Take, for instance, the following Doctrine schema for a simple project management system:

# config/doctrine/schema.yml

Project:
  columns:
    name: { type: string(255), notnull: true, unique: true }
  relations:
    Users:
      refClass: ProjectUser
      class:    User
      local:    project_id
      foreign:  user_id

User:
  columns:
    username: { type: string(255), notnull: true, unique: true }
  relations:
    Projects:
      refClass: ProjectUser
      class:    Project
      local:    user_id
      foreign:  project_id

Role:
  columns:
    name: { type: string(255), notnull: true, unique: true }

ProjectUser:
  columns:
    user_id:      { type: integer, notnull: true, primary: true }
    project_id:   { type: integer, notnull: true, primary: true }
    user_role_id: { type: integer, notnull: true }
  relations:
    Role:
      class:   Role
      local:   user_role_id
      foreign: id
    Project:
      class: Project
      local: project_id
      foreign: id
    User:
      class: User
      local: user_id
      foreign: id

Read the rest of this entry »

Posted in Symfony | Tagged: , | Leave a Comment »

Understanding Permissions/Credentials with SfDoctrineGuardPlugin

Posted by halestock on February 8, 2010

When it comes time to secure an application, be it for user management or protecting an application’s internals, Symfony provides an excellent framework to handle the process. This can be extended with the use of the official SfDoctrineGuardPlugin, which provides a foundation to manage users, permissions and groups through the Doctrine ORM.

Read the rest of this entry »

Posted in Symfony | Tagged: , , | 11 Comments »

Implementing a Nested Set (part three)

Posted by halestock on February 4, 2010

In the final post of this series, I’ll add some relatively simple formatting to the nested set list to make it much more intuitive and readable. I’ll also show how to correctly implement the deleting of items, which I forgot to explain before (and is definitely something that needs to be added to make this usable).

Read the rest of this entry »

Posted in Symfony | Tagged: , , | 18 Comments »

Implementing a Nested Set (part two)

Posted by halestock on February 4, 2010

In my last post, I used a custom widget and validator to represent a nested set in Doctrine. Of course, they aren’t much use without actually being implemented, so in this post I will show how to go about creating them.

Read the rest of this entry »

Posted in Symfony | Tagged: , , | 11 Comments »

Implementing a Nested Set (part one)

Posted by halestock on February 3, 2010

While representing data in a tree structure is normally straightforward, implementing it in a relational database is somewhat of a struggle. The standard way of representing hierarchical data in a relational database is using what’s called a nested set, which (luckily) Doctrine has a built-in behavior for.

Read the rest of this entry »

Posted in Symfony | Tagged: , , | 23 Comments »

 
Follow

Get every new post delivered to your Inbox.