Zum Inhalt springen

extbase: "Catchable fatal error: Argument 1 passed..."

Erstellt am 13. Juli 2009 · 1 Antwort · letzte Antwort am 22. August 2009

Tags: Frage

greenbanana ·

Ich bin dabei eine Extension mit "extbase" und "fluid" zu schreiben. Leider erhalte ich aber bei einer Formular-Eingabe immer den selben Fehler. Kann mir jemand helfen was ich da falsch mache?


Catchable fatal error: Argument 1 passed to Tx_ExtbaseSandbox_Controller_FormController::confirmAction() must be an instance of Tx_ExtbaseSandbox_Domain_Model_Form, array given in /home/httpd/vhosts/myweblog.ch/httpdocs/typo3conf/ext/extbase_sandbox/Classes/Controller/FormController.php on line 58

Folgendermasse sehen die Files aus:

formController.php

class Tx_ExtbaseSandbox_Controller_FormController extends Tx_Extbase_MVC_Controller_ActionController {

	/**
	 * Initializes the current action
	 *
	 * @return void
	 */
	public function initializeAction() {
	}
	
	/**
	 * Displays a form
	 * 
	 * @param Tx_ExtbaseSandbox_Domain_Model_Form $newForm A fresh blog object taken as a basis for the rendering
	 * @return string An HTML form for creating a new blog
	 */
	public function indexAction(Tx_ExtbaseSandbox_Domain_Model_Form $newForm = NULL) {
		$this->view->assign('newForm', $newForm);		
	}

	/**
	 * Display the form-content
	 *
	 * @param Tx_ExtbaseSandbox_Domain_Model_Form $newForm A fresh Form object
	 * @return void
	 */
	public function confirmAction(Tx_ExtbaseSandbox_Domain_Model_Form $newForm){
		$this->view->assign('newForm', $newForm);				
	}

Form-Model

class Tx_ExtbaseSandbox_Domain_Model_Form extends Tx_Extbase_DomainObject_AbstractEntity {

	/**
	 * @var string
	 */
	protected $textboxOne;

	/**
	 * @var string
	 */
	protected $textArea;

	/**
	 * @var string
	 */
	protected $selectLabelOne;

	/**
	 * @var array
	 */
	protected $selectLabelTwo;
	
	/**
	 * @var string
	 */
	protected $file;
	/**
	 * Constructs this post
	 */
	
	public function __construct() {
	}	
}

index.html

<f:debug>{newForm}</f:debug>
<h1>Form - View</h1>
<f:form method="post" controller="Form" action="confirm" name="newForm" object="{newForm}">
	<!-- Textbox -->
	<label for="textboxLabel">
		Textbox
		<span class="required">(required)</span>
	</label><br />
	<f:form.textbox name="textboxOne" property="textboxOne" /><br />
	
	<!-- Textarea -->
	<label for="textareaLabel">
		Textarea
	</label><br />
	<f:form.textarea name="textArea" property="textArea" rows="8" cols="46" /><br />
	
	<!-- Select -->
	<label for="selectLabelOne">
		Select One
	</label><br />
	<f:form.select name="selectLabelOne" options="{payPal: 'PayPal International Services', visa: 'VISA Card', master: 'MasterCard'}" value="visa" property="selectLabelOne" /><br />	
	
	<label for="selectLabelTwo">
		Select Two
	</label><br />
	<f:form.select name="selectLabelTwo" options="{payPal: 'PayPal International Services', visa: 'VISA Card', master: 'MasterCard'}" value="{0: 'master', 1: 'visa'}" multiple="multiple" property="selectLabelTwo" /><br />
 	
	<!-- Upload -->
	<label for="uploadLabel">
		Upload
	</label><br />
	<code title="Upload">
 		<f:form.upload name="file" property="file" />
 	</code>
	<!-- Submit Button -->
	<f:form.submit>Create</f:form.submit>
</f:form>
greenbanana ·

Der Fehler war, wie die Fehlermeldung ja eigentlich auch sagt, dass das verwendete Objekt nicht instanziert war.

Folgendes muss in die initializeAction() rein:

/**
 * Initializes the current action
 *
 * @return void
 */
public function initializeAction() {
	$this->formRepository = t3lib_div::makeInstance('Tx_ExtbaseSandbox_Domain_Model_Form');		
}