the error is happen because i use variable as model name
$model_data = $this->AreaInfo->{$model_name}->find('list');

but although its give me error and stop the php compile on that ** line
its still could fetch data from that $model_name table..
that is why the $model_data have value when i try to print it.

my question is how to get rid this error?

sorry for my bad english before :)



________________________________
From: brian <bally.z...@gmail.com>
To: cake-php@googlegroups.com
Sent: Thursday, January 22, 2009 2:10:17 PM
Subject: Re: Dynamic Model Call


I don't think I understand what your question is, then. Yes, you can
use a variable as the model name, if used the way I showed you. But,
where did this error come from? If it was from the find() line, how is
it that your array has data in it?

On Wed, Jan 21, 2009 at 11:22 PM, Yusuf Widiyatmono <wmo...@yahoo.com> wrote:
> sorry it just a mark for the code line.
>
> Fatal error: Cannot access empty property in
> {some_directories_path}\app\controllers\areas_controller.php on line **
>
> i mean that i got that message from this line
>
> $model_data = $this->AreaInfo->$model_name->find('list');    **
>
>
>
>
>
> ________________________________
> From: brian <bally.z...@gmail.com>
> To: cake-php@googlegroups.com
> Sent: Thursday, January 22, 2009 1:06:39 PM
> Subject: Re: Dynamic Model Call
>
>
> What is on line** (from the error msg)?
>
> On Wed, Jan 21, 2009 at 10:37 PM, Yusuf Widiyatmono <wmo...@yahoo.com>
> wrote:
>> the model is loaded...
>> see the print_r result, the model can retrieve some data,
>> but in the end the error still appear and make the further logic die
>>
>>
>>
>> ________________________________
>> From: brian <bally.z...@gmail.com>
>> To: cake-php@googlegroups.com
>> Sent: Thursday, January 22, 2009 12:30:22 PM
>> Subject: Re: Dynamic Model Call
>>
>>
>> Are these models loaded?
>>
>> On Wed, Jan 21, 2009 at 6:10 PM, Yusuf Widiyatmono <wmo...@yahoo.com>
>> wrote:
>>> i did and it still shows me same errors...
>>>
>>>
>>> ________________________________
>>> From: brian <bally.z...@gmail.com>
>>> To: cake-php@googlegroups.com
>>> Sent: Thursday, January 22, 2009 2:49:31 AM
>>> Subject: Re: Dynamic Model Call
>>>
>>>
>>> Try $this->AreaInfo->{$model_name}->find(...)
>>>
>>> On Wed, Jan 21, 2009 at 12:33 AM, wmonou <wmo...@gmail.com> wrote:
>>>>
>>>> Helo there i am trying to call model from a variable
>>>>
>>>> let say that i have a code is like this:
>>>>
>>>>        // $model_name is a string
>>>>        // bind necessary model
>>>>        if(!empty($model_name)){
>>>>                $this->AreaInfo->bindModel(
>>>>                        array(
>>>>                                'belongsTo'=>array(
>>>>                                        $model_name => array(
>>>>                                                'className' =>
>>>> $model_name,
>>>>                                                'foreignKey' =>
>>>> 'reference_id'
>>>>                                                )
>>>>                                        )
>>>>                                )
>>>>                        );
>>>>                }
>>>>
>>>>        $model_data = $this->AreaInfo->$model_name->find('list');    //
>>>> **
>>>> this is my question
>>>>        print_r($model_data);
>>>>
>>>> the $model_data variable now is not empty, but i got something like
>>>> this :
>>>>
>>>> Array
>>>> (
>>>>    [1] => 1
>>>>    [2] => 2
>>>>    [3] => 3
>>>>    [4] => 4
>>>>    [5] => 5
>>>>    [6] => 6
>>>>    [7] => 7
>>>>    [8] => 8
>>>>    [9] => 9
>>>>    [10] => 10
>>>>    [11] => 11
>>>>    [12] => 12
>>>>    [13] => 13
>>>>    [14] => 14
>>>>    [15] => 15
>>>>    [16] => 16
>>>>    [17] => 17
>>>>    [18] => 18
>>>>    [19] => 19
>>>>    [20] => 20
>>>> )
>>>>
>>>> Fatal error: Cannot access empty property in {some_directories_path}
>>>> \app\controllers\areas_controller.php on line **
>>>>
>>>> is it possible to do such a thing like above? if yes or no please let
>>>> me know with your sugesstion :) ...
>>>>
>>>> >
>>>>
>>>
>>>
>>> >
>>>
>>
>>
>> >
>>
>
>
> >
>



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

Reply via email to