2017-08-04 87 views
0

CentOS 3.10.0-327.36.3.el7.x86_64, PHP 7.0.12Zend框架 - 錯誤不會登錄

public function render($html, $input) { 
    $view = new ViewModel($input); 
    $view->setTemplate($html); 
    $viewRenderer = $this->getServiceLocator()->get('ViewRenderer'); 
    return $viewRenderer->render($view); 

    } 

在舊的PHP和舊的CentOS的工作,但當我遷移到新服務器失敗。

PHP Deprecated: You are retrieving the service locator from within the class Application\\Controller\\MainController. Please be aware that ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along with the ServiceLocatorAwareInitializer. You will need to update your class to accept all dependencies at creation, either via constructor arguments or setters, and use a factory to perform the injections. in /home/www/html/xxmanager/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php on line 258, referer: https://xx.xx.com/ 



244  /** 
245  * Retrieve serviceManager instance 
246  * 
247  * @return ServiceLocatorInterface 
248  */ 
249  public function getServiceLocator() 
250  { 
251   trigger_error(sprintf(
252    'You are retrieving the service locator from within the class %s. Please be aware that ' 
253    . 'ServiceLocatorAwareInterface is deprecated and will be removed in version 3.0, along ' 
254    . 'with the ServiceLocatorAwareInitializer. You will need to update your class to accept ' 
255    . 'all dependencies at creation, either via constructor arguments or setters, and use ' 
256    . 'a factory to perform the injections.', 
257    get_class($this) 
258  ), E_USER_DEPRECATED); 
259 
260   return $this->serviceLocator; 
261  } 

編輯:

步驟1:取出新

$ echo '' > composer.lock 

步驟2:插入舊到composer.lock

{ 
    "hash": "3d8fc311b085e1e9bc4ed181947f205d", 
    "packages": [ 
     { 
      "package": "zendframework/zendframework", 
      "version": "2.0.3" 
     } 
    ], 
    "packages-dev": null, 
    "aliases": [ 

    ], 
    "minimum-stability": "stable", 
    "stability-flags": [ 

    ] 
} 

步驟3:刪除新供應商

$ rm -fr vendor 

步驟4:嘗試安裝和故障

$ ./composer.phar install 


    [RuntimeException]                            
    Your composer.lock was created before 2012-09-15, and is not supported anymore. Run "composer update" to generate a new one. 


install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]... 

編輯2:

# cat composer.json 
{ 
    "name": "zendframework/skeleton-application", 
    "description": "Skeleton Application for ZF2", 
    "license": "BSD-3-Clause", 
    "keywords": [ 
     "framework", 
     "zf2" 
    ], 
    "homepage": "http://framework.zend.com/", 
    "require": { 
     "php": ">=5.3.3", 
     "zendframework/zendframework": "2.2.10" 
    } 
} 

# php composer.phar install 
Loading composer repositories with package information 
Updating dependencies (including require-dev) 
Package operations: 2 installs, 0 updates, 0 removals 
    - Installing zendframework/zendxml (1.0.2): Loading from cache 
    - Installing zendframework/zendframework (2.2.10): Downloading (100%)   
zendframework/zendframework suggests installing doctrine/annotations (Doctrine Annotations >=1.0 for annotation features) 
zendframework/zendframework suggests installing ext-intl (ext/intl for i18n features (included in default builds of PHP)) 
zendframework/zendframework suggests installing ircmaxell/random-lib (Fallback random byte generator for Zend\Math\Rand if OpenSSL/Mcrypt extensions are unavailable) 
zendframework/zendframework suggests installing ocramius/proxy-manager (ProxyManager to handle lazy initialization of services) 
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf for creating PDF representations of barcodes) 
zendframework/zendframework suggests installing zendframework/zendservice-recaptcha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\Form) 
Writing lock file 
Generating autoload files 

失敗: 錯誤:PHP的致命錯誤:未捕獲的錯誤:調用未定義的功能應用\ Controller \ mysql_real_escape_string()

+1

舊的PHP意味着什麼? –

+0

在我的另一臺服務器上工作:PHP 5.3.3(cli)(built:Oct 30 2014 20:12:53) – YumYumYum

+0

在我的新服務器不工作:PHP 7.0.12(cli)(built:Oct 14 2016 09:23 :01)(NTS) – YumYumYum

回答

1

它看起來真的很重要新服務r是您的vendor/文件夾內容。看起來,一旦你部署你的軟件,你安裝了依賴關係composer update而不是composer install或者你沒有composer.lock文件保留。

速戰速決應該是簡單地複製舊機器composer.lock文件,擦上一個新的文件夾vendor/並重新做composer install應然後根據composer.lock內容。

編輯

Your composer.lock was created before 2012-09-15

看來你的舊體制是真的老了。你可以做的是更新你的composer.json請求剛好你在舊系統上有相同的版本。這很簡單,你需要做的就是看看你在OLD系統上得到了什麼,並提出新的請求。

所以名單已安裝的版本與composer show

$ composer show 

foo/bar   1.4.3 Some description 
.... 

新的系統然後編輯composer.json和更新所有版本的約束指向完全相同的版本。即而不是

'require': { 
    'foo/bar': '~1.0', 
    ... 
} 

你需要把通過composer show所示版本爲foo/bar

'require': { 
    'foo/bar': '1.4.3', 
    ... 
} 

然後取出composer.lockvendor/,做composer install,你應該是不錯的。

+1

我編輯我的答案在此期間,所以請再讀一遍,因爲現在它應該更精確如何恢復 –

+0

請參閱我的上述編輯。我嘗試過,但compoer安裝失敗,並要求我做其他事情(在過去,當我跟着它的指令擰) – YumYumYum

+1

見編輯答案。 –