video: queries & code

  • suppose we want to create in the homepage a module with the list of the last 4 news, only title and date for each
  • first step is to create a query that returns title and date of news ordered by date
  • here is where we choose what properties of a news will be returned by the query: title and date
  • all results ordered by date, DESC
  • now execute our query to see if it returns desired results
  • that's ok: we only have 2 instances of news saved, and we receive their titles and dates
  • now we generate the .tpl file for the view and a .php file to call the query and assign results to the .tpl
  • to do so we create a new module inside the home page
  • then we assign our query to our module
  • and finally we generate the default .tpl and .php files associated to the query
  • and here it is our "latest news" module in homepage!
  • now suppose we want to add some custom php code
  • for example we want to set uppercase titles of news
  • we uncomment a pre generated block of code that loops on all results of the query, and set uppercase each property returned
  • after submitting we see our uppercase latest news
  • last thing is to reduce to 4 the number of results. to do so we set pagination variable
 

lingue

italiano english