PHP HMVC Framework Kohana Summary 1
Before the installation of Kohana 3 see: http://jackyrong.iteye.com/admin/blogs/1186006
1 set the development mode in bootstrap:
Kohana:: $environment = Kohana::D evelopment;
Add the following code:
if (Isset ($_server[' kohana_env '))
{
Kohana:: $environment = $_server[? Kohana_env?];
}
The relevant values are:
PRODUCTION, STAGING, testing, and development.
2 Setting the time zone
Date_default_timezone_set (' America/chicago ');
3 Enabling the relevant module
Kohana::modules (the comment in the array opens as needed
4 Create a default Config file (this is worse than CI)
Set a file such as site.php under Application\config, and place the variables that are commonly used in the day, such as:
Return Array (
' Name ' = ' egotist ',
' Tag_line ' = ' Let's talk about me! '
);
When the variable is obtained, this is:
$site _config = kohana::config (' site ');
$site _name = $site _config[' name '];
$tag _line = $site _config[' tag_line ');
You can even load only one of these variables:
$site _name = kohana::config (' Site.name ');
You can also load variables in the form of arrays, such as:
Return Array (
' Name ' = ' egotist ',
' Details ' = Array (
' Tag_line ' = ' Let's talk about me! ',
' Alt_tag_line ' = "Today's subject:me!";
);
);
Load:
$site _config = kohana::config (' site ');
Echo Site name and details
echo $site _config[' name ']; Egotist
echo $site _config[' Details ' [' tag_line ']//Lets Talk about me!
echo $site _config[' Details ' [' alt_tag_line ']//Today ' s subject:me!
You can also:
echo kohana::config (' site.details.tag_line ');
5 controller naming specification must conform to the following
Controller_xxxx,xxx on classes/controller/xxx.php, like
Controller_user_profile is the classes/controller/user/profile.php
6 Passing data to view
Controller:
Public Function Action_index ()
{
3.2 Can only use this method
$view = view::factory (' Welcome ')
->set (' site_name ', ' egotist ')
->set (' Random ', rand (1,10));
$this->response->body ($view);
}
In view:
Welcome to
is a number between 1 and 10
You can also bind with bind
$view = view::factory (' Welcome ')->bind (' site_name ', $site _name)
->bind (' random ', $random);
$site _name = ' egotist ';
$random = rand (1, 10);
$this->response->body ($view);
7 Using Template Controller
Class Controller_welcome extends Controller_template
{
$content = view::factory (' Welcome ')
->bind (' random ', $random);
$random = rand (1, 10);
$content->site_name = ' egotist Beta ';
$this->template->content = $content;
}
}
Direct output from the page:
8 set global variables to make it easy to read directly from each page
View::set_global (' site_name ', ' egotist Beta ');
can then be read in any view:
9 in the control layer, write a base class, save some basic information, such as Css,javascript, constants can this
Sample:
Abstract class Controller_application extends Controller_template {
Public function before ()
{
Parent::before ();
View::set_global (' site_name ', ' egotist Beta ');
$this->template->content = ";
$this->template->styles = Array ();
$this->template->scripts = Array ();
}
Other PHP control layer files re-inherit, very useful