A few beginner question from the new module dev tutorial
A few beginner question from the new module dev tutorial
Since I've spent a lot of time learning PHP the past year, I want to become an active developer for CMSMS. I'm reading the new module development tutorial (thanks for this), and thought I'd ask some questions as I'm reading it to be able to learn the app's secrets.
My first one:
If I understand correctly, all files prefixed as 'action' (so action.do_something.php) are the handler files. They handle any data manipulation and database interaction. After this, you display a Smarty template file with the results. Now for my question, is it mandatory to name the Smaty template files the same as the accompanying action/handler file? So in the example, there's a handler file called action.edit_holiday.php. Is it mandatory to name the smarty template file 'edit_holidat.tpl'? Or is this just a good idea to keep thing organised?
My first one:
If I understand correctly, all files prefixed as 'action' (so action.do_something.php) are the handler files. They handle any data manipulation and database interaction. After this, you display a Smarty template file with the results. Now for my question, is it mandatory to name the Smaty template files the same as the accompanying action/handler file? So in the example, there's a handler file called action.edit_holiday.php. Is it mandatory to name the smarty template file 'edit_holidat.tpl'? Or is this just a good idea to keep thing organised?
Re: A few beginner question from the new module dev tutorial
My second question:
I see there is a method called: 'Insert_ID()', which is a method of the database object. I looked at the api documentation, but couldn't find a database class. I'd like to know what this method does, and why it's called separately from the insertion from the rest of the record.
EDIT
I read there is a 'CmsDbQueryBase' class, but I can't find that on this page: http://www.cmsmadesimple.org/APIDOC2_0/ ... s/CMS.html
I see there is a method called: 'Insert_ID()', which is a method of the database object. I looked at the api documentation, but couldn't find a database class. I'd like to know what this method does, and why it's called separately from the insertion from the rest of the record.
EDIT
I read there is a 'CmsDbQueryBase' class, but I can't find that on this page: http://www.cmsmadesimple.org/APIDOC2_0/ ... s/CMS.html
Re: A few beginner question from the new module dev tutorial
My third question:
I see this method used, which is a method if the 'LayoutTemplateQuery' class. It doesn't accept any arguments, am I correct to assume that this method knows from which module it's being called, so that it returns the records for this module automatically?
Code: Select all
$holidays = $query->GetMatches();
Re: A few beginner question from the new module dev tutorial
Shouldn't the following line on page 23:
be:
?
EDIT
No, that's optional, didn't know that but I just looked it up on PHP.net
Code: Select all
$obj = new HolidayItem;
Code: Select all
$obj = new HolidayItem();
EDIT
No, that's optional, didn't know that but I just looked it up on PHP.net
Last edited by Guido on Wed Jan 06, 2016 12:42 pm, edited 1 time in total.
Re: A few beginner question from the new module dev tutorial
I don't fully understand this part:
You assign the result set to $this->_rs, (I'm guessing the underscore is a CMSMS naming convention?), what is the actual query in which the rows are returned? Is it:
The 'FOUND_ROWS();' is a MySQL function I'm guessing, (will investigate this) but how does it know what rows to select? You'd think it wants to base it on the result set, but '$this->_rs' isn't mentioned in this call.
Code: Select all
public function execute()
{
if( !is_null($this->_rs) ) return;
$sql = 'SELECT SQL_CALC_FOUND_ROWS H.*
FROM '.CMS_DB_PREFIX.'mod_holidays H ORDER BY the_date DESC';
$db = \cms_utils::get_db();
$this->_rs = $db->SelectLimit($sql,$this->_limit,$this->_offset);
IF( $db->ErrorMsg() ) throw new \CmsSQLErrorException($db->sql.' -- '.$db->ErrorMsg());
$this->_totalmatchingrows = $db->GetOne('SELECT FOUND_ROWS()');
}
Code: Select all
$this->_totalmatchingrows = $db->GetOne('SELECT FOUND_ROWS()');
Re: A few beginner question from the new module dev tutorial
It's jut a good practice.Guido wrote: Is it mandatory to name the smarty template file 'edit_holidat.tpl'? Or is this just a good idea to keep thing organised?
CMSMS is using ADOdb Lite 3rd party library for the db interactions, although it will slowly move away from it on the new versions. It should keep backwards compatibility as much as possible though. The $db object referenced there comes from that lib.Guido wrote:My second question:
I see there is a method called: 'Insert_ID()', which is a method of the database object. I looked at the api documentation, but couldn't find a database class. I'd like to know what this method does, and why it's called separately from the insertion from the rest of the record.
Docs on external site: http://adodblite.sourceforge.net/functions.php
It is not documented on the API (yet) but the best documentation is looking at the code itself . Peek the file and look at the comments: it's fairly well documented.Guido wrote: I read there is a 'CmsDbQueryBase' class, but I can't find that on this page: http://www.cmsmadesimple.org/APIDOC2_0/ ... s/CMS.html
No, it's not a method of LayoutTemplateQuery class, but of HolidayQuery class. It seems that there is a line missing there, on the original code of the tutorial, the $query->execute(): call, which would execute the query itself, just before the $holidays = $query->GetMatches();... probably like:Guido wrote:My third question:
I see this method used, which is a method if the 'LayoutTemplateQuery' class. It doesn't accept any arguments, am I correct to assume that this method knows from which module it's being called, so that it returns the records for this module automatically?Code: Select all
$holidays = $query->GetMatches();
Code: Select all
$query = new HolidayQuery;
$query->execute();
$holidays = $query->GetMatches();
HTH
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: A few beginner question from the new module dev tutorial
Nope. This is correct.
The GetMatches() method calls the MoveFirst() method which calls the execute() method... so all of the internals of executing the query are handled.
The CmsDbQuery base class contains a 'resultset/recordset' object, and has wrappers for many of the methods in that class. Derived classes are responsible for converting each and every returned row into an object of some type for returning to the application.
http://www.cmsmadesimple.org/APIDOC2_0/ ... yBase.html
Code: Select all
$query = new HolidayQuery;
$holidays = $query->GetMatches();
The CmsDbQuery base class contains a 'resultset/recordset' object, and has wrappers for many of the methods in that class. Derived classes are responsible for converting each and every returned row into an object of some type for returning to the application.
http://www.cmsmadesimple.org/APIDOC2_0/ ... yBase.html
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: A few beginner question from the new module dev tutorial
I suspected as much but missed that bit in the code itself when I looked. Makes sense and makes the code cleaner too .calguy1000 wrote:Nope. This is correct.The GetMatches() method calls the MoveFirst() method which calls the execute() method... so all of the internals of executing the query are handled.Code: Select all
$query = new HolidayQuery; $holidays = $query->GetMatches();
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Re: A few beginner question from the new module dev tutorial
Thanks, I'll study you answers as soon as I get the time.