Hachther Blog > Open Source  > How to develop a Mautic plugin: MVC – Routes

How to develop a Mautic plugin: MVC – Routes

Welcome to the lesson II of the series Develop a Mautic plugin. If you have not read the previous article I highly recommended you to do it (you can find it here).

Mautic is based on Symfony which is a MVC PHP framework. So, develop a module in Mautic means that you will work follow the MVC paradigm but with Mautic rules. So in the article we will give a brief description of MVC then the first big step for module development: configuration of routes and menus.

MVC stand for Model View Controller which is a software architecture pattern. MVC define three components:

  • Model: responsible for the interaction with your data.
  • View: responsible for the presentation to the user.
  • Controller: responsible for bind data from the model and display the view.

And to give access to the user you need to define routes so ca have access to resources.

And to give access to the user you need to define routes.

In the next, we will configure routes (MVC paradigm) and menus (Mautic specification) to display routes to the user. And before we continue, we need to define one of the most important things: the key name of the module, which will be used in all our configurations.

Configurations

All configurations are done Config/config.php: routes, menus, service, categories, … We will only focus on the configurations for basic MVC module and to do that, we only need to add route and menu configurations. As define the previous article, our module name is HelloWord and the key name is helloword. Let us configure the routes for different actions and the menu to give access to our module to a user.

Routes

Mautic have three types of routes:

  • main: users need to be authenticated to have access to those routes. (/s/ will be automatically appended)
  • public: those routes will be accessible for everyone authenticated or not
  • api: accessible only through API secure requests (/api/ will be automatically appended)

For a route you need to define some required parameters and some other optionals, depending on your needs.

  • path (required): is the path used in the browser (since Mautic is base on Symfony this path definition follows the same rules as Symfony).
  • controller (required): Is the action to call when this route is triggered. We will see how to define a controller in the next article.
  • method (optional): is the HTTP method (GET, POST, …) which need to be used to trigger this route.

There are other parameters which can be defined in the route, you can find a full documentation here.

Each of your routes must have a unique name, name which will be used to refer to this route in the other configurations or in your source code.

In this article, we will only focus on the main route.

Menu

Mautic have 4 types of menus:

  • main: Main menu on the left.
  • admin: Admin menu accessible through the cogwheel in upper right-hand side of Mautic.
  • profile: Profile menu accessible through clicking the username in upper right-hand side of Mautic.
  • extra: Displays to the right of the Mautic logo in the upper left hand. Only shows if there are menu items injected.

Same like routes, menu has some parameters that you can set.

  • route (optional): The name of the route to link to this menu.
  • parent (optional): Display this item under another parent menu item.

There are other parameters which can be defined in the menu, you can find a full documentation here.

In this article, we will only focus on the main menu.

Config file

This is what your file will look like.

 'HelloWord',
	'description' => 'Hello Word module',
	'version' => '1.0',
	'author' => 'Hachther Co.',

	'routes' => [
		'main' => [
			'mautic_helloword_index' => [
				'path' => '/helloword/{page}',
				'controller' => 'MauticHelloWordBundle:HelloWord:index',
				'method' => 'GET'
			],
			'mautic_helloword_action' => [
				'path' => '/helloword/{objectAction}/{objectId}',
				'controller' => 'MauticHelloWordBundle:HelloWord:execute',
			],
		]
	],
	'menu' => [
		'main' => [
			'mautic.helloword' => [
				'route'    => 'mautic_helloword_index',
				'parent'   => 'mautic.core.channels',
			]
		]
	],
];

As you can see, make a configuration file is just a matter of return a php array with a specific structure. We have routes ( with main routes within) and menu (with main menu within) and for each element you define a unique name and your configuration within.

This is the end of this article. Hope this was helpful and see you in the next article.

Previous article

Comments:
  • Norman Carrie
    April 28, 2018 at 3:24 pm

    So how would you create an operation that you wanted to kick off with the console?

  • Esmeralda
    May 27, 2020 at 12:45 am

    Fantastic goods from you, man. I’ve understand your stuff previous to and you are just extremely excellent.
    I actually like what you have acquired here, really like what you are stating and the
    way in which you say it. You make it entertaining and you still
    care for to keep it sensible. I cant wait to read much more from you.
    This is really a tremendous web site.

  • Marcella
    May 30, 2020 at 11:07 pm

    Hey There. I found your weblog the use of msn. This is a really neatly
    written article. I’ll make sure to bookmark it
    and come back to learn extra of your helpful information. Thanks for the post.
    I will certainly return.

  • Kathryn
    May 31, 2020 at 6:20 am

    I was able to find good advice from your content.

  • Dewey
    June 1, 2020 at 8:12 am

    I’m curious to find out what blog system you are using? I’m having
    some small security problems with my latest website and I would like to find something more safe.
    Do you have any recommendations?

  • Kassandra
    June 1, 2020 at 4:21 pm

    We are a group of volunteers and starting a new scheme in our
    community. Your website offered us with valuable info to work
    on. You’ve done an impressive job and our entire community will be thankful to you.

  • Christen
    June 4, 2020 at 2:49 am

    Wow, fantastic weblog layout! How long have you ever been blogging for?
    you made blogging look easy. The total glance of your site
    is magnificent, as smartly as the content material!

  • ปั้มไลค์
    June 12, 2020 at 10:20 pm

    Like!! I blog frequently and I really thank you for your content. The article has truly peaked my interest.

  • Charli
    June 13, 2020 at 3:08 am

    Hi just wanted to give you a quick heads up and let
    you know a few of the pictures aren’t loading properly.

    I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the
    same outcome.

  • Steffen
    June 29, 2020 at 6:22 am

    you’re in point of fact a excellent webmaster.

    The web site loading pace is amazing. It seems that you’re doing any
    distinctive trick. Furthermore, The contents are masterwork.

    you have done a magnificent process on this topic!

  • Larue
    January 21, 2021 at 2:52 am

    An impressive share! I have just forwarded this onto a colleague who had been conducting
    a little research on this. And he actually bought me lunch because I discovered it for him…
    lol. So let me reword this…. Thanks for the meal!! But yeah,
    thanks for spending the time to talk about this issue
    here on your internet site.

  • Crystle
    January 21, 2021 at 12:05 pm

    I think that is among the most significant information for me.

    And i am happy reading your article. However want to commentary on few common issues, The web site style is wonderful,
    the articles is really excellent : D. Excellent process, cheers

  • Rusty
    January 21, 2021 at 3:31 pm

    It’s actually a great and useful piece of info. I’m happy that you simply shared this helpful info with us.
    Please stay us informed like this. Thanks for sharing.

  • Johnie
    February 23, 2021 at 12:47 am

    Very soon this site will be famous amid all blog users, due to it’s fastidious posts

  • Jacques
    March 17, 2021 at 3:20 pm

    What’s Happening i’m unfamiliar with this, I found this We have found It
    positively useful and features aided me out loads. I’m hoping to provide a contribution &
    assist other users like its helped me. Great job.

    Here is my webpage – RenatoCPanek

  • Rick
    April 20, 2021 at 5:52 pm

    This is my first time go to see at here and i am genuinely pleassant
    to read everthing at alone place.

  • Bonny
    April 22, 2021 at 3:31 pm

    I visited many web pages however the audio feature for audio songs
    current at this web site is really fabulous.

  • Ernestina
    March 8, 2023 at 7:30 am

    Oh my goodness! Awesome article dude! Thank you, However I am having issues with your RSS.
    I don’t know why I can’t join it. Is there anyone else getting the same RSS issues?
    Anybody who knows the solution can you kindly respond? Thanks!!

  • Melissa
    March 9, 2023 at 1:56 pm

    Hi, constantly i used to check website posts here in the early hours in the morning,
    because i enjoy to gain knowledge of more and more.

  • Lona
    March 9, 2023 at 3:22 pm

    Wonderful work! This is the kind of info that should be shared across the web.
    Shame on Google for now not positioning this publish
    higher! Come on over and consult with my web site
    . Thank you =)

  • Ebony
    March 9, 2023 at 4:01 pm

    What’s up colleagues, nice post and pleasant urging commented here, I am actually enjoying by these.

  • Lorenza
    March 9, 2023 at 10:21 pm

    If some one wants expert view about blogging afterward i propose him/her to pay a quick visit this blog, Keep
    up the nice work.

  • Princess
    March 10, 2023 at 8:03 am

    Wow, wonderful blog layout! How long have you been blogging
    for? you made blogging look easy. The overall look of your site is excellent, as
    well as the content!

  • Geoffrey
    March 10, 2023 at 11:37 pm

    This piece of writing is really a nice one it helps new internet people, who are
    wishing in favor of blogging.

  • Jonathan
    March 11, 2023 at 1:37 am

    Very good article! We are linking to this great post on our site.
    Keep up the good writing.

  • Charli
    March 11, 2023 at 9:38 am

    Hi there to all, as I am actually eager of reading this weblog’s
    post to be updated on a regular basis. It consists of good stuff.

  • Agnes
    March 11, 2023 at 6:06 pm

    Normally I do not learn post on blogs, however I would
    like to say that this write-up very pressured me to check out
    and do it! Your writing style has been surprised me.

    Thank you, very great article.

  • Anton
    March 12, 2023 at 1:53 am

    I’m gone to say to my little brother, that he should also go to see this webpage
    on regular basis to take updated from most recent reports.

  • Saundra
    March 12, 2023 at 2:25 am

    This is really interesting, You’re a very skilled blogger.
    I’ve joined your feed and look forward to seeking more of
    your great post. Also, I have shared your web site in my social
    networks!

  • Curtis
    March 12, 2023 at 3:37 am

    Terrific article! That is the kind of information that are
    meant to be shared across the web. Shame on Google for not positioning this post higher!
    Come on over and seek advice from my website . Thanks =)

  • Esperanza
    March 12, 2023 at 8:00 am

    Right now it looks like WordPress is the top blogging platform available right now.
    (from what I’ve read) Is that what you’re using on your
    blog?

  • Dirk
    March 12, 2023 at 6:15 pm

    Hello there, just became alert to your blog through Google, and found that it is really
    informative. I’m gonna watch out for brussels. I’ll be
    grateful if you continue this in future. A lot of people
    will be benefited from your writing. Cheers!

  • Lorraine
    March 12, 2023 at 9:17 pm

    Thanks for the good writeup. It if truth be told
    was once a entertainment account it. Glance advanced to more delivered agreeable
    from you! By the way, how can we be in contact?

  • Mackenzie
    March 13, 2023 at 4:23 am

    When I initially commented I clicked the “Notify me when new comments are added” checkbox and now
    each time a comment is added I get three e-mails with the same comment.
    Is there any way you can remove me from that service? Bless you!

  • Georgiana
    March 13, 2023 at 4:36 am

    When I originally commented I clicked the “Notify me when new comments are added” checkbox
    and now each time a comment is added I get several emails with the same
    comment. Is there any way you can remove me from that service?
    Appreciate it!

  • Mabel
    March 13, 2023 at 11:26 am

    Great delivery. Solid arguments. Keep up the good effort.

  • Lakeisha
    March 13, 2023 at 8:34 pm

    Hi this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML.

    I’m starting a blog soon but have no coding know-how so I wanted to get guidance
    from someone with experience. Any help would be enormously appreciated!

  • Sonia
    March 14, 2023 at 8:27 am

    I visited multiple web pages however the audio feature for audio songs present at this web page is
    truly marvelous.

  • Israel
    March 14, 2023 at 12:58 pm

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter
    updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience
    with something like this. Please let me know if you run into anything.
    I truly enjoy reading your blog and I look forward to
    your new updates.

  • Vivien
    March 14, 2023 at 11:31 pm

    Very good article. I definitely love this website. Stick with it!

  • Buster
    March 15, 2023 at 12:00 am

    I visited many web pages but the audio feature for audio songs current at
    this web page is in fact superb.

  • Hazel
    March 15, 2023 at 4:43 am

    This post offers clear idea designed for the new people of blogging,
    that in fact how to do blogging and site-building.

  • Jillian
    March 16, 2023 at 2:20 pm

    Everyone loves what you guys are usually up too. Such clever work and reporting!
    Keep up the superb works guys I’ve included you
    guys to my blogroll.

  • Earnestine
    March 16, 2023 at 6:06 pm

    My spouse and I stumbled over here different website and thought I might
    as well check things out. I like what I see so now i’m following
    you. Look forward to going over your web page
    yet again.

  • Phillipp
    March 17, 2023 at 12:45 am

    Link exchange is nothing else except it is just placing the other
    person’s weblog link on your page at appropriate place and other
    person will also do same for you.

  • Eugenio
    March 17, 2023 at 5:46 pm

    Hey There. I discovered your blog the usage of msn. This is a very smartly written article.
    I will be sure to bookmark it and come back to read more of your helpful information.
    Thanks for the post. I will definitely comeback.

  • Jed
    March 18, 2023 at 1:37 am

    Awesome post.

Leave a reply