The Onethink of learning ideas

Source: Internet
Author: User
Tags explode

In the previous period, thinkphp's overall design ideas, including the implementation of each module.

TP official in order to test the framework, wrote a Onethink, is can learn under the


It is not recommended to use this, the feeling is testing nature. But you can understand his design ideas, continue to deepen the thinking, you can re-write a suitable for their own.


For example: test various environments and combine data information with arrays

$items = Array (' os ' = = Array (' OS ', ' Unrestricted ', ' Unix-like ', Php_os, ' success '), ' php ' = = Array (' PHP Version ', ' 5.3 ', ' 5.3+ ', php_version, ' success '), ' upload ' = = Array (' Attachment upload ', ' No Limit ', ' 2m+ ', ' unknown ', ' success '), ' GD ' = ' = Array (' GD library ', ' 2.0 ', ' 2.0+ ', ' unknown ', ' success '), ' disk ' = = Array (' Diskette space ', ' 5M ', ' No Limit ', ' unknown ', ' succ ESS '),);

You can then use references to make real-time changes to your data

foreach ($items as & $val)

Another example: some of the ideas of automation, write a part of the configuration file or SQL statement or output file template, and then replace some of the information

Conf.tpl

<?php// +----------------------------------------------------------------------// | onethink  [ we can do it just think it ]// +------------------------- ---------------------------------------------// | copyright  (c)  2013 http:// www.onethink.cn All rights reserved.// +-------------------------------------------------- --------------------// | author:  mai Fuel  <[email protected]> 

And then write a partial replacement

$conf = Str_replace (' [Auth_key] ', $auth, $conf); $user = Str_replace (' [Auth_key] ', $auth, $conf);

Or to say replace or read execution

Read SQL file $sql = file_get_contents (Module_path.    ' Data/install.sql ');    $sql = Str_replace ("\ r", "\ n", $sql);    $sql = explode ("; \ n", $sql);    Replace table prefix $orginal = C (' Original_table_prefix '); $sql = Str_replace ("' {$orginal} '," ' {$prefix} ", $sql);

Another example: The extension of TP is the core of behavior

Write a tags.php

Return Array (' App_init ' =>array (' Common\behavior\inithookbehavior '));

This allows you to use the components you want to parse the template, various rights management, routing control, the application of the front post-processing, some of the cross-sectional tools

This allows you to dynamically add many components and extend the core of your framework, not the components, but how you make data flow, composition, and storytelling. This is the most commendable place in the program.

His inithookbehavior under the appendix.

Class Inithookbehavior extends Behavior{public function run (& $content) {if (Defined (' Bind_module ') && bind_ MODULE = = = ' Install ') return, $data = S (' hooks '), if (! $data) {$hooks = M (' hooks ')->getfield (' name,addons '); foreach ($ Hooks as $key = $value) {# code...if ($value) {$map [' status '] = 1; $names = explode (', ', $value); $map [' name '] = Array (' in ') , $names), $data = M (' Addons ')->where ($map)->getfield (' Id,name '), if ($data) {$addons = Array_intersect ($names, $ data); Hook::add ($key, Array_map (' Get_addon_class ', $addons));}}} S (' hooks ', hook::get ());} Else{hook::import ($data, False);}}} Add-ons addons//from the hooks to the accessory to find the corresponding component


This involves automating the operation of the senses, which reminds us of Python.


Just write so much, technology is for everyone, everyone's potential is different, we have a lot of people around the point of interest is not the same. Take care of your life and go to the summit.


May all sentient beings in the law world be well-off.

This article is from the "one-stop solution" blog, so be sure to keep this source http://10725691.blog.51cto.com/10715691/1963481

The Onethink of learning ideas

Related Article

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.