0

I would like to create a form in my "contactus" page. I'm following this tutorial. I have to extends the sfFrom class to use sfWidget, but in my code I've already extends BaseController.

Is there any solution to do this without making a new class?

class InfoController extends BaseController
{
    /**
     *
     * @Route("/contactus", name="info_contactus_page")
     * @Template()
     */
    public function contactusAction()
    {
        return array();
    }
}
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Tom-pouce
  • 758
  • 2
  • 11
  • 28
  • I don't understand how I can make the same. In this post C class is created at the top of the file, but mine it's a symfony class. Can you help me? – Tom-pouce Oct 29 '12 at 11:26
  • @rabudde not at all. Did you read the **full** question ? – j0k Oct 29 '12 at 12:10
  • @Tom-pouce are you working with symfony 1 or 2? Because `BaseController` doesn't exist in symfony1 but in sf2. And then, you are reading the wrong tutorial .. – j0k Oct 29 '12 at 12:11
  • Also I just noticed, controller should never extend sfForm. controller in some action should create instance of custom sfForm child and work with it. The whole question does not make any sense – Igor Oct 29 '12 at 12:31
  • @j0k I'm working on Sf2. I can't find any Symfony2 tutorial to create form... =( – Tom-pouce Oct 29 '12 at 13:29

3 Answers3

1

You're doing all wrong.

symfony 1 is completely different than Symfony 2 (check this article: How Symfony2 differs from symfony1). You follow a tutorial from sf1 to create form in sf2.

You should instead try to find resources for sf2, like :

And since you're french, I recommend you to read these tutorials:

Then, when you will have read these tutorials, you can come back here to ask a new question about a problem you got when implementing a form.

j0k
  • 22,600
  • 28
  • 79
  • 90
  • I didn't see that my tutorial was for sf1. =/ Thanks for the remark I was seeking solution for hours... – Tom-pouce Oct 29 '12 at 13:57
0

use composition or interfaces.

In your case composition is solution.

PHP does not allow multiple inheritance

Igor
  • 1,835
  • 17
  • 15
  • What? I mean if you have for example class A { }, then you can "inherit" class A behavior in class B with class B { public/private/protected $instanceOfA; } http://en.wikipedia.org/wiki/Object_composition – Igor Oct 29 '12 at 11:57
0

If you can use PHP5.4, use traits: http://php.net/manual/en/language.oop5.traits.php

<?php 

trait SomeOtherControllerTrait {
    function SomethingSomethingSomething() { /* Something */ }
}

class InfoController extends BaseController {
    use SomeOtherControllerTrait;
    /* ... */
}

They allow you to get similar result to multiple inheritence by using composition.

EDIT: Since the tags underneath the question changed to Symfony2: You don't need the multiple inheritance since Symfony2 handled this situation in a different way. The accepted answer described it well.

Chris Hasiński
  • 2,965
  • 2
  • 25
  • 34