未定义的属性:我的代码中的stdClass :: $ account_id错误

时间:2015-04-29 11:48:05

标签: php mysql laravel-4

我遇到了以下错误

  

未定义属性:stdClass :: $ account_id(查看:   C:\ XAMPP \ htdocs中\ laravel \ awsconfig \应用\视图\ search.blade.php)

这是导致此错误的代码:

$resource_types = array();
$resource_types['AWS::EC2::Instance'] = 'EC2Instance';
$resource_types['AWS::EC2::NetworkInterface'] = 'EC2NetworkInterface';
$resource_types['AWS::EC2::VPC'] = 'VPC';
$resource_types['AWS::EC2::Volume'] = 'Volume';
$resource_types['AWS::EC2::SecurityGroup'] = 'EC2SecurityGroup';
$resource_types['AWS::EC2::Subnet'] = 'Subnet';
$resource_types['AWS::EC2::RouteTable'] = 'RouteTable';
$resource_types['AWS::EC2::EIP'] = 'EIP';
$resource_types['AWS::EC2::NetworkAcl'] = 'NetworkAcl';
$resource_types['AWS::EC2::InternetGateway'] = 'InternetGateway';


 $accounts = DB::table('aws_account')->get();
 $account_list = array();




foreach(glob('../app/views/*.json') as $filename)
{
    //echo $filename;
    $data = file_get_contents($filename);

    if($data!=null)

    {


            $decoded=json_decode($data,true);  


            if(isset($decoded["Message"])) 
            { 
            //echo "found message<br>";
                $message= json_decode($decoded["Message"]);
if(isset($message->configurationItem))
{
//  echo"found cfi<br>";    
            $insert_array = array();
                $cfi = $message->configurationItem;
                switch ($cfi->configurationItemStatus)
                {

                    case "ResourceDiscovered":
                //echo"found Resource Discovered<br>";  
                        if (array_key_exists($cfi->resourceType,$resource_types))

                        {
                            //var_dump($cfi->resourceType);
                            $resource = new $resource_types[$cfi->resourceType];

                            foreach ($cfi->configuration as $key => $value)
                            {
                                if (in_array($key,$resource->fields))
                                {
                                    $insert_array[from_camel_case($key)] = $value;
                                }
                            }




                            $resource->populate($insert_array);
                            if (!$resource->checkExists())
                            {
                                $resource->save();

                                    if(isset($cfi->configuration->tags))
                                    {
                                       foreach ($cfi->configuration->tags as $t )

                                        {

                                        $tag= new Tag;
                                    $tag->resource_type = "instance";

                                    $tag->resource_id = $resource->id;
                                    $tag->key = $t->key;
                                    $tag->value = $t->value;

                                    $tag->save();


                                        if(isset($cfi->awsAccountId))
                                    {
                                     foreach ($accounts as $a)

                                     {
                                       $account_list[] = $a->account_id;
                                     }


                                    if (!in_array($account_id,$account_list))
                                    {



                                    $account_id = new Account;
                                    $account_id->aws_account_id = $cfi->awsAccountId;

                                    $account_list[] = $account_id;
                                     $account_id->save();

                                        }        






                                }
                                }
}




                            }

                        }

                        else
                        {
                            echo "Creating ".$cfi["resourceType"]." not yet supported<br>";
                        }





                    break;

我知道这将是愚蠢的事我感谢所有的帮助,一如既往地谢谢

1 个答案:

答案 0 :(得分:2)

根据您的代码,这是一个简单的演示,我将解释,angular.module('stratabet') .directive('donutChart', function(appVersion) { 'use strict'; var directive = { priority: 0, restrict: 'E', scope: { team1: '=', team2: '=' }, controller: function($scope) { console.log('donutChart controller - team1: ' + $scope.team1 + ', team2: ' + $scope.team2); }, link: function(scope, element, attrs) { console.log('donutChart - team1: ' + scope.tea1 + ', team2: ' + scope.team2); } } 将返回一个包含多个对象(可能不止一个)的数组,然后将其分配给DB::select。< / p>

请记住,$this->food看起来像

$this->food

实际上,$ this-&gt; food-&gt;名称正在尝试访问未定义的属性。

解决方案1:

您应该使用Array ( [0] => stdClass Object ( [name] => 'Beef' ) )来访问它。

认为它看起来很奇怪,但它确实有用。

解决方案2:

为什么不拨打$this->food[0]->name来取回对象而不是Food::find($id)

您可以阅读此$food = new food($id)

了解详情

希望这可以帮助您解决问题