Reputation: 571
I have a CakePHP application where all the view works, but two. This is the controller:
<?php
App::uses('AppController', 'Controller');
class CardsController extends AppController {
public function index() {
}
}
?>
And this is the view
<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');*/
?>
Checking with the firefox console I got this:
<html>
<head></head>
<body></body>
</html>
The "view" view, called by the form has the same problem. Normally if the view is missing Cake return an error, in this case if I delete the index.ctp the result is in any case a blank page. I can't find what the problem is.
UPDATE 1
My route code:
<?php
Router::connect('/', array('controller' => 'users', 'action' => 'login'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
?>
**UPDATE 2 **
My folder structure
├── 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
UPDATE 3
Card model
<?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);
}
}
UPDATE 4
My View/Layout/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>
Upvotes: 2
Views: 2248
Reputation: 571
The error was sneaky, in the controller, before the php tag there was an empty line. That line broke the flow of the dispatcher of the controller.
Upvotes: 1
Reputation: 11693
Create Cards
folder in your View folder and add there index.ctp. You may be missing Folder structure which is convention in cakephp.
Remove */
from your code.
I recommand you to create elements like header.ctp, footer.ctp
And use default.ctp for normal usage like this which will include your header , footer and view content.
<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>
Make sure you have routs.php like this.
<?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';
An ideal model should look like this :
<?php
App::uses('AppModel', 'Model');
class Card extends AppModel {
}
?>
Upvotes: 1