0

我正在使用 CakePHP 开发一个发票系统,它从一开始就相当基本。我使用博客教程 ( http://book.cakephp.org/2.0/en/getting-started.html ) 作为我项目的基础。我还安装了 Twitter 的 Bootstrap 框架。

我正在使用标签进行导航。因此,目前用户将拥有以下选项卡选项:

摘要 - 发票 - 费用 - 银行业务 - 联系人 - 更多

在 Apps->View 文件夹中,我有一个 Contacts 文件夹和一个 Invoices 文件夹,这些文件夹包含以下文件:

index.ctp - 这是页面的一般布局,即发票和联系人,它只是一个列出数据库中所有条目的表格。

view.ctp - 当用户单击表条目时显示详细视图。

add.ctp - 每个视图都有一个添加按钮,这个脚本是添加页面的布局。

在 Apps->View->Elements 文件夹中,我有标签式导航 (tabs.ctp) 的代码。我在 Apps->View->Contacts->index.ctp & Apps->View->Invoices->index.ctp 中有以下代码行:

<? echo $this->element('tabs'); ?>

这将在每个视图中显示选项卡式导航。

在我的 App->Config->routes.php 我有以下代码:

Router::connect('/', array('controller' => 'invoices', 'action' => 'index'));

显然,这使得 Apps->View->Invoices->index.ctp 成为用户查看的初始页面。

但是当应用程序加载时,我可以看到没有问题的发票页面,但是当我尝试点击联系人选项卡时没有任何反应。当我查看源代码时,没有加载联系人视图代码。

我可能错误地布置了项目,所以任何帮助表示赞赏。

更新: 来自 ContactsController.php 的代码:

<?php
class ContactsController extends AppController {
    public $helpers = array('Html', 'Form', 'Session');
    public $components = array('Session');

    public function index() {
        $this->set('contacts', $this->Contact->find('all'));
    }

    public function view($id) {
        if (!$id) {
            throw new NotFoundException(__('Invalid contact'));
        }

        $contact = $this->Contact->findById($id);
        if (!$contact) {
            throw new NotFoundException(__('Invalid contact'));
        }
        $this->set('contact', $contact);
    }

    public function add() {
        if ($this->request->is('contact')) {
            $this->Contact->create();
            if ($this->Contact->save($this->request->data)) {
                $this->Session->setFlash('Your contact has been saved.');
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash('Unable to add your contact.');
            }
        }
    }
}

更新 来自 routes.php 的示例代码:

/**
 * Here, we are connecting '/' (base path) to controller called 'Pages',
 * its action called 'display', and we pass a param to select the view file
 * to use (in this case, /app/View/Pages/home.ctp)...
 */
    //Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
    Router::connect('/', array('controller' => 'invoices', 'action' => 'index'));   
/**
 * ...and connect the rest of 'Pages' controller's urls.
 */
    Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); 

/**
 * Load all plugin routes.  See the CakePlugin documentation on
 * how to customize the loading of plugin routes.
 */
    CakePlugin::routes();

/**
 * Load the CakePHP default routes. Only remove this if you do not want to use
 * the built-in default routes.
 */
    require CAKE . 'Config' . DS . 'routes.php';

问候,斯蒂芬

4

2 回答 2

0

您可能还想清除您的蛋糕核心缓存,例如

app/tmp/cache/*/*
于 2013-04-07T18:21:06.003 回答
0

确保您创建的“联系人”选项卡的链接格式正确。例如;

<?php echo $this->Html->link('Contacts',array('controller'=>'contacts','action'=>'index'); ?>

如果您正确配置了重写规则,那么该链接现在应该可以工作了。

于 2013-04-08T11:37:19.297 回答