【问题标题】:How to call plugin controller action from base application?如何从基础应用程序调用插件控制器操作?
【发布时间】:2014-03-19 20:23:56
【问题描述】:

我正在开发一个 CakePHP 应用程序并安装了 Silas Montgomery 的 Cake FullCalendar 插件。

我创建了一个表来记录人们何时参加由插件管理的事件。所以我有这个模型:

<?php
App::uses('AppModel', 'Model');
class Attendance extends AppModel {
public $primaryKey = 'idattendance';

public $belongsTo = array(
    'PeopleAttendance' => array(
        'className' => 'People',
        'foreignKey' => 'idpeople',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    ),
    'AttendanceEvent' => array(
        'className' => 'FullCalendar.Event',
        'foreignKey' => 'idevent',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);
}

如何在出勤视图中调用 FullCallendar 操作(比如 add() 来添加事件)?

这行得通...

echo $this->Html->link(__('New Event'),'http://localhost:8888/project/full_calendar/events/add');

...但对我来说,这似乎不是“正确的”...

使用此类插件时最好的方法是什么?另外,我还没有完全测试,但我猜我的模型也不正确......

【问题讨论】:

    标签: cakephp cakephp-2.4


    【解决方案1】:

    您应该在链接数组中添加一个选项“插件”:

    $this->Html->link(__('New Event'), array('controller' => 'events', 'action' => 'add', 'plugin' => 'full_calendar'));
    

    【讨论】:

    • 感谢您的帮助。出于单纯的好奇。如果我 BAKE 视图,为什么 Cake 不能通过查看关联找出正确的链接?
    【解决方案2】:

    您可以使用plugin 选项链接到插件操作:

    echo $this->Html->link(
        __('New Event'),
        array(
            'plugin' => 'full_calendar', // Define the plugin here as option
            'controller' => 'events',
            'action' => 'add'
        )
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-15
      • 2011-07-22
      • 2013-11-27
      • 1970-01-01
      • 2021-04-26
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      相关资源
      最近更新 更多