Many years ago I had the same question: "where should I put my own code in Joomla?". It was very frustrating at that time for me too and Joomla has a long learning curve, comparing to WordPress for example. Many of us easily can forget how confusing Joomla can be if someone wants to customize it or understand it. No wonder why WordPress is used like on 5-600 million websites and Joomla is like on 3 million. That is an extremely big difference and I think the simple reason for this is told in this question even if the answer of this question could be only 1 line:
Use and override the display()
method.
It is only my own opinion - Joomla is a good example of trying to make something clean and simple but at the end it gets way too complex to understand (Joomla4 for example took about 7 years to develop of course no-one can understand it in one week or two). I see thousands of packages in Javascript field (NextJS, Node js ie.) doing similarly in a smaller manner nowadays. With a good intention they try to provide "a solution" in a package or more, then not enough documentation, too complex logic, only few people have time to understand it, then it gets abandoned and wrecks applications. It is different of course, but the point is the frustration level you can find in full stack development when you just want to display "hello world" and it takes a week setup (and docker, and kubernetes, and npm, node js, and so on...)
Instead of writing any explanation here I would just link the Joomla documentation which describes how Joomla handles requests and how and why the Controller is responsible for deciding whether it loads the View (and which view) or redirect:
https://docs.joomla.org/Model-View-Controller
UPDATE:
Since it was not part of the original question I actually just avoided this but in Joomla 3 (similar in Joomla 4 ), in your component, you can extend BaseController
, FormController
or AdminController
, or if you do not want to use the namespaced Controllers, then just extend JControllerAdmin
for example (at list views), so you do not extend just Controller
. So, that is wrong in your Controller code.
So, I suggest you to use either (this one was used in Joomla3) :
class MycomponentnameControllerProfiles extends JControllerAdmin {...}
or with namespaced (used now in Joomla4 can be used in Joomla 3 too):
// on the top of the file we include:
use Joomla\CMS\MVC\Controller\AdminController;
...
// and then the class (in Joomla4)
class ProfilesController extends AdminController {...}
// in Joomla 3
class MycomponentnameControllerProfiles extends AdminController {...}