Username Password        Sign up Lost password

Create the home page

written by bcoos on 16 June 2012

Now we have the controller created from previous chapter.

Edit the controller.php to look like this

<?php // bcoos 2.0 GPL àèíóú UTF-8
class whyController extends bcoosController {
	function index() {

The controller have the default action on module index, it only calls the view, created in previous chapter.

The next step is to register module on bcoos.

Execute this query on the bcoos database, change table prefix if necessary.

INSERT INTO `bcoos_modules` (`id` ,`directory` ,`slug` ,`title`) VALUES ('53', 'why', 'why', 'why');

After executing the query go to you must see this screen:

The text that appears is the text entered on view file index.php on the create module structure chapter you can change this text and refresh browser to see changes.

But we want that for when we go to to achieve this we must register the method on bcoos, only registered methods that are available for anonymous users are possible home pages.

To register a method we need to create a string to associate with this method, bcoos provides interface translation to multiple languages, bcoos uses UTF-8 encoding and you can translate interface to your language if you want.

Register string

Login with the user provided during installation.

Go to administration > system > register strings

Enter the string identifier why_home_page it must be of form
(lowercase letters, numbers and underscores) ex(string10_exemple) enter in default language the string of the english translation in our case home page.

You can enter translations for your language select the new language option and choose the two letter iso of your language if it's not present above.

Click on save and you will get the Saved define message.

If you entered a new language you will see a field to enter translation for that language in new string registration.

We can access anywhere in the code the string registered
 using the function t()  use t('string_identifier')  to get 
the string in the selected default bcoos language

Now we can use the new string identifier registered to associate it to the why/index method.

Register method

Go to administration > system > register methods

Scroll down the page and the last module is why, you will see in red an unregistered method.

Click on unregistered index to register it.

Choose method type content and enter the define previously registered why_home_page save and you will see the message Method updated, if you scroll down the page on why section you will see the method registered with translation and method name in parentheses.

When bcoos registers a new method by default is only available to administrators group, now we can go to manage groups and make this method available to registered users and anonymous users.

Give permissions to method to anonymous and registered users

Go to administration > system > groups

Click on registered group go to why section and tick index to make this method available to registered users, make the same on anonymous group.

Now the index method can be the default index page.

Go to administration > system > configuration

In the middle of page on home page select why and index

Go to and you must see the home page is now an action of why module.

Now we will change the text provided during create module structure chapter.

Change the view file of why module index.php to this code:

<?php // bcoos 2.0 GPL àèíóú UTF-8 

echo t('why_home_page');

We must use the t() function for all strings to provide the possibility to use our applications in different languages.

Next chapter - Create first question

Previous chapter - Create module structure

Table of contents - How to make a Question / Answer site

View all tags bcoos why tutorial


Powered by bcoos 2.0 | 0.0093 seconds | 25 queries | SQL: 0.0015 seconds | 42 files: 322.73 KB | HTML: 15.79 KB