Blog Blog http://www.bcoos.net/tag/tutorial Mon, 17 Dec 2018 10:49:29 +0100 FeedCreator 1.7.2 http://www.bcoos.net/includes/images/logo.png Blog http://www.bcoos.net/tag/tutorial Blog Create the home page http://www.bcoos.net/create-the-home-page <span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span>Now we have the controller created from previous chapter.<br><br>Edit the controller.php to look like this<br><span><span><br><pre class="brush: php">&lt;?php //bcoos.net bcoos 2.0 GPL àèíóú UTF-8 class whyController extends bcoosController { function index() { $this-&gt;loadView('index'); } }</pre><br></span></span>The controller have the default action on module index, it only calls the view, created in previous chapter.<br><br>The next step is to register module on bcoos.<br><br>Execute this query on the bcoos database, change table prefix if necessary.<br><span><br><pre class="brush: sql">INSERT INTO `bcoos_modules` (`id` ,`directory` ,`slug` ,`title`) VALUES ('53', 'why', 'why', 'why');</pre></span><br>After executing the query go to <span style="font-style: italic;">example.com/why</span> you must see this screen:<br><br><img src="http://www.bcoos.net/includes/images/uploaded/why-first-home-page.png"><br><br><br>The text that appears is the text entered on view file index.php on the <span><a href="http://www.bcoos.net/create-module-structure">create module structure</a></span> chapter you can change this text and refresh browser to see changes.<br><br>But we want that for when we go to <span style="font-style: italic;">example.com </span>to achieve this we must register the method on bcoos, only registered methods that are available for anonymous users are possible home pages.<br><br>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.<br><br></span></span></span></span></span></span></span></span></span></span></span></span><h3><span><span><span><span><span><span><span><span><span><span><span><span>Register string</span></span></span></span></span></span></span></span></span></span></span></span></h3><span><span><span><span><span><span><span><span><span><span><span><span>Login with the user provided during installation.<br><br>Go to <span style="font-style: italic;">administration &gt; system &gt; register strings</span><br><br>Enter the string identifier <span style="font-style: italic;">why_home_page</span> it must be of form </span></span></span></span></span></span></span></span></span>(lowercase letters, numbers and underscores) ex(string10_exemple) enter in default language the string of the english translation in our case <span style="font-style: italic;">home page.<br><br></span>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. <span style="font-style: italic;"><br></span><br>Click on save and you will get the <span style="font-style: italic;">Saved define</span> message.<br><br>If you entered a new language you will see a field to enter translation for that language in new string registration.<br><br></span></span></span></span><div style="text-align: center;"> <span style="font-style: italic;">We can access anywhere in the code the string registered<br>&nbsp;using the function t()&nbsp; use <span style="font-weight: bold;">t('string_identifier')</span>&nbsp; to get&nbsp; <br>the string in the selected default bcoos language</span><br><span><span><span><span></span></span></span></span></div><span><span><span><span><br>Now we can use the new string identifier registered to associate it to the why/index method.<br><br></span></span></span><h3><span><span><span>Register method </span></span></span></h3><span><span><span>Go to <span style="font-style: italic;">administration &gt; system &gt; register methods</span><br style="font-style: italic;"><br>Scroll down the page and the last module is why, you will see in red an unregistered method.<br><br>Click on unregistered index to register it.<br><br>Choose method type <span style="font-style: italic;">content</span> and enter the define previously registered <span style="font-style: italic;">why_home_page</span> save and you will see the message <span style="font-style: italic;">Method updated</span>, if you scroll down the page on why section you will see the method registered with translation and method name in parentheses.<br><br>When bcoos registers a new method by default is only available to <span style="font-style: italic;">administrators</span> group, now we can go to manage groups and make this method available to <span style="font-style: italic;">registered</span> users and <span style="font-style: italic;">anonymous</span> users. <br><br></span></span></span><h3><span><span><span>Give permissions to method to anonymous and registered users<br></span></span></span></h3><span><span><span>Go to <span style="font-style: italic;">administration &gt; system &gt; groups </span><br style="font-style: italic;"><br>Click on <span style="font-style: italic;">registered</span> group go to <span style="font-style: italic;">why</span> section and tick <span style="font-style: italic;">index </span>to make this method available to <span style="font-style: italic;">registered </span>users, make the same on <span style="font-style: italic;">anonymous</span> group.<br><br>Now the index method can be the default index page.<br><br>Go to <span style="font-style: italic;">administration &gt; system &gt; configuration</span><br><br>In the middle of page on <span style="font-style: italic;">home page </span>select <span style="font-style: italic;">why</span> and <span style="font-style: italic;">index<br><br></span>Go to <span style="font-style: italic;">example.com</span> and you must see the home page is now an action of why module.<br><br><img src="http://www.bcoos.net/includes/images/uploaded/why-first-home-page.png"><br><br style="font-style: italic;"><span style="font-style: italic;"></span><span><span><span><span><span><span><span><span><span>Now we will change the text provided during <span><a href="http://www.bcoos.net/create-module-structure">create module structure</a></span> chapter.<br><br>Change the view file of why module index.php to this code:<br><span><br><pre class="brush: php">&lt;?php //bcoos.net bcoos 2.0 GPL àèíóú UTF-8 echo t('why_home_page');</pre></span><br>We must use the t() function for all strings to provide the possibility to use our applications in different languages.<br><span><a href="http://www.bcoos.net/create-first-question"><br><span>Next chapter - Create first question</span></a></span><span><br><a href="http://www.bcoos.net/create-module-structure">Previous chapter - Create module structure</a></span><br><br><span><a href="http://www.bcoos.net/bcoos-tutorial-how-to-make-a-question-answer-site-why-bcoos-net">Table of contents - How to make a Question / Answer site why.bcoos.net</a></span><br></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span> Sat, 16 Jun 2012 23:05:35 +0100 Create module structure http://www.bcoos.net/create-module-structure <span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><img src="http://www.bcoos.net/includes/images/uploaded/bcoos-fresh-install.png"><br><br>Now we have bcoos installed but the default page when we go to our domain is to show blog/index action. But we can change this.<br><br>Our home page must be why/index, but at this time we don't have the why module.<br><br>To change default action to why/index we have to make few steps the first one is create a new module structure to hold our application.<br><br>Let's go to create the structure of why module.<br><br></span></span></span></span></span></span></span></span></span></span></span></span></span><div style="text-align: center;"><span><span><span><span><span><span><span><span><span><span><span><span><span><span style="font-style: italic;">A module contains a full application</span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></div><span><span><span><span><span><span><span><span><span><span><span><span><span><br>The minimal folder structure of a bcoos module is the following:<br><span><br><pre class="brush: bash">controller models views/themes/bcoos/blocks views/themes/bcoos/css views/themes/bcoos/images views/themes/bcoos/layouts tests</pre><br>Create the module folder structure inside a why folder.<br><br>In case we are making a foo module it would be inside a foo folder.<br><br></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><h3><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span>Module folder structure</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h3><h3><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></h3><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><br>The <span style="font-style: italic;">controller</span> folder has one unique controller per module.<br></span></span></span></span></span></span></span></span></span></span></span></span></span></span><div style="text-align: center;"><span><br><span style="font-style: italic;">The controller have methods each one gets data from models and send it to the choosen view </span><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><span><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div><span><span><span><span><span><span><span><span><span><span><span><span><span><span><br>The <span style="font-style: italic;">models</span> folder can have one or more models.<br><br></span></span></span></span></span></span></span></span></span></span></span></span></span></span><div style="text-align: center;"><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span style="font-style: italic;">Models get data from database and send it to controller</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br></div><span><span><span><span><span><span><span><span><span><span><span><span><span><span><br>The <span style="font-style: italic;">view/themes/bcoos</span> folder has the views files.<br><br></span></span></span></span></span></span></span></span></span></span></span></span></span></span><div style="text-align: center;"><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span style="font-style: italic;">A view is a representation of the model</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><br><span><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div><span><span><span><span><span><span><span><span><span><span><span><span><span><span>The </span></span></span></span></span></span></span></span></span></span><span style="font-style: italic;">views/themes/bcoos/blocks</span> has the blocks files. <br><br><div style="text-align: center;"><span style="font-style: italic;">A block is a view embedded in a layout</span><br></div><br>The <span style="font-style: italic;">views/themes/bcoos/layouts<span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span> has the layouts files.<br><br><div style="text-align: center; font-style: italic;">A layout is a group of one view and 0 or more blocks<br></div><br>The <span style="font-style: italic;">views/themes/bcoos/css</span> has the css files specific to module.<br>The <span style="font-style: italic;">views/themes/bcoos/js</span> has the javascript files specific to module.<br>The <span style="font-style: italic;">views/themes/bcoos/images</span> has the image files specific to module.<br><br>The <span style="font-style: italic;">tests</span> folder has the tests specific to this module.<br><br></span></span></span></span></span></span><span><span><span><span><span><span></span></span></span></span></span></span><h2>Minimal files at module structure</h2><br>The minimal files a module can have are:<br><span><br><pre class="brush: bash">controller/controller.php models/why.php views/themes/bcoos/index.php </pre><br></span>The model isn't necessary but without a model our site will be static.<br>For convention we name the model with the same name of module.<br><br>Create these three files with this content:<br><br><span style="font-style: italic;">controller/controller.php<br><span><br><pre class="brush: php">&lt;?php //bcoos.net bcoos 2.0 GPL àèíóú UTF-8 class whyController extends bcoosController { }</pre></span></span></span></span></span></span><div style="text-align: center;"><span><span style="font-style: italic;">controller class naming <span style="font-weight: bold;">module</span>Controller</span><span><span><span></span></span></span></span><br><span><span><span><span></span></span></span></span></div><span><span><span><span><br><span style="font-style: italic;">models/why.php<br><span><br><pre class="brush: php">&lt;?php //bcoos.net bcoos 2.0 GPL àèíóú UTF-8 class whyModel extends bcoosModel { }&nbsp;&nbsp;&nbsp;&nbsp; </pre></span></span><br></span></span></span></span><div style="text-align: center;"><span style="font-style: italic;">model class naming <span style="font-weight: bold;">modelName</span>Model</span><br><br><span><span><span><span></span></span></span></span></div><span><span><span><span><br><span style="font-style: italic;">views/themes/bcoos/index.php<span><br><span style="font-family: monospace;"><span><br><pre class="brush: php">&lt;?php //bcoos.net bcoos 2.0 GPL àèíóú UTF-8 ?&gt; This is where the home page will go. </pre></span></span></span></span><br><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span><span><a href="http://www.bcoos.net/create-the-home-page">Next chapter - Create the home page</a></span><br><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span><span style="text-decoration: underline;"></span><span><span><span><span><span><span><span><span><span><span><span><a href="install-bcoos"></a></span><span><a href="http://www.bcoos.net/install-bcoos">Previous chapter - Install bcoos</a></span><br><br><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span><a href="bcoos-tutorial-how-to-make-a-question-answer-site-why-bcoos-net"><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span>Table of contents - </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>How to make a Question / Answer site why.bcoos.net</a></span></span></span><br><span><span><span><span><span><br>&nbsp;<br></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span> Sat, 16 Jun 2012 20:09:38 +0100 Install bcoos http://www.bcoos.net/install-bcoos <span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span>Go to were httpdocs reside on your domain and download bcoos files.<span><br><pre class="brush: bash">cd /home/to/your/example.com/httpdocs svn export http://svn.bcoos.net/trunk/core</pre></span>Svn will download files to the directory on a folder named core<br><br><br>Move files of core folder to the same directory and list files on the directory.<span><span style="font-family: monospace;"><span><br><pre class="brush: bash">mv core/* . mv core/.htaccess . ls -a</pre><br></span></span>You must obtain a file list similar to this.<span><br><pre class="brush: bash">. applications core icon.png index.php INSTALL.en.txt removeInstallDirectory.php version.php .. config.php .htaccess includes install LICENSE-GPL.txt update </pre><br>Remove core folder<span><br><pre class="brush: bash">rm -fr core</pre></span><br>Go to the <span style="font-weight: bold;">http://example.com</span> in your browser, you must see a screen like this:<br><br><img src="http://www.bcoos.net/includes/images/uploaded/bcoos-install.png"><br></span><br>At the </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>/home/to/your/example.com chmod the following files:<span><br><pre class="brush: bash">chmod 0666 config.php chmod 0777 includes/cache chmod 0777 includes/cache/permissions chmod 0777 includes/cache/pages chmod 0777 includes/image/uploaded chmod 0777 includes/image/uploaded/anonymous</pre></span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span>Fill the form with database settings and the administrator account data.<br><br>Click save and point again your browser to http://example.com you will see a screen asking to remove install folder.<br><br>Remove install folder:<br><span><pre class="brush: bash">rm -fr install</pre><br></span>Click on the link with your url and it must show the screen of a fresh bcoos installation.<br><br><br><img src="http://www.bcoos.net/includes/images/uploaded/bcoos-fresh-install.png"><br><br>Login with the data of administrator account provided during setup.<br><br>Now bcoos is installed properly.<br><br></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><a href="../create-module-structure">Next chapter - Create module structure</a><br><br><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span><a href="http://www.bcoos.net/bcoos-tutorial-how-to-make-a-question-answer-site-why-bcoos-net"><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span>Table of contents - </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>How to make a Question / Answer site why.bcoos.net<span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></a></span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><br><span></span><br></span><span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span> Sat, 16 Jun 2012 16:34:51 +0100 bcoos Tutorial - How to make a Question / Answer site why.bcoos.net http://www.bcoos.net/bcoos-tutorial-how-to-make-a-question-answer-site-why-bcoos-net <span><span><span><span><span><span><span>Chapters<br></span><ul><li><span><a href="http://www.bcoos.net/install-bcoos">Install bcoos</a></span></li><li><span><a href="http://www.bcoos.net/create-module-structure">Create module structure</a></span></li><li><span><span><a href="http://www.bcoos.net/create-the-home-page">Create the home page</a></span></span></li><li><span><span><span><a href="http://www.bcoos.net/create-first-question">Create first question</a></span><br></span></span></li></ul><span></span></span></span></span></span></span></span> Sat, 16 Jun 2012 16:01:14 +0100