Error when adding/editing entry in admin module

Discussion relating to version 1.2.x stable

Error when adding/editing entry in admin module

Postby LrsK » Tue Mar 03, 2009 6:42 pm

I get this error when trying to run backend_dev.php/user, then clicking "New" and adding some data:

Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in C:\xampp\htdocs\sf_sandbox\lib\symfony\util\sfParameterHolde r.class.php on line 53

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sf_sandbox\lib\symfony\util\sfParameterHolde r.class.php:53) in C:\xampp\htdocs\sf_sandbox\lib\symfony esponse\sfWebRespons e.class.php on line 335

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sf_sandbox\lib\symfony\util\sfParameterHolde r.class.php:53) in C:\xampp\htdocs\sf_sandbox\lib\symfony esponse\sfWebRespons e.class.php on line 349


Also, the fields that I filled in are returned with *Required tags, indicating that they weren't submitted somehow. Even the CSRF token is missing according to the response from the form.

I followed the "Admin generator" tutorial, so I'm not sure what went wrong. :?~ :-?~ :???:


Thanks for any help!
LrsK
Junior Member
 
Posts: 2
Joined: Tue Mar 03, 2009 6:36 pm

Re: Error when adding/editing entry in admin module

Postby GeeF » Fri Apr 17, 2009 10:50 am

Hi,

I had the same problem, but not with the admingenerator.
I set a new widgetschema in my formclass, to overwrite the widgetschema in the generated baseclass.

In the docs it says that the configure method is used in the users formclass, so you don't have to rewrite the whole setup routine of the generated baseclass.

Unfortunately, when you call setWidgets, a new (empty) widgetSchema is created; so this also overwrites the nameformat.

My mistake was that I didn't explicitly set the nameformat for the widgetschema in the configure method again, as well as the errorSchema. Just had to copy them from the baseclass.



However, Symfony shouldn't raise this error. I looked a bit into the code and found, that the default value for a new widgetSchemas nameFormat is '%s'. The getName method of the form checks for '%s' and returns false for the name, but the value of getName is just passed on to the getParameter methods and this produces the array error. False is no valid array index ;)~ ;-)~ :wink:

The getParameter method looks like this:

Code: Select all
public function getParameter($name, $default = null)
{
     return $this->parameterHolder->get($name, $default);
}


and parameterHolder->get looks like:

Code: Select all
public function & get($name, $default = null)
{
    if (array_key_exists($name, $this->parameters))
    {
        $value = & $this->parameters[$name];
    }
    else
    {
         $value = sfToolkit::getArrayValueForPath($this->parameters, $name, $default);
    }

    return $value;
}


It crashes, because array_key_exists itself can't handle 'false' as $name. So either build a check for this and give the poor symfony hacker a proper error message, so he doesn't have to read through the whole sourcetree ;)~ ;-)~ :wink: ; or leave it that way.
Sounds dumb, but I think this method is really trimmed for performance. Request Parameters are frequently accessed and that shouldn't take too long.

Please give me feedback. Shall I file a bug report for this? Or just keep this in the forums, so other devs know what's wrong, when they get this error.
Last edited by GeeF on Fri Apr 17, 2009 10:51 am, edited 1 time in total.
GeeF
Junior Member
 
Posts: 6
Joined: Fri Mar 27, 2009 12:53 pm

Re: Error when adding/editing entry in admin module

Postby grenoult » Mon Apr 20, 2009 5:21 pm

Hi.

I had the same problem with Symfony 1.2 and without the admin generator.

In fact, I added the setWidgets and setLabels in my /lib/form/XXXForm.class.php and the error was shown. Once i've added
Code: Select all
$this->widgetSchema->setNameFormat('XXX[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
in this file (copied from base form class), it worked nice.

Weird... but thanks :D~ :-D~ :grin:
grenoult
Member
 
Posts: 52
Joined: Fri Sep 19, 2008 10:18 am
Location: France

Re: Error when adding/editing entry in admin module

Postby jeanmich » Mon Apr 19, 2010 5:44 pm

I have exactly the same problem after generating an admin module.
Table with 3 primary keys, I changed the routing.yml to
Code: Select all
column:               code_id/:employe_id/:date


and added in lib/model/Codeemploye.php :
Code: Select all
public function getPrimaryKey()
  {
    return $this->getCodeId().$this->getEmployeId().$this->getDate();
  }


Deleting works, but I cannot add or update. I have
Code: Select all
Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in /home/XXX/lib/vendor/symfony/lib/util/sfParameterHolder.class.php on line 53


Any idea?
Thank you.
Last edited by jeanmich on Wed Apr 21, 2010 6:06 pm, edited 1 time in total.
jeanmich
Junior Member
 
Posts: 24
Joined: Thu Nov 06, 2008 10:31 pm
Location: France

Re: Error when adding/editing entry in admin module

Postby jeanmich » Wed Apr 21, 2010 11:17 pm

It seems object doesn't get correctly by routing.
Because when I disable CSRF I got:
Code: Select all
Fatal error: Call to undefined method sfRoute::getObject() in /home/XXX/cache/backend/dev/modules/autoCodeemploye/actions/actions.class.php  on line 93
jeanmich
Junior Member
 
Posts: 24
Joined: Thu Nov 06, 2008 10:31 pm
Location: France

Re: Error when adding/editing entry in admin module

Postby jeanmich » Thu Apr 22, 2010 5:03 pm

How explain...
First time I worked on this project was several months ago and I forgot I changed /lib/form/XXXForm.class.php.

So I added:
$this->widgetSchema->setNameFormat('XXX[%s]');

$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

and it finally works...
jeanmich
Junior Member
 
Posts: 24
Joined: Thu Nov 06, 2008 10:31 pm
Location: France

Re: Error when adding/editing entry in admin module

Postby gofaster » Tue Jun 15, 2010 6:54 pm

wanted to give a big thanks for this. BIG thanks.
gofaster
Junior Member
 
Posts: 4
Joined: Wed Dec 23, 2009 1:27 am


Return to symfony 1.2

Who is online

Users browsing this forum: No registered users and 1 guest