Error on `switch` syntax
williamn opened this issue · comments
A switch
block like below
- switch ($this->params['action']):
- case 'edit'
= $this->Html->tag('label', 'Username')
= $this->Html->tag('p', $this->data['User']['username'])
- break
- case 'add'
= $this->Form->input('username')
= $this->Form->input('password')
- break
- endswitch
is being rendered to
<?php switch ($this->params['action']): { ?>
<?php case 'edit' { ?>
<?php echo $this->Html->tag('label', 'Username'); ?>
<?php echo $this->Html->tag('p', $this->data['User']['username']); ?>
<?php break; ?>
<?php } ?>
<?php case 'add' { ?>
<?php echo $this->Form->input('username'); ?>
<?php echo $this->Form->input('password'); ?>
<?php break; ?>
<?php } ?>
<?php } ?>
<?php endswitch; ?>
which is produce a fatal error.
If switch
syntax is not supported yet, I would like to patch a fix for that. Please give me some clue on where should I start.
Does the following syntax work ?
(removed :
after switch, added :
after case, removed endswitch
)
- switch ($this->params['action'])
- case 'edit':
= $this->Html->tag('label', 'Username')
= $this->Html->tag('p', $this->data['User']['username'])
- break
The PHP renderer basically adds a {
before an indented block, and a }
after an indented block.
No it does not works.
Here is the parsed PHP
<?php switch ($this->params['action']) { ?>
<?php case 'edit': { ?>
<?php echo $this->Html->tag('label', 'Username'); ?>
<?php echo $this->Html->tag('p', $this->data['User']['username']); ?>
<?php break; ?>
<?php } ?>
<?php case 'add': { ?>
<?php echo $this->Form->input('username'); ?>
<?php echo $this->Form->input('password'); ?>
<?php break; ?>
<?php } ?>
<?php } ?>
it seems the problem is on the case
syntax?
FYI,
- switch ($this->params['action'])
- case 'edit':
= $this->Html->tag('label', 'Username')
= $this->Html->tag('p', $this->data['User']['username'])
- break
- case 'add':
= $this->Form->input('username')
= $this->Form->input('password')
- break
- endswitch
is rendered to
<?php switch ($this->params['action']) { ?>
<?php case 'edit': { ?>
<?php echo $this->Html->tag('label', 'Username'); ?>
<?php echo $this->Html->tag('p', $this->data['User']['username']); ?>
<?php break; ?>
<?php } ?>
<?php case 'add': { ?>
<?php echo $this->Form->input('username'); ?>
<?php echo $this->Form->input('password'); ?>
<?php break; ?>
<?php } ?>
<?php } ?>
<?php endswitch; ?>
Apparently PHP doesn't like the ?> <?php
before case
(the syntax in your comment at #41 (comment) is otherwise valid)
So what is the solution, I'm using PHP 5.4.16 by the way.
Ok, I got it to work but it doesn't look anywhere good.. So, this is an example of a switch-case code that works:
-switch($model) { |
case 'user': |
echo $this->Html->addCrumb('Media', '/users/media'); |
break; |
} |
I hope it helps someone else out there.
Closing as I do not see a way to properly support switch statements.