PHPHMVC framework kohana summary 1

Source: Internet
Author: User
Tags kohana
Kohana summary of PHPHMVC framework 1 & nbsp; for details about kohana3 installation, refer to kohana summary 1 of hybrid php hmvc framework.

For the installation of kohana 3, see: http://jackyrong.iteye.com/admin/blogs/1186006.
1. set the development mode in bootstrap:
Kohana: $ environment = Kohana: DEVELOPMENT;
Add the following code:
If (isset ($ _ SERVER ['kohana _ env'])
{
Kohana: $ environment =$ _ SERVER [? KOHANA_ENV?];
}
Related values include:
PRODUCTION, STAGING, TESTING, and DEVELOPMENT.


2. set the time zone
Date_default_timezone_set ('America/Chicago ');
3. enable related modules
Kohana: modules (array (the comment in is opened as needed

4. create the default config file (this is worse than CI)
Set a file such as site. php under application \ config and place the variables for routine use, such:
Return array (
'Name' => 'egotist ',
'Tag _ line' => "Let's talk about me! "
);
Then, when obtaining the variable, it is as follows:
$ Site_config = Kohana: config ('site ');
$ Site_name = $ site_config ['name'];
$ Tag_line = $ site_config ['tag _ line'];
You can even load only one of the variables as follows:
$ Site_name = Kohana: config ('site. name ');

You can also load variables in the form of arrays, such:
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. the controller naming rules must comply with the following requirements:
Controller_xxxx and XXX are placed in classes/controller/xxx. php, for example
Controller_User_Profile is classes/controller/user/profile. php
6. pass data to the view

Controller:
Public function action_index ()
{
// 3.2 you can only use this method
$ View = View: factory ('Welcome ')
-> Set ('site _ name', 'egotist ')
-> Set ('random ', rand ));
$ This-> response-> body ($ view );
}

View:
Welcome
Is a number between 1 and 10


Bind can also be used for binding.

$ View = View: factory ('Welcome ')-> bind ('site _ name', $ site_name)
-> Bind ('random ', $ random );
$ Site_name = 'egotist ';
$ Random = rand (1, 10 );

$ This-> response-> body ($ view );

7. Use 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 on the page:


8. set global variables to facilitate direct reading on various pages
View: set_global ('site _ name', 'egotist Beta ');
You can then read the following information in any view:

9 in the control layer, write a base class to save some basic information, such as CSS, JAVASCRIPT, and constants.

Example:
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 can be inherited, which is very easy to use.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.