Using the Framework: Basics: Unterschied zwischen den Versionen
Tm (Diskussion | Beiträge) |
Tm (Diskussion | Beiträge) |
||
| Zeile 60: | Zeile 60: | ||
* '''js:''' Put here your javascript files. For now there will no special processing be done. | * '''js:''' Put here your javascript files. For now there will no special processing be done. | ||
* '''etc:''' Put here everything else, like pdf or flash files. For now there will no special processing be done. | * '''etc:''' Put here everything else, like pdf or flash files. For now there will no special processing be done. | ||
Overjumping Image-Processing: If you do not want | |||
[[Controllers: Asset Management]] | |||
== Extended Form Handling == | == Extended Form Handling == | ||
Version vom 17. Februar 2014, 20:32 Uhr
MVC Approach
First of all you should learn how to create a simple webpage. For this you must understand the underlying framework CodeIgniter. CodeIgniter is a web application framework using the Model-View-Controller approach, which allows separation between logic and presentation. For further assistance read the very clear and thorough documentation here: http://codeigniter.com/user_guide/index.html
Here a little "Hello World" example:
To "write" a page you need at least a controller and a view. Create at first a file named test.php in the folder application/controllers/ with the following code:
<?php
class Test extends CI_Controller {
public function index()
{
$this->load->view('test');
}
}Then create a file named test.php in the folder application/views/ with the following code:
<h1>Hello World!</h1>
Now open the url "http://<yourdomain>/test". You will see your first webpage created with this framework. If you look into the sourcecode you will see one of the relevant differendes between CodeCoupler and CodeIgniter: You do not have to write a complete html-structure, CodeCoupler will do it for you.
Master Template with Components Concept
In contrast to the basic CodeIgniter framework, every output of a controller will be surrounded by a master-template. The basic layout of the master template looks like this:
<!DOCTYPE ... />
<html ... >
<head>
<charset ... />
<title> ... </title>
</head>
<body>
[YOUR CONTROLLER OUTPUT]
</body>
</html>
But the Master Template do much more:
- Enabling JavaScript and CSS libraries using a component concept.
- Autoloading scripts and styles
- Injecting snippets from everywhere in your code into every place in the template.
Read the full documentation of the master-template library here: Libraries: Master
Asset Management
Assets like images, stylesheets or javascripts will be placed into subfolders within application/assets. Every type will be processed specially:
- css: Put here your stylesheets. You can use SASS/SCSS for writing your stylesheet instructions. The files will be automatically compiled everytime they change and cached within the folder application/compiled/css. You can use every extension you want, you are not limited to ".css". Used library: https://github.com/richthegeek/phpsass - More info about SASS/SCSS: http://sass-lang.com/
- img: Put here your gif, png or jpg-images. Images will be automaticaly downsized for small devices, like mobile-phones. Retina displays will be detected and the bigger image will be used if there is one, thus they show a sharp image. The files will be automatically resized everytime they change and cached within the folder application/compiled/img. Used library: http://adaptive-images.com/
- js: Put here your javascript files. For now there will no special processing be done.
- etc: Put here everything else, like pdf or flash files. For now there will no special processing be done.
Overjumping Image-Processing: If you do not want
Extended Form Handling
The whole usage of form-elements is packaged in a new form-class which encloses the existing form-validation-class and form-helper of CodeIgniter. The goal was to avoid some always recurring coding. To insert a text-field, for example, it is not enough to write “form_input($data)”. You have to remember the validation of the field, set the value to the previous posted, set the correct class if an error occurred and so on. A radio-button group or a group of checkboxes you have to think much more about the whole roundtrip and validation. Or what in case if you want to add more than one form onto one page? Using the form-class you will not need doing all this.
Here is a simple example of a view including a form. You do not have to do anything more in the controller than loading this view. A validation of the form will be done for you automatically based on configuration file for this form:
<?=form_start('example_form')?>
<?=form_label('name')?>:<br /><?=form_field('name')?> <br /><br />
<?=form_label('amount')?>:<br /><?=form_field('amount')?> <br /><br />
<br />
<?=form_submit()?>
<?=form_end()?>
<br />
<?=form_errors()?>
<?=form_confirmation()?>Read the full documentation of the form-handling library here: Libraries: Form
Multilanguage Routing
- tbd -
Default Enabled Components
- tbd -
