Create a Custom Joomla 2.5 Module
Lesson 2 of 3 · Create a Custom Joomla 2.5 Module – Part 2 · IT & Software
Create a Custom Joomla 2.5 Module – Part 2
okay guys welcome to part two of building a custom jeweler module and we left off on the the entry point file which is mod featured articles dot PHP
and that's all set we have everything we need there so the next thing I want to do is build up the helper dot PHP file so I'm gonna paste in the code so we have our standard comments and version
info and we have this function now or method whatever you want to call it of mod underscore featured articles helper okay so what this does is it's going to get get the actual articles for us it's
going to deal with the database and bring this back to the controller and then we can display in the view how we want so and if we go back to mod featured articles PHP you can see this
rows variable is being assigned to the featured helper featured articles helper get Rose method and that is this right here so it's the featured articles helper get Rose method it's all being
assigned to that Rose variable now what this does is the first thing it does is it gets it creates a database instance or a database object with this standard J factory get dbo method so that gives
us a database instance to work with now this next section is the query what this this is just building up the query this isn't this isn't submitting it yet or or running it we're just putting it into
this variable and what it's doing is selecting all this this asterisk means all it's getting everything from the content table now this this hash tag and then these two underscores this
represents the the prefix of your table so if we could go and we can look at the table of our Joomla site I have the prefix as Jos but your Joomla site might have something different so this here
just replaces that's what that is so we're selecting all from content which I can actually show you is right here okay this is the Joss content tate table so it's
selecting all which means ID at asset ID title alias everything okay and we're doing it we're featured is a one so if we go here we'll see we should have a featured um
column which is right here so if you make an article featured in Joomla this turns into a one like right here this article if we can scroll over it is the article called beginners so that is
actually a featured article so that's that's one of the Articles that were grabbing and then the limit we're setting to whatever we put for our art count parameter which we can see is
right here we have five so really it's saying limit to five and you can't you'll be able to change that within module manager the next thing it's doing is actually running it so we have the DB
instance and then we're calling the set query method onto our actual query and then we're loading it as an object right here into the variable rows okay so this is how you would load your query into an
object load object list and here this lets us get the article links so we're actually assigning the links to role link and we do this this Ju RI root just means to get it from the root of the
site of the Joomla site and then we're using the content helper route to get the actual the links because I don't know if you you've seen the Joomla links but it's like index dot PHP option
equals whatever component and then ID equals whatever the idea is and that's what it's getting for us here so now we're returning everything that's in the Rose variable okay
and then we're actually putting that into this Rose variable alright so now what we want to do is deal with the view file so that is that is in the TMP el folder and the default dot PHP so I'm
going to copy and paste the code from here so again we have this J exact line so people can't just access this file directly and the next we have a div with a class this class is class is going to
be the module class suffix that we define in the module manager so that can be whatever we want and we can separate this module different than other modules and then we have a for
each statement and a for each what it does is it loops through an array and allows us to work with each each instance of that array which in this case will be a featured article and
we're using this Rose variable once again if we go to our entry point the Rose is grabbing all the rows from the helper which is grabbing it from the database so it's basically saying for
each featured article we're going to do this we're going to have a div and it's we just have some styling here just for physical presentation we don't need this but it's just to make it look nice we're
putting the the title because we can now use dynamic fields we can use row to row whatever we want so if we go here we could use row ID we could use row title like we are we could get the intro text
we could basically get anything from the articles we need using that row variable so we're gonna have the title and it's going to be in this h4 tag now the title is going to be
a link so you see this a tag and we're styling it and then the href is pointing to this row link which is going to give us that the article on that instance is it's going to give us the link and you
saw that in the help file so next we're going to say we have a conditional saying if show text is equal to 1 then that means they want to show the intro text so they're going to do that here
else if they don't want to show the intro text wait I'm sorry well we don't have an else for that so if show text equals one it'll show the intro text if it doesn't then it won't
show it now here is where we echo out the intro text we're going to also put it undo another conditional here called if word limit is not equal to zero so that means if they put a limit on the
text on the intro text then it's going to do this say they put 50 450 words then it's going to call this function limit words it's going to call that on the intro text and the word limit will
be the parameter so it'll show what however many words is in this word limit now this is a good time to bring up this functions file because this is where I want to put this this limit words
function here this is this has nothing to do with Joomla it's just a function that I created so we can limit the the words so when the functions file we're just going to have this function called
limit words and what it does is it just basically if you know PHP then you can see what it does but what it does basically is just limits an amount of text to a certain number of words
all right so save that so if the word limit was if the person wants a word limit then it's going to do this if they don't if they leave it at zero and it's just going to show everything so it's
just going to echo the intro text right out and here we have if the read more is equal to one if they want to shoot if they want to show the read more then we have this link to this read more text
and you can see it's the roll link just like in the title we use the same thing this roll link and then that's it and we should be good to go I'm gonna save this so we should
be able to actually package this up so we want to just grab everything there and put it into a zip file so we have this mod featured articles zip okay so I'm gonna actually put that on my
desktop and we're gonna go to Joomla to our admin area log in and get the extension install and we're gonna grab that file on the desktop the mod mod featured articles and upload and you can
see it's was installed successfully the description is here so we should be able to go to module manager and our featured articles module is here and you can see it has all the parameters and the
defaults I'm gonna choose to put this in the position seven which is the left hand position I'm gonna publish it and put it on all pages and we'll just leave this as the margin class suffix we'll
just leave this five articles show intro text 25 25 words and show read more so if I save this and then we visit the front-end and reload and here it is it's showing us five featured articles and if
you click on the lip on the axis forbidden all right so that's something we have to troubleshoot real quick but you know what we are running out of time so I'm
going to stop it here and I guess we will have a third part
Part 2 – An intermediate tutorial on creating a custom Joomla 2.5 module which will list all of the featured articles on a Joomla website