In the templates I want to use for example the label ‘Water’ for the fieldname ‘H20’.
Don’t know why, but it was hard find in the book or by google. Aliases, rename, label, etc. mostly give answers about forms. It’s a bit mysterious why such a common feature is so hard to find (I know, by me, wrong search word etc, but nevertheless). Maybe a subheading in the book could help google?
Finally found it by a link on stackoverflow discussing a completely other topic, query builder, selecting data.
// Results in SELECT id AS pk, title AS aliased_title, body ... $query = $articles->find(); $query->select(['pk' => 'id', 'aliased_title' => 'title', 'body']);
Pasted and changed the table and fields in my controller: find on null gives problem.
Guess these lines are needed somewhere?
use Cake\ORM\Locator\LocatorAwareTrait; $query = $this->getTableLocator()->get('Articles')->find();
Tried some, but no success. I ended with a working
$individuals = $this->paginate($this->Individuals->find()->select(['id','name','water'=>'data_1']));
Just keep wondering why the book is at places so hard to understand by noobs. It’s like it’s written for people who have a deep understanding of cakephp, but that group of people isn’t the audience.
One thing I guess is the start, using the console, clean sheet after fresh install or baked files. At this point the book presumes console/clean sheet, while I’m working with baked code?
Ok, that’s my frustration, if there are more people having this idea, I’m willing to help to build a book where the baking is the core, and with three levels of knowledge. I come across a lot of features I know I will never use, or even just don’t know when I should use them. Such simple things and much used as aliases are hard to find and implement (by me).
The question I can’t find an awnser: When working sloppy (that’s me), I will forget to change copied templates for 100%. In the end a template can use a field which isn’t selected anymore. The value gets ‘0’, that’s misleading.
A blank would be better, an error the best (like in other cases when a field/data is not available to the view/template).
How to get that done?