craphunter
craphunter

Reputation: 830

Multiple action.class.php

I do have an module e.g. account. Of course you will find a file called in acount/actions/action.class.php.

The PHP-file action.class.php is getting big. Is it possible to extend it?

for an example:

/account/action/action.class.php
/account/action/action2.class.php

If it is possible, how does the code look like in action.class.php and in action2.class.php? And/or where should I enter something in a config-ymal-file?

Thanks in advance!

Craphunter

Upvotes: 5

Views: 1389

Answers (4)

guiman
guiman

Reputation: 1334

Symfony actions can be declare in two flavors:

  1. A big actios.class.php file that inherit from sfActions
  2. Multiple xxxAction.class.php file that inherit from sfAction

The are both basically the same but these cant be mixed (you must decide if you want 123123 files, 1 per action, or one big fat file).

Here its the symfony reference on this matters: Symfony Front Controller - Actions check the Action section.

Upvotes: 7

mgois
mgois

Reputation: 343

Also consider if some of the behavior you're implementing in the action (controller) belongs to the model (or the view) instead. If the really belongs to the action just follow guiman's advice and create an action per class inheriting sfAction.

If I have a CRUD module based on a model (as generated by the CLI), and I have to define additional behaviors for that model, I tend to create another module to contain that behaviours. E.g., considering a model Article. I could create an article module for the CRUD behaviors (generated), article_support for additional behaviors like moderation, activation, etc. and perhaps article_ajax for async requests.

Upvotes: 1

Tom
Tom

Reputation: 30698

It sounds like the action class is getting too big because you have too much stuff in it. I would suggest breaking it into multiple modules or moving relevant parts of the logic code into your models.

Adding an include for an action2 file is not how Symfony 1.4 is intended to be used and will likely just lead to all kinds of other headache.

Upvotes: 4

Grad van Horck
Grad van Horck

Reputation: 4506

PHP doesn't support 'partial classes' like C#. So you have two options:

  • Create an inheritance chain, by creating a baseActions class which inherits from sfAction. Then create your MainActions class which inherits from baseActions. You can add different layers of inheritance.

  • Group functions in seperate classes. Override the execute() function in your actions file, and manually call the function on the class you need.

Upvotes: 1

Related Questions