本文整理汇总了PHP中CakeEvent类的典型用法代码示例。如果您正苦于以下问题:PHP CakeEvent类的具体用法?PHP CakeEvent怎么用?PHP CakeEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CakeEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formAfterSubmit
/**
* Form After Submit
*
* フォームの保存ボタンの前後に、一覧、プレビュー、削除ボタンを配置する
* プレビューを配置する場合は、設定にて、preview を true にする
*
* @param CakeEvent $event
* @return string
*/
public function formAfterSubmit(CakeEvent $event)
{
if (!BcUtil::isAdminSystem()) {
return;
}
$View = $event->subject();
$data = $View->request->data;
if (!preg_match('/(AdminEditForm|AdminEditAliasForm)$/', $event->data['id'])) {
return;
}
$output = $View->BcHtml->link('一覧に戻る', array('plugin' => '', 'admin' => true, 'controller' => 'contents', 'action' => 'index'), array('class' => 'button'));
$setting = Configure::read('BcContents.items.' . $data['Content']['plugin'] . '.' . $data['Content']['type']);
if (!empty($setting['preview']) && $data['Content']['type'] != 'ContentFolder') {
$output .= "\n" . $View->BcForm->button('プレビュー', array('class' => 'button', 'id' => 'BtnPreview'));
}
$output .= $event->data['out'];
if (empty($data['Content']['site_root'])) {
if ($data['Content']['alias_id']) {
$deleteText = '削除';
} else {
$deleteText = 'ゴミ箱へ移動';
}
$output .= $View->BcForm->button($deleteText, array('class' => 'button', 'id' => 'BtnDelete'));
}
return $output;
}
示例2: formAfterEnd
/**
* formAfterCreate
*
* @param CakeEvent $event
* @return array
*/
public function formAfterEnd(CakeEvent $event)
{
$Form = $event->subject();
if ($Form->request->params['controller'] == 'blog_posts') {
if (!empty($Form->request->data['PetitBlogCustomFieldConfig']['status'])) {
// ブログ記事追加画面にプチ・カスタムフィールド編集欄を追加する
if ($Form->request->action == 'admin_add') {
if ($event->data['id'] == 'BlogPostForm') {
$event->data['out'] = $event->data['out'] . $Form->element('PetitBlogCustomField.petit_blog_custom_field_form');
}
}
// ブログ記事編集画面にプチ・カスタムフィールド編集欄を追加する
if ($Form->request->action == 'admin_edit') {
if ($event->data['id'] == 'BlogPostForm') {
$event->data['out'] = $event->data['out'] . $Form->element('PetitBlogCustomField.petit_blog_custom_field_form');
}
}
}
}
if ($Form->request->params['controller'] == 'blog_contents') {
// ブログ設定編集画面にプチ・カスタムフィールド設定欄を表示する
if ($Form->request->action == 'admin_edit') {
if ($event->data['id'] == 'BlogContentAdminEditForm') {
$event->data['out'] = $event->data['out'] . $Form->element('PetitBlogCustomField.petit_blog_custom_field_config_form');
}
}
// ブログ追加画面にプチ・カスタムフィールド設定欄を表示する
if ($Form->request->action == 'admin_add') {
if ($event->data['id'] == 'BlogContentAdminAddForm') {
$event->data['out'] = $event->data['out'] . $Form->element('PetitBlogCustomField.petit_blog_custom_field_config_form');
}
}
}
return $event->data['out'];
}
示例3: beforeDispatch
/**
* Checks if a requested asset exists and sends it to the browser
*
* @param CakeEvent $event containing the request and response object
* @return mixed The resulting response.
* @throws NotFoundException When asset not found
*/
public function beforeDispatch(CakeEvent $event)
{
$url = urldecode($event->data['request']->url);
if (strpos($url, '..') !== false || strpos($url, '.') === false) {
return;
}
// CUSTOMIZE DELETE 2014/07/02 ryuring
// >>>
/*if ($result = $this->_filterAsset($event)) {
$event->stopPropagation();
return $result;
}*/
// <<<
$assetFile = $this->_getAssetFile($url);
if ($assetFile === null || !file_exists($assetFile)) {
return null;
}
$response = $event->data['response'];
$event->stopPropagation();
$response->modified(filemtime($assetFile));
if ($response->checkNotModified($event->data['request'])) {
return $response;
}
$pathSegments = explode('.', $url);
$ext = array_pop($pathSegments);
$this->_deliverAsset($response, $assetFile, $ext);
return $response;
}
示例4: modelConstruct
public function modelConstruct(CakeEvent $Event)
{
$Model = $Event->subject();
// Because, by default, the SQL is only logged and displayed if debug > 2; using the `DebugKit`
// new 'autoRun' and/or 'forceEnable' still doesn't help in profiling SQL calls in production.
// This will force the current model's datasource to log all SQL calls ONLY when in production
// mode and DebugKit is used with either 'autoRun' or 'forceEnable'.
if (Reveal::is('DebugKit.running') && !Reveal::is('Page.test')) {
$Model->getDatasource()->fullDebug = true;
}
if (!isset($Model->belongsToForeignModels)) {
return;
}
// Get all foreign models used if not defined by current model.
if (empty($Model->belongsToForeignModels)) {
$foreignModels = $Model->find('all', array('fields' => array('DISTINCT' => 'foreign_model'), 'recursive' => -1, 'callbacks' => false));
foreach ($foreignModels as $foreignModel) {
// Rarely, some tokens are not associated with any other model.
if (empty($foreignModel[$Model->alias]['foreign_model'])) {
continue;
}
list($plugin, $name) = pluginSplit($foreignModel[$Model->alias]['foreign_model']);
$Model->belongsToForeignModels[$name] = array('className' => $foreignModel[$Model->alias]['foreign_model'], 'foreignKey' => 'foreign_key', 'conditions' => null, 'fields' => null, 'order' => null, 'counterCache' => false);
}
}
// Associate foreign `belongsTo` models.
$Event->result = Hash::merge((array) $Event->result, array('belongsTo' => array_merge($Model->belongsTo, $Model->belongsToForeignModels)));
}
示例5: onAdminLoginSuccessful
/**
* onAdminLoginSuccessful
*
* @param CakeEvent $event
* @return void
*/
public function onAdminLoginSuccessful($event)
{
$Controller = $event->subject();
$message = __('Welcome %s. Have a nice day', $Controller->Auth->user('name'));
$Controller->Session->setFlash($message);
$Controller->redirect(array('admin' => true, 'plugin' => 'example', 'controller' => 'example', 'action' => 'index'));
}
示例6: formAfterInput
/**
* formAfterInput
*
* @param CakeEvent $event
* @return string
*/
public function formAfterInput(CakeEvent $event)
{
if (!BcUtil::isAdminSystem()) {
return $event->data['out'];
}
$View = $event->subject();
if (!in_array($View->request->params['controller'], $this->targetController)) {
return $event->data['out'];
}
if (!in_array($View->request->params['action'], $this->targetAction)) {
return $event->data['out'];
}
if (!isset($View->request->data['KeywordConfig'])) {
return $event->data['out'];
}
if (!$View->request->data['KeywordConfig']['status']) {
return $event->data['out'];
}
// 固定ページ:入力欄の下にキーワード入力欄を表示する
if ($event->data['fieldName'] == 'Page.description') {
$event->data['out'] = $event->data['out'] . $View->element('Keyword.keyword_form');
}
// ブログ記事:記事タイトル入力欄の下にキーワード入力欄を表示する
if ($event->data['fieldName'] == 'BlogPost.name') {
$event->data['out'] = $event->data['out'] . $View->element('Keyword.keyword_form');
}
return $event->data['out'];
}
示例7: beforeDispatch
/**
* Checks whether the response was cached and set the body accordingly.
*
* @param CakeEvent $event containing the request and response object
* @return CakeResponse with cached content if found, null otherwise
*/
public function beforeDispatch(CakeEvent $event)
{
if (Configure::read('Cache.check') !== true) {
return;
}
$path = $event->data['request']->here();
if ($path === '/') {
$path = 'home';
}
$prefix = Configure::read('Cache.viewPrefix');
if ($prefix) {
$path = $prefix . '_' . $path;
}
$path = strtolower(Inflector::slug($path));
$filename = CACHE . 'views' . DS . $path . '.php';
if (!file_exists($filename)) {
$filename = CACHE . 'views' . DS . $path . '_index.php';
}
if (file_exists($filename)) {
$controller = null;
$view = new View($controller);
$result = $view->renderCache($filename, microtime(true));
if ($result !== false) {
$event->stopPropagation();
$event->data['response']->body($result);
return $event->data['response'];
}
}
}
示例8: beforeDispatch
public function beforeDispatch(CakeEvent $event)
{
$MaintenanceMode = Configure::read('MaintenanceMode');
/* Not in maintenance mode*/
if (!$MaintenanceMode['enabled']) {
return;
}
/* Allow access from following IPS*/
if (!empty($MaintenanceMode['ip_filters'])) {
if (!is_array($MaintenanceMode['ip_filters'])) {
$ips = array($MaintenanceMode['ip_filters']);
} else {
$ips = $MaintenanceMode['ip_filters'];
}
$userIP = $this->_getUserIpAddr();
foreach ($ips as $ip) {
if ($this->_compareIp($userIP, $ip)) {
return;
}
}
}
$statusCode = 503;
$body = 'Currently undergoing maintenance';
if (!empty($MaintenanceMode['code'])) {
$statusCode = $MaintenanceMode['code'];
}
if (!empty($MaintenanceMode['view']['template'])) {
$View = $this->_getView();
$body = $View->render($MaintenanceMode['view']['template'], $MaintenanceMode['view']['layout']);
}
$event->data['response']->statusCode($statusCode);
$event->data['response']->body($body);
$event->stopPropagation();
return $event->data['response'];
}
示例9: testPropagation
/**
* Tests the event propagation stopping property
*
* @return void
* @triggers fake.event
*/
public function testPropagation()
{
$event = new CakeEvent('fake.event');
$this->assertFalse($event->isStopped());
$event->stopPropagation();
$this->assertTrue($event->isStopped());
}
示例10: afterRender
/**
* After Render
*
* @param CakeEvent $event
*/
public function afterRender(CakeEvent $event)
{
if (BcUtil::isAdminSystem()) {
return;
}
$View = $event->subject();
$this->_execShortCode($View);
}
示例11: onLogin
/**
* AuthController onLogin
* @param CakeEvent $event
*/
public function onLogin($event)
{
$this->log(__("User '%s' just logged in", $event->data['username']), 'auth');
//Write LastLogin Date
$event->subject()->BackendUser->id = $event->data['id'];
$event->subject()->BackendUser->saveField('last_login', date("Y-m-d H:i:s"));
//return $redirectUri;
}
示例12: blogBlogBeforeRender
/**
* 拡張BlogHelperを呼び出しに追加
*
*/
public function blogBlogBeforeRender(CakeEvent $event)
{
$path = App::pluginPath('ExHelper');
// ヘルパーのパスを追加
App::build(array('View/Helper' => array($path . 'View' . DS . 'Helper' . DS)), APP::APPEND);
$Controller = $event->subject();
$Controller->helpers[] = 'ExBlog';
}
示例13: onSubscribeNewTopic
/**
* Start the keep alive timer when the first client subscribes
*
* @param CakeEvent $event
*/
public function onSubscribeNewTopic(CakeEvent $event)
{
if (Configure::read('Ratchet.Connection.keepaliveInterval') > 0) {
$this->__timer = $this->__loop->addPeriodicTimer(Configure::read('Ratchet.Connection.keepaliveInterval'), function () use($event) {
$event->subject()->broadcast('Rachet.connection.keepAlive', ['ping']);
});
$event->subject()->broadcast('Rachet.connection.keepAlive', ['ping']);
}
}
示例14: handleAfterCreateComment
/**
* Test event listener for before create comment
*
* @param CakeEvent $event
* @return mixed
*/
public function handleAfterCreateComment(CakeEvent $event)
{
$data = $event->data;
$model = $event->subject();
$comment = $model->Comment->read(null, $data['Comment']['id']);
$comment['Comment']['body'] = 'Changed in afterComment!';
$model->Comment->save($comment);
return $data;
}
示例15: blogBlogStartup
function blogBlogStartup(CakeEvent $event)
{
$Controller = $event->subject();
if (!isset($Controller->contentId) || $Controller->contentId != Configure::read('BlogShare.contentId')) {
return;
}
$dbConfigName = Configure::read('BlogShare.dbConfigName');
$Controller->BlogPost->setDataSource($dbConfigName);
$Controller->BlogPost->BlogCategory->setDataSource($dbConfigName);
$Controller->BlogPost->BlogTag->setDataSource($dbConfigName);
}