問題: Laravel 4 コードを Laravel 5.2 に変換しています。ビューを移動して変換しようとしていますが、次のエラーを回避できません。
エラー: IndexController.php 行 27 の ErrorException: 非オブジェクトのプロパティを割り当てようとしています
デバッグ情報:
- IndexController.php の 27 行目
- HandleExceptions->handleError('2', '非オブジェクトのプロパティを割り当てようとしました', 'C:\Apache24\B2B_Contracts\app\Http\Controllers\IndexController.php', '27', array('numberofpcs' = > object(additionalPCs), 'addtpcs' => array('0', '1', '2', '3', '4', '5', '6', '7', '8', ' 9'、'10'、'11'、'12'、'13'、'14'、'15'、'16'、'17'、'18'、'19'、'20'、'21' 、「22」、「23」、「24」、「25」、「26」、「27」、「28」、「29」、「30」、「31」、「32」、「33」、「 34'、'35'、'36'、'37'、'38'、'39'、'40'、'41'、'42'、'43'、'44'、'45'、'46'、'47'、'48'、'49'、'50'、'51'、'52'、'53'、'54 '、'55'、'56'、'57'、'58'、'59'、'60'、'61'、'62'、'63'、'64'、'65'、'66'、 '67'、'68'、'69'、'70'、'71'、'72'、'73'、'74'、'75'、'76'、'77'、'78'、'79 '、'80'、'81'、'82'、'83'、'84'、'85'、'86'、'87'、'88'、'89'、'90'、'91'、 '92'、'93'、'94'、'95'、'96'、'97'、'98'、'99'、'100'))) が IndexController に含まれています。PHP27行目
- IndexController->index() で
リクエスト:エラーが発生する理由を理解するのを手伝ってください。可能であれば、それを防ぐ方法と例で何が間違っているのかを詳細に説明してください.
注:データベースをシードした後、Laravel 4で同様のエラーを受け取っていましたが、移行を更新してデータベースを再シードすると、すべてが再び機能し始めました。これは、Laravel 5 のこのエラーでは機能しません。このコードは L4 で機能します。
試行:私は Google で多くのことを読んでおり、php artisan clear-compiled、composer dump-autoload、php artisan optimizeなどのさまざまな項目を試しましたが、役に立ちませんでした。エラーは$numberofpcs = new additionalPCs()から来ていると思います。しかし、私はそれを確認できませんでした。ビューに送信しているすべての変数も削除しましたが、エラーは引き続き発生するため、 $this->layout->content = View::make('index'); のように見えました。
IndexController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Library\additionalPCs;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use View;
use App\Models\businesstype;
use App\Models\contractterm;
class IndexController extends BaseController
{
Protected $layout = 'master';
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
/** Wayne - 03-02-2014 - Moved for loop to a method within its own class. */
$numberofpcs = new additionalPCs();
$addtpcs=$numberofpcs->display();
$this->layout->content = View::make('index')->with('addtpcs', $addtpcs)->with('businesstypelist', businesstype::dropdown())->with('contracttermlist',ContractTerm::dropdown());
}
}
additionalPCs.php
<?php
namespace App\Library;
use App\Library\additionalComputer;
class additionalPCs extends additionalComputer {
public function display() {
return $this->displayMenu();
}
}
追加のComputer.php
<?php
namespace App\Library;
/** Counts up the Number of Additional PC Options
* and stores them into an array then sends them to the view.
*/
class additionalComputer {
protected function displayMenu() {
$addtpcs= [];
for ($i=0; $i <= 100; $i++) {
$addtpcs[$i] = $i;
}
return $addtpcs;
}
}
BaseController.php - (これは、IndexController 用の BaseController.php ファイルがあることを示すためだけのものです。L5 にはデフォルトで同梱されていないことを認識しています。)
<?php
namespace App\Http\Controllers;
class BaseController extends Controller {
/**
* Setup the layout used by the controller.
*
* @return void
*/
protected function setupLayout()
{
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
}
}