我一直在研究一些旧的代码,这些代码是给我玩的和编辑以熟悉的,我想知道你是否可以看到我正在做的是语法合理的声音,因为我迷惑自己与laravel框架。我基本上想知道我是否接近我的意见想做什么,以及我的代码和评论是否结婚或我错过了重点?由于我收到以下错误消息
通过终端运行此命令时获取的错误消息是
PHP Parse error: syntax error, unexpected '$email' (T_VARIABLE), expecting '(' in /Libraryenter code here/WebServer/Documents/healthandsafetymonitoringsystem.local/app/commands/IncompleteReportsCommand.php on line 157
我的代码如下
// This function uses the parameters $data that is passed to this function each time
// the fire() function loops through and assigns and determines that there is a duereport
private function sendGeneralManagerEmail($data)
{
// create an array called 'Park' that is poulated via the $data parameters
// in the function and is specificly looking for the ParkName entries
$data['Park'] = $Park->ParkName;
//for each item in that array use $ParkName as a key and name each elements $name
foreach($data['Park'] as $ParkName => $name)
{
// Every time i loop through this file get the element $name and
// attach this prefix to it
$email = $name."generalmanager@parkholidays.com";
}
// Then send an email with new $email variable as a reciepient and sending the $data passed
// from the fire() function and used within this functions parameters
Mail::send('emails.GeneralManager', $data, function($message) use $email
{
$message->to( $email, 'General Manager')->subject('[Urgent] Health & Safety Reports');
});
}
对于这个愚蠢的问题,如果有任何关于阵列/数据模型和laravel中的php函数的文章,你建议阅读它们会很棒。这是一个陡峭的学习曲线,因为我已经从记事本++上的普通PHP编码转到了laravel 4,我似乎无法找到一个很好的教程,从头到尾都有一个完整的新手。
关心迈克
答案 0 :(得分:0)
您只有PHP语法错误。这是你想要的代码:
// This function uses the parameters $data that is passed to this function each time
// the fire() function loops through and assigns and determines that there is a duereport
private function sendGeneralManagerEmail($data)
{
// create an array called 'Park' that is poulated via the $data parameters
// in the function and is specificly looking for the ParkName entries
$data['Park'] = $Park->ParkName;
//for each item in that array use $ParkName as a key and name each elements $name
foreach($data['Park'] as $ParkName => $name)
{
// Every time i loop through this file get the element $name and
// attach this prefix to it
$email = $name."generalmanager@parkholidays.com";
}
// Then send an email with new $email variable as a reciepient and sending the $data passed
// from the fire() function and used within this functions parameters
Mail::send('emails.GeneralManager', $data, function($message) use ($email)
{
$message->to( $email, 'General Manager')->subject('[Urgent] Health & Safety Reports');
});
}
请在结尾处查看我已更改为use $email
的{{1}}。
我可以看到一些对我来说不合适的事情。这段代码是函数的精确副本还是删除了一些代码?
答案 1 :(得分:0)
很难对代码进行更多说明,因为它已脱离了上下文。 编写新代码作为答案,会让您更加困惑。
所以最好:
订阅laracast,您将了解有关Laravel的所有信息。还有新的,更新的Laravel 4.1 documentation