Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-21 Thread Grant Cox

Have you tried debugging this yourself - what problems did you
encounter?  The errors above give you specific line numbers in your
own code that should give a good idea what is happening.

For a guess, since it is in your afterFind, you are expecting the
afterFind to have an array of results each with a $this->name key,
e.g.
$results = array(  array('Professor'=>array()),
array('Professor'=>array()) )

which is the case when the model is the primary one being queried.
When the model is only associated to the model being queried, then you
may get an array with a single $this->name key, under which is a
numerically indexed array of results, e.g.

$results = array( 'Professor'=>array(  0=>array(...), 1=>array(...),
2=>array(...) ));

So, your afterFind needs to be a bit smarter.  Personally, I have the
following in my app_model:

function afterFind( $results )
{
// see if the model wants to attach attributes
if ( method_exists($this, '_attachAttributes') ){
for ($i = 0; $i < sizeof($results); $i++) {
// check if this is a model, or if it is an 
array of models
if ( isset($results[$i][$this->name]) ){
// this is the model we want, see if 
it's a single or array
if ( 
isset($results[$i][$this->name][0]) ){
// run on every model
for ($j = 0; $j < 
sizeof($results[$i][$this->name]); $j++) {

$this->_attachAttributes( &$results[$i][$this->name][$j] );
}
} else {
$this->_attachAttributes( 
&$results[$i][$this->name] );
}
}
}
}

return $results;
}

and then in my model class I would have something like:

function _attachAttributes( $row )
{
if ( isset($row['firstname']) and isset($row['surname']) ){
$row['fullname'] = $row['firstname'].' 
'.$row['surname'];
}
}


But if you really just want a select with the two fields, just do it
by hand:

function niceSelect( $conditions )
{
$select_list = array();

$rows = $this->findAll( $conditions, null, null null, 1, -1 );
if ( !empty($rows) ){
foreach( $rows as $row ){
$select_list[ $row[$this->name]['id'] ] = 
$row[$this->name]
['firstname'].' '.$row[$this->name]['surname'];
}
}

return $select_list;
}



On Nov 21, 9:41 pm, dandreta <[EMAIL PROTECTED]> wrote:
> Thanks for your response, but this doesn't solve the problem.
> I don't know what to do.
> Do you know another way of showing two fields
> joined in a select?
>
> On 20 nov, 22:56, francky06l <[EMAIL PROTECTED]> wrote:
>
> > I do not know if this can be a hint ... I have had the same problem
> > recently (working from the SVN branch).. Again I am not sure, but this
> > was linked to a Cache::config that had a "serialize" => false, in my
> > core.php.
> > I am quite sure it's not related, but  might be a track :
>
> >http://groups.google.com/group/cakephp-edge/browse_thread/thread/d127...
>
> > cheers
>
> > On Nov 20, 8:20 pm, dandreta <[EMAIL PROTECTED]> wrote:
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-21 Thread dandreta

Thanks for your response, but this doesn't solve the problem.
I don't know what to do.
Do you know another way of showing two fields
joined in a select?

On 20 nov, 22:56, francky06l <[EMAIL PROTECTED]> wrote:
> I do not know if this can be a hint ... I have had the same problem
> recently (working from the SVN branch).. Again I am not sure, but this
> was linked to a Cache::config that had a "serialize" => false, in my
> core.php.
> I am quite sure it's not related, but  might be a track :
>
> http://groups.google.com/group/cakephp-edge/browse_thread/thread/d127...
>
> cheers
>
> On Nov 20, 8:20 pm, dandreta <[EMAIL PROTECTED]> wrote:
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-20 Thread francky06l

I do not know if this can be a hint ... I have had the same problem
recently (working from the SVN branch).. Again I am not sure, but this
was linked to a Cache::config that had a "serialize" => false, in my
core.php.
I am quite sure it's not related, but  might be a track :

http://groups.google.com/group/cakephp-edge/browse_thread/thread/d127b7826ae723b3

cheers

On Nov 20, 8:20 pm, dandreta <[EMAIL PROTECTED]> wrote:
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-20 Thread dandreta


>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-19 Thread dandreta

> Set debug to 2 and try fixing your sql error. which will be the source
> of the first error message (this one: Notice (8): Undefined offset:  0
> [CORE/cake/libs/model/datasources/ dbo_source.php, line 882]).
>
> AD

Thanks for your response.
I have tried what you have said to me, but in the sql code I don't
obtain any error.
I don't find a solution, do you know another way of showing two fields
joined in a select?
My version of cake is 1.2 pre-beta.
Regards
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-19 Thread AD7six



On Nov 19, 1:24 pm, dandreta <[EMAIL PROTECTED]> wrote:
> ¿?

Set debug to 2 and try fixing your sql error. which will be the source
of the first error message (this one: Notice (8): Undefined offset:  0
[CORE/cake/libs/model/datasources/ dbo_source.php, line 882]).

AD
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-19 Thread dandreta
¿?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-17 Thread dandreta

Any suggestion?
I have been a lot of time trying to solve the problem but I don´t know
because the warning happens and I do not find a solution.Please,help

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-16 Thread Grant Cox

And what is line 62 of your /app/models/director.php ?


On Nov 16, 2:28 am, dandreta <[EMAIL PROTECTED]> wrote:
> Sorry, I work with cake is 1.2.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-16 Thread dandreta

I have done it like in the link that I have written up, and the line
of the error in the model director.php is:

if ( array_key_exists('firstname',$val[$this->name]) &&
array_key_exists('lastname',$val[$this->name]))

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-15 Thread dandreta

Sorry, I work with cake is 1.2.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object

2007-11-15 Thread dandreta

Hello!
I have one table called Projects and another table called Directors in
my database:
Project belongsTo Director
Director hasMany Project
Adding a new project, I have a select of directors and I want that
they appear with their firstname and lastname and not with their Id.
The fields of the table Director are: Id, firstname, lastname.
I saw how to do it here:

http://groups.google.com/group/cake-php/browse_thread/thread/d4aa1929ce4d61c7/edcacb9354ff1f7a?lnk=gst&q=displayfield#edcacb9354ff1f7a

And the select has the directors with full_name(firstname+lastname).
But the problem is that if I do the index view of projects:



 


And projects_controller:

function index() {
$this->Project->recursive = 2;
$this->set('projects', $this->paginate());
}

The projects and their directors appear correctly but, I obtain these
warnings:

Notice (8): Undefined offset:  0 [CORE/cake/libs/model/datasources/
dbo_source.php, line 882]
Notice (8): Undefined index:  Profesor [CORE/app/models/director.php,
line 63]
Warning (2): array_key_exists() [function.array-key-exists]: The
second argument should be either an array or an object [CORE/app/
models/director.php, line 63]

Why these warnings appear? How can I solve it?
I hope you can help me.
Thanks and regards

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---