我有一个CakePHP应用程序,其中所有视图都有效,但有两个。 这是控制器:
<?php
App::uses('AppController', 'Controller');
class CardsController extends AppController {
public function index() {
}
}
?>
这是视图
<h2>Title</h2>
<?php
echo $this->Form->create('Card', array(
'url' => array(
'controller' => 'cards',
'action' => 'view'
)
));
echo $this->Form->input('codice');
echo $this->Form->end('Cerca');*/
?>
使用firefox控制台检查我得到了这个:
<html>
<head></head>
<body></body>
</html>
&#34;视图&#34;视图,由表单调用具有相同的问题。 通常如果视图丢失,Cake会返回错误,在这种情况下,如果我删除了index.ctp,结果无论如何都是空白页面。 我无法找到问题所在。
更新1
我的路线代码:
<?php
Router::connect('/', array('controller' => 'users', 'action' => 'login'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
?>
**更新2 ** 我的文件夹结构
├── Config
│ └── Schema
├── Console
│ ├── Command
│ └── Templates
├── Controller
│ ├── ()
│ ├── Component
│ ├── docs
│ └── output
├── files
├── Lib
├── Locale
│ └── eng
├── Model
│ ├── ()
│ ├── Behavior
│ └── Datasource
├── Plugin
│ ├── AclExtras
│ ├── CakePdf
│ └── DebugKit
├── Test
│ ├── Case
│ └── Fixture
├── tmp
│ ├── cache
│ └── logs
├── Vendor
│ └── tcpdf
├── View
│ ├── ()
│ ├── Cards
│ ├── Clientis
│ ├── Elements
│ ├── Emails
│ ├── Errors
│ ├── Fornitoris
│ ├── Groups
│ ├── Helper
│ ├── Indirizzos
│ ├── Layouts
│ ├── Magsits
│ ├── Movimentis
│ ├── Pagamentos
│ ├── Pages
│ ├── Pdcard
│ ├── Pdf
│ ├── Posts
│ ├── Rdocumentos
│ ├── Rlistinos
│ ├── Scaffolds
│ ├── Storicotransaziones
│ ├── Tdocumentos
│ ├── Titoliviaggios
│ ├── Tmovimentis
│ ├── Users
│ ├── Verificas
│ ├── Voucher
│ └── Widgets
└── webroot
├── css
├── files
├── images
├── img
└── js
更新3
卡片型号
<?php
App::uses('AppModel', 'Model', 'AuthComponent', 'Controller/Component');
class Card extends AppModel {
public $belongsTo = array('Packet' => array('foreignKey' => 'pacchetto'), 'Tdocumento' => array('foreignKey' => 'iddocument'));
public $hasMany = array('Visit' => array('foreignKey' => 'codicecarta'));
public $primaryKey = 'codicecarta';
public function afterFind($results, $primary = true) {
for ($i=0; $i < sizeof($results); $i++) {
if($results[$i]['Card']['minore'] == 1){
$results[$i]['Card']['minore'] = 'Yes';
}else{
$results[$i]['Card']['minore'] = 'No';
}
if($results[$i]['Card']['gratuito'] == 1){
$results[$i]['Card']['gratuito'] = 'Yes';
}else{
$results[$i]['Card']['gratuito'] = 'No';
}
$datavalidita = $this->formatodata($results[$i]['Card']['iniziovalidita']);
$datavisita = $this->formatodata($results[$i]['Card']['dataprenotazione']);
$results[$i]['Card']['datainizio'] = $datavalidita[0];
$results[$i]['Card']['orainizio'] = $datavalidita[1];
$results[$i]['Card']['datavisita'] = $datavisita[0];
$results[$i]['Card']['oravisita'] = $datavisita[1];
}
return $results;
}
public $validate = array(
'nominativo' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'A username is required'
)
),
'codicecarta'=> array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Inserire il codice'
)
)
);
private function formatodata($dataora){
$dataora = explode(' ', $dataora);
$data = $dataora[0];
$data = date('d-m-y', strtotime($data));
$ora = $dataora[1];
$ora = substr($ora, 0,5);
return array($data, $ora);
}
}
更新4
我的视图/布局/ default.ctp
<html>
<head>
<?php echo $this->Html->charset(); ?>
<title>
<?php echo $cakeDescription ?>:
<?php echo $title_for_layout; ?>
</title>
<?php
echo $this->Html->meta('icon');
echo $this->Html->css('cake.generic');
echo $this->fetch('meta');
echo $this->fetch('css');
echo $this->fetch('script');?>
</head>
<body>
<div id="container">
<div id="header">
<h1><?php echo $this->Html->link($cakeDescription, 'http://cakephp.org'); ?></h1>
</div>
<div id="content">
<?php echo $this->Session->flash(); ?>
<?php echo $this->fetch('content'); ?>
<?php echo $this->element('sql_dump'); ?>
</div>
<div id="footer">
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
在View文件夹中创建Cards
文件夹,然后在其中添加index.ctp。您可能缺少文件夹结构,这是cakephp中的惯例。
从代码中删除*/
。
我建议您创建header.ctp,footer.ctp
等元素并使用default.ctp进行正常使用,包括页眉,页脚和视图内容。
<html>
<?php echo $this->element('head'); ?>
<body>
<?php echo $this->Session->flash(); ?>
<?php echo $this->fetch('content'); ?>
<?php echo $this->element('sql_dump');
echo $this->Html->script('additional-methods');
?>
<div class="footerVersion" style="float: left;
width: 100%;text-align: center;">
Version : <?php echo VERSION_NUMBER;?>
</div>
</body>
</html>
确保你有这样的routs.php。
<?php
//Goto login page if base url is called.
Router::connect('/', array('controller' => 'Users', 'action' => 'login'));
/**
* ...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';
理想模型应如下所示:
<?php
App::uses('AppModel', 'Model');
class Card extends AppModel {
}
?>
答案 1 :(得分:1)
错误是偷偷摸摸的,在控制器中,在php标记之前有一个空行。那条线打破了控制器调度员的流量。