argument type ... could not be detected - typo3

I have defined a model (I know, I should be using namespaces but this leads me to other problems, so I decided to leave it for now):
class Tx_SimpleOrders_Domain_Model_File extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
...
}
and the controller has two methods for a plugin. The first is to show the form and the second to save the form data to persistance layer. Nothing wild.
class Tx_SimpleOrders_Controller_FileController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
public function showAction() {
echo "<pre>";
var_dump( class_exists('Tx_SimpleOrders_Domain_Model_File') );
echo "</pre>";
}
/**
* Creates a new file
*
* #param Tx_SimpleOrders_Domain_Model_File $newFile A fresh File object which has not yet been persisted
* #return void
*/
public function createAction(Tx_SimpleOrders_Domain_Model_File $newFile) {
echo "<pre>";
var_dump($_POST["tx_simpleorders_upload"]["newFile"]);
echo "</pre>";
}
}
The show action is correctly invoked. I used that - as you can see - to dump class_exists('Tx_SimpleOrders_Domain_Model_File') and it returns true. So the model exists.
I always get the error, when I submit the form
The argument type for parameter $newFile of method Tx_SimpleOrders_Controller_FileController->createAction() could not be detected.
According to the docs, I get this exception, if I don't specify the class of the parameter (as written here https://docs.typo3.org/typo3cms/extensions/efs/ExtExtensionFromScratch/Target7ASimpleCrudApplicationTheFePlugins/TheSubmitForm/Index.html).
But I did.
So what's the problem here?
Here is the Fluid "code" of the view:
{namespace so=Tx_SimpleOrders_ViewHelpers}
<f:form enctype="multipart/form-data" method="post" controller="File" action="create" name="newFile" object="{newFile}">
<f:form.textfield property="identifier" /><br />
<f:form.textarea property="description" rows="3" cols="40" /><br />
<!--<f:form.upload property="image" /><br />-->
<f:form.submit class="submit" value="Hochladen" />
</f:form>

Related

Magento 2.2 - Append Attribute Name To Product Name (H1)

This is driving me nuts, I created a module with a helper:
namespace MyNamespace\MyModule\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
protected $registry;
public function __construct
(
\Magento\Framework\Registry $registry,
\Magento\Eav\Api\AttributeSetRepositoryInterface $attributeSet
) {
$this->registry = $registry;
$this->attributeSet = $attributeSet;
}
public function getTitle()
{
$this->product = $this->registry->registry('product');
$product_name = $this->product->getName();
$attributeSetRepository = $this->attributeSet->get($this->product->getAttributeSetId());
if ($attributeSetRepository->getAttributeSetName() == "Default Engine Component"){
$engine = $this->product->getAttributeText('engine_select');
if (!is_array($engine)){
return "$engine $product_name";
}
}
return $product_name;
}
}
...and this works as it should. Then I added the following to:
/app/design/frontend/vendor/theme/Magento_Catalog/layout/catalog_product_view.xml
<referenceBlock name="page.main.title">
<action method="setPageTitle">
<argument name="title" xsi:type="helper" helper="MyNamespace\MyModule\Helper\Data::getTitle"></argument>
</action>
</referenceBlock>
...but it changes nothing on the product page. I know it's getting called as I can echo out the vars and they show at the top of the page, but it seems that the XML isn't doing what I hoped it would.
Anyone got any ideas?
So, tried multiple variations of achieving what I wanted but in the end, I created a template under Magento_Catalog/templates/product (in my theme), which was based of the magento-theme title.phtml and then modified the page.main.title block in the catalog_product_view layout file.
The template code may look a bit odd (getAttribute and then getAttributeText) but there's no error handling for getAttributeText and with getAttribute, if an attribute has multiple values, it's returned in a string, not an array like getAttributeText. It would have been nicer if I could have made sure the value was always present by checking which attribute set was being used but although getAttributeSetId is part of the product model, it's not available in the product/view interceptor and tbh, I've given up on trying to figure out how all that works!
Anyway, this has taken far more hours than I'd care to admit to figure out so here's the code, hope it helps someone!
Template:
<?php
$product = $block->getProduct();
$product_name = $product->getName();
$attr_exists = $product->getResource()->getAttribute('attr_code');
$title = $product_name;
$cssClass = $block->getCssClass() ? ' ' . $block->getCssClass() : '';
if ($attr_exists){
$attr_name = $product->getAttributeText('attr_code');
if (!is_array($attr_name)){
$title = "$attr_name $product_name";
}
}
?>
<?php if ($title): ?>
<div class="page-title-wrapper<?= /* #escapeNotVerified */ $cssClass ?>">
<h1 class="page-title"
<?php if ($block->getId()): ?> id="<?= /* #escapeNotVerified */ $block->getId() ?>" <?php endif; ?>
<?php if ($block->getAddBaseAttributeAria()): ?>
aria-labelledby="<?= /* #escapeNotVerified */ $block->getAddBaseAttributeAria() ?>"
<?php endif; ?>>
<?= /* #escapeNotVerified */ $title ?>
</h1>
<?= $block->getChildHtml() ?>
</div>
<?php endif; ?>
Layout:
<block name="page.main.title" class="Magento\Catalog\Block\Product\View" template="Magento_Catalog::product/product-h1.phtml" />

How to change input name and db name?

I build a registration form with CodeIgniter. I have a question.
As an example, one of the field from my form
<input type="text" name="username">
But in database, I will use another name instead of username such as user. How do I do it?
So, on the form it will be username, but in the database its name will be user.
Will clear the whole flow (comments may help to understand better)
View:
<form action="/user/register" method="post">
<input name="username" type="text" />
<input name="pass" type="password" />
<input name="age" type="text" />
<input type="submit" />
</form>
Controller:
<?php
class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
}
public function register()
{
if($this->input->server('REQUEST_METHOD') == 'POST')
{
// if validation success
if($validation)
{
/*
Mapping form fields with DB fields
Assuming below as fields in DB
user, password, age
*/
$data['user'] = $this->input->post('username');
$data['password'] = $this->input->post('pass');
$data['age'] = $this->input->post('age');
// Add user
$this->user_mode->add_user($data);
}
}
}
}
Model:
<?php
class User_model extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->db = $this->load->database('default',true);
}
public function add_user($data)
{
$this->db->insert('users', $data);
}
}
To understand please read the Active Record section of CI User manual.

how pass form from module to component in joomla 3.1

I wana create a front-end joomla component and this is my first experience.
here is important things:
1-component/controller.php
class TestController extends JControllerLegacy
{
public function display($cachable = false, $urlparams = false)
{
$view= JFactory::getApplication()->input->getCmd('view','items');
JFactory::getApplication()->input->set('view', $view);
parent::display($cachable, $urlparams);
}
}
2: com_test/model/items.php
<?php
defined('_JEXEC') or die();
jimport( 'joomla.application.component.modellist' );
class TestModelItems extends JModelList
{
public function __construct($config = array())
{
if (empty($config['filter_fields']))
$config['filter_fields'] = array('id', 'title', 'catid');
parent::__construct($config);
}
function getListQuery()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select(...)
return $query;
}
}
I can print the query result on default.php on view folder!
but I wana another thing.
I have a form like this in the front page of my site in a custom module:
<form action="" method="post">
<input type="text" name="wordsearch" value="search">
.
.
<input type="submit" />
</form>
Now!
I do not know how can I send this form (with post method) to getListQuery() function in model folder...how can do it?
i wana when sb click submit form, the component filter query sql according to values of form and then show new result to user!
i googled for hourse but no chance to solve. thanks for your help.
You can submit Form from module to component as follows.
Suppose your component name is com_helloworld The in your module form should have the following things.
<form action="" method="post">
<input type="text" name="wordsearch" value="search">
.
.
<input type="hidden" name="option" value="com_helloworld" />
<input type="hidden" name="view" value="yourview" />
<input type="hidden" name="task" value="my_controller_fun" />
<input type="hidden" value="your_controller_file_name" name="controller">
<input type="submit" />
</form>
In this example your controller file should have my_controller_fun method from controller to model you can use regular method. This methods will get all the form data in your controller , then you can pass that to model.
Detailed :
In your controller file.
function my_controller_fun(){
$post_array = $_POST;
$model = $this->getModel('Profile', 'UsersModel');//example for including profile model you can specify your model file name
$model->function_inyourmodel($post_array);//this function should be in model
}
Hope its help..

Trying to stop page from resubmitting form on refresh

I have the following code. I am trying to prevent my page from resubmitting a form after a page refresh with the header("location:location.php"); However I get a error Listed below
Error
Warning: Cannot modify header information - headers already sent by (output started at /Users/anderskitson/Sites/fiftyfity/wp-content/themes/fiftyfityNew/contact-form copy.php:7) in /Users/anderskitson/Sites/fiftyfity/wp-content/themes/fiftyfityNew/contact-form copy.php on line 68
Code
<?php
/*
Template Name: form-test.php
*/
?>
<?php include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); ?>
<? include_once(ABSPATH. 'wp-content/themes/fiftyfityNew/contact-form.php'); ?>
<?php
/**
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the wordpress construct of pages
* and that other 'pages' on your wordpress site will use a
* different template.
*
* #package WordPress
* #subpackage Starkers
* #since Starkers 3.0
*/
get_header(); ?>
<script>
var i=0;
function test(){
for(i=0;i<=5;i++){
document.write( "the number is" + i);
}
}
</script>
<script>
test();
</script>
<?php function make_user_feedback_form() {
global $wpdb;
global $current_user;
$ufUserID = $current_user->ID;
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'updateFeedback' ) {
$ufDataUpdate = $wpdb->insert( 'wp_user_feedback', array( 'date' => current_time('mysql'), 'responses' => $_POST["test"]) );
}
}?>
<div id="form">
<ol>
<form method="post">
<li><label for="test">Pick a date Babe:</label><input type="text" id="datepicker" name="test" value="" /></li> <!-- the (name="test") value is what the ('responses' => $_POST["test"]) value is talking too -->
<li><input name="submit" type="submit" id="submit" class="submit button" value="Send feedback" /></li>
<?php wp_nonce_field( 'updateFeedback' ); ?>
<input name="action" type="hidden" id="action" value="updateFeedback" />
</form>
</ol>
</div>
<?php
add_action('the_content','make_user_feedback_form');
header("location: http://localhost:8888/fiftyfity/?page_id=90");
?>
<?php
make_user_feedback_form();
?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
The problem is that one of the scripts you are including sends headers before WordPress gets a chance to do so, or that the blank lines between your include_once and the get_header statement makes the web server itself send its default headers.
So, modify the first few lines to look like (i.e. removing the extra PHP opening/closing tags):
<?php
/*
Template Name: form-test.php
*/
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
include_once(ABSPATH. 'wp-content/themes/fiftyfityNew/contact-form.php');
/**
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the wordpress construct of pages
* and that other 'pages' on your wordpress site will use a
* different template.
*
* #package WordPress
* #subpackage Starkers
* #since Starkers 3.0
*/
get_header(); ?>
Also check the included files for any data output, header() calls or similar adjacent opening/closing tags.

Dynamically adding form elements with jQuery and Zend_Form

I have a form in which people shall be able to add the same portion of elements with a plus-button, so that something like this is produced:
<div id="person-1" class="person">
<input type="text" name="name-1" id="name-1" />
<input type="text" name="age-1" id="age-1" />
</div>
<!-- as of here, it's JS created -->
<div id="person-2" class="person">
<input type="text" name="name-2" id="name-2" />
<input type="text" name="age-2" id="age-2" />
</div>
<div id="person-3" class="person">
<input type="text" name="name-3" id="name-3" />
<input type="text" name="age-3" id="age-3" />
</div>
I already managed to write jquery-code that allows me to add the same elements once again with a new id (name-1, age-1, name-2, age-2, name-3, age-3, …).
Of course, Zend_Form does not know about name-2 and name-3, so it just drops them when the form contains an error and is displayed again. Neither can I access the value of name-2 with $form->getValue('name-2'). I have to go over raw $this->getRequest()->getPost().
Is there a better method I can use to combine Zend_Form and javascript-based added form elements (of same type like an hardcoded element).
Caveat: In the real problem, it’s select and not input. Found out this could make a difference (with ->setIsArray(true)), but using select would blow up the example code.
What you could do is create a subform container inside your main form and add an X amount of subforms to that container.
For example:
class My_Form extends Zend_Form
{
private $_numPersons = 1;
public function setNumPersons($numPersons)
{
$this->_numPersons = (int) $numPersons;
}
public function init()
{
$container = new Zend_Form_SubForm();
$this->addSubForm($container, 'persons');
for($index = 0; $index < $this->_numPersons; $index++) {
$personForm = new My_PersonForm();
$container->addSubForm($personForm, $index+1);
}
}
}
When rendered, the input fields will have names like persons[1][name]. Note the $index+1, Zend_Form does not allow a form to be named '0'.
Ofcourse, you should only use this method if the amount of person subforms is limited.
Another strategy would be to override the isValid method and use a single My_PersonForm form to validate all the person data.
Sidenote; the above code will only work when you define the numPersons as part of the options set, when creating the form instance. E.g.;
$form = new My_Form(array('numPersons' => 10));