如何解决Undefined属性

时间:2016-05-15 10:22:08

标签: php

我有我在PHP中的nubie。 我有一个问题。

PM> Enable-Migrations -ContextTypeName HRHR.Models.ListofvacanciesEntities Checking if the context targets an existing database... 
System.TypeInitializationException: The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception.
---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. 
---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize 
---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section compilation. (C:\Users\Taras\documents\visual studio 2015\Projects\HRHR\HRHR\tmpAE68.tmp line 7)
       at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
       at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
       at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
       at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       --- End of inner exception stack trace ---
       at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
       at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
       at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
       at System.Configuration.ConfigurationManager.get_ConnectionStrings()
       at System.Data.Entity.Internal.AppConfig..ctor()
       at System.Data.Entity.Internal.AppConfig..cctor()
       --- End of inner exception stack trace ---
       at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForAssembly(Assembly assemblyHint, Type contextTypeHint)
       at System.Data.Entity.Infrastructure.DependencyResolution.DbConfigurationManager.EnsureLoadedForContext(Type contextType)
       at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..cctor()
       --- End of inner exception stack trace ---
       at System.Data.Entity.Migrations.DbMigrationsConfiguration`1..ctor()
       at HRHR.Migrations.Configuration..ctor() in C:\Users\Taras\documents\visual studio 2015\Projects\HRHR\HRHR\Migrations\Configuration.cs:line 10
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
       at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
       at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
       at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldInitialCreate(String language, String rootNamespace)
       at System.Data.Entity.Migrations.EnableMigrationsCommand.<>c__DisplayClass2.<.ctor>b__0()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception.

你能帮我解决一下这个问题吗? 我附上了swipe.php文件。

谢谢。

2 个答案:

答案 0 :(得分:1)

将您的代码更改为此

public function getContent() {
        $this->_html = '<img src="'.$this->_p otocol.$this->context->shop->domain.$this->_path.'logo-big.png" style="margin-bottom:20px" />';
        if (Tools::isSubmit('btnSubmit')) {
            $this->_postValidation();
            if (isset($this->_postErrors)
            {
            if (!count($this->_postErrors))
                $this->_postProcess();
            else
                foreach ($this->_postErrors as $err)
                    $this->_html .= '<div class="alert error">' . $err . '</div>';
           }
        }
        else
            $this->_html .= '<br />';

        $this->_displayTop();
        $this->_displayForm();

        return $this->_html;
    }
    }

当您访问房产时该属性不存在此错误发生。在生产中,此错误不会显示,因为您不会在生产中显示任何错误,但在开发过程中,最好显示所有错误。

使用isset函数检查属性是否存在。

答案 1 :(得分:0)

将您的if条件更改为

if (empty($this->_postErrors))
    $this->_postProcess();

这样,如果$this->_postErrors未定义,您的条件也会起作用。