我正在使用Laravel 4框架处理事件管理器,并在/app/models/Event.php
中创建了一个新模型。在这个文件中,我有方法public function postCreateEvent($eventDetails)
。我收到错误Call to undefined method Illuminate\Events\Dispatcher::postCreateEvent()
。任何人都可以帮我确定为什么Laravel 4没有找到模型中的功能吗?
/app/controllers/Events/Controllers/Manager/ManagerController.php是:
<?php
namespace Events\Controllers\Manager;
use \View, \BaseController, \Site, \Event, \Input;
class ManagerController extends BaseController
{
//This control ensures the user is logged in before they can view any of the manager pages or use the manager actions
public function __construct()
{
$this->beforeFilter('auth');
}
//This control gets the correct manager page and displays it
public function getManager($nav = null)
{
if ($nav == null)
{
return View::make('manager');
}
else
{
return View::make('manager/'.$nav);
}
}
//This control takes the site settings page when it is POSTed and moves it to the model to update the site settings.
public function postSiteSettings()
{
$siteSettings = array(
'siteTitle' => Input::get('siteTitle'),
'siteAddress' => Input::get('siteAddress'),
'adminEmail' => Input::get('adminEmail'),
'openRegistrations' => Input::get('openRegistrations')
);
Site::postSiteSettings($siteSettings);
return View::make('manager/settings');
}
public function postCreateEvent()
{
$eventDetails = array(
'eventCalendar' => Input::get('siteTitle'),
'eventName' => Input::get('eventName'),
'eventDescription' => Input::get('eventDescription'),
'eventCapacity' => Input::get('eventCapacity'),
'eventRegistrationType' => Input::get('eventRegistrationType'),
'eventLocationName' => Input::get('eventLocationName'),
'eventLocationAddress1' => Input::get('eventLocationAddress1'),
'eventLocationAddress2' => Input::get('eventLocationAddress2'),
'eventLocationAddress3' => Input::get('eventLocationAddress3'),
'eventLocationCity' => Input::get('eventLocationCity'),
'eventLocationState' => Input::get('eventLocationState'),
'eventLocationZIP' => Input::get('eventLocationZIP'),
'eventLocationCountry' => Input::get('eventLocationCountry'),
'eventLocationPhone' => Input::get('eventLocationPhone'),
'eventStartDate' => Input::get('eventStartDate'),
'eventEndDate' => Input::get('eventEndDate'),
'eventStartTime' => Input::get('eventStartTime'),
'eventEndTime' => Input::get('eventEndTime'),
'eventRSVPEndDate' => Input::get('eventRSVPEndDate'),
'eventPublishDate' => Input::get('eventPublishDate'),
'eventArchiveDate' => Input::get('eventArchiveDate')
);
$event = new Event;
if (Event::postCreateEvent($eventDetails))
{
return View::make('manager/createEvent');
}
else
{
echo "WTF....";
}
}
}
/app/models/Event.php是:
<?php
class Event extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'events';
/**
* Add New Event To The Database
*
* @param array
* @return booelan
*/
public function postCreateEvent($eventDetails)
{
$event = new Event;
$event->eventCalendar = $eventDetails['eventCalendar'];
$event->eventName = $eventDetails['eventName'];
$event->eventDescription = $eventDetails['eventDescription'];
$event->eventCapacity = $eventDetails['eventCapacity'];
$event->eventRegistrationType = $eventDetails['eventRegistrationType'];
$event->eventLocationName = $eventDetails['eventLocationName'];
$event->eventLocationAddress1 = $eventDetails['eventLocationAddress1'];
$event->eventLocationAddress2 = $eventDetails['eventLocationAddress2'];
$event->eventLocationAddress3 = $eventDetails['eventLocationAddress3'];
$event->eventLocationCity = $eventDetails['eventLocationCity'];
$event->eventLocationState = $eventDetails['eventLocationState'];
$event->eventLocationZIP = $eventDetails['eventLocationZIP'];
$event->eventLocationCountry = $eventDetails['eventLocationCountry'];
$event->eventLocationPhone = $eventDetails['eventLocationPhone'];
$event->eventStartDate = $eventDetails['eventStartDate'];
$event->eventEndDate = $eventDetails['eventEndDate'];
$event->eventStartTime = $eventDetails['eventStartTime'];
$event->eventEndTime = $eventDetails['eventEndTime'];
$event->eventRSVPEndDate = $eventDetails['eventRSVPEndDate'];
$event->eventPublishDate = $eventDetails['eventPublishDate'];
$event->eventArchiveDate = $eventDetails['eventArchiveDate'];
$event->created_at = date('Y-m-d H:i:s');
$event->updated_at = date('Y-m-d H:i:s');
if ($event->save())
{
return true;
}
else
{
return false;
}
}
public static function test()
{
echo "True";
}
}
有人能看出为什么Laravel 4没有在模型中找到这个功能吗?
答案 0 :(得分:2)
类Event已经存在于框架中,而这就是你在
中调用的内容 Event::postCreateEvent($eventDetails)
因此它尝试在框架的postCreateEvent
类上调用Event
方法,但该方法不存在。
如果有帮助,请尝试将类名更改为其他名称。