Hello,
i'm new to cakePHP and struggling with the MVC pattern in my views.
According to the cakePHP book there are e.g. Helpers in the views to easily
format the data.
My problem is, that my views get more and more complex like winding pathes.
In practical use combining data is necessary very often in views, for
example "Amount: € 100,00 from 01.01.2015 to 31.12.2015" (the currency and
the dates are variables). For the formatting i use the NumberHelper and the
TimeHelper, but because i'm inside the view i also have to check if the
variables are empty or even set to prevent undefined index errors during
development and later results like "Amount: € from to". So i add a lot of
if-branches to suppress the rendering of the static elements in the view in
case of empty variables. Due to tree structures and array indexes in the
variables the names are often longer than short and makes the view code
difficult to read. This problem becomes even more critical due to
higher-level branches:
<table>
<tr>
<?php if () { // Begin If-Block ?>
<td>
<?php //... ?>
</td>
<?php } else { // Begin Else-Block ?>
<td>
<?php //... ?>
</td>
<?php } // End If-Else-Block ?>
</tr>
</table>
Of course the tables are much more bigger and complex with many rows and
columns in real life and in combination with all the other branches the
view gets more and more hard to read and maintain.
So i thought about parsing the string in the controller and then just
render this complete string in the view, but the Helpers seems to be
located in the views, so i'm not sure how to do it and if this would be a
good idea. But apart from this there is still the problem with the
higher-level branches...i thought about rendering different views in the
controller, but then i end up with a lot of duplicate code which is also
difficult to maintain.
I hope that someone with enough experience can tell me if there is a way to
keep complex views at a more manageable level.
Greetings
Karl Klammer
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.