#1
Hello fellow Trongate users,
I am trying to define a few icons that I use throughout my app as constants in this manner:

However, I have tried putting the above code in various files with no luck eg:
engine/Trongate
engine/Model
Is there a specific location/file that would make these constants available to all of my views?

Cheers!
#2
Hello KeepCalm. I think you could implement this in your css.
This would make it available to view files.
Check this out

https://www.angularjswiki.com/amp/fontawesome/csscontentcode/
#3
Hi djnordeen,
thanks for the response, I like the idea, but I have no idea how to go about this via css.

EDIT: Just read through the link you provided, this seems overly complicated for what I want to achieve

I eventually just used the config.php file and I defined them in there.

I will mark your response as correct as someone else may find it useful.

Cheers!
#4
Hi guys,

Interesting use of it in CSS Dan, will note for future projects.

Another way is to define constants or add methods you use regularly from project to project is to create a utility module that has all your handy work you find repeating or rewriting in one place. You could also intercept some methods from the engine or helper folders, replacing them with your own too, as mentioned in a post on the SCA forum by codefire (Jason) https://ums.myds.me/phpbb/viewtopic.php?f=5&t=87&p=2190&hilit=require+once#p2190
Here is his site https://www.codefire.co.uk/ (of course written using Trongate) too - we have so many talented users in our community :)

Here is my take:
Create a module, lets call it 'my_utility' (easy to do with the VS Code extension) or just make them manually:
Folder structure


This is an example My_utility.php controller with your icon defines and a few example methods > a constructor, that when the module is loaded, gets executed and a simple add method:


Now the trick is to load this up when the framework does, so place this line inside of public/index.php

I find adding it right after the bootstrap has loaded works fine, or you could just write some code without a class and load it before the bootstrap, but doing it this way keeps you inline with modules calling modules and the like.

public/index.php


Now when your app is loaded:
- The defines are available anywhere
- You can load the my_utility module and any code in the constructor will run
- add any utility method you want

example load the module and call the my_add(); method


Happy coding :)
#5
Hi DaFa,
thanks for the response,
I will definitely use your approach in the future as some of my view files are creeping past the 1,000 lines of code mark.
I don't know what it is about Trongate, but I have never felt so much joy while coding.
Granted I am neither a great coder nor do I know php all that well, but Trongate is so much fun, I can't help but push myself to see what I can do with it.
My task management project is coming along fine, with only formatting of the view files, setting up user permissions, a reports generator and a dashboard for some KPI eye candy left to implement.
I even have csv files generated from my tables for instant download into MS Excel and a very advanced search utility for more targeted search than Trongate's code generator's default.
I am loving every moment I code in Trongate, even when I am challenged, the documentation is good and the Help Bar is even better!

Cheers!
#6
KeepCalm. Simon's way should get the star. Much better approach in that it makes it portable from project to project
#7
Hi djnordeen,
I agree, but I had given the star to you before DaFa's post, I don't know if I can change it now.
Will try.
Edit: Star re-assigned.
Still like your idea as well though.
Cheers!