typecho framework初步学习

typecho framework是70写的一个框架。听说是参考了java的思想。php

项目地址:https://github.com/typecho/framework
参考项目:https://github.com/typecho/framework-examplejava

1.一切hello world开始

先clone这个example,而后咱们要写个控制器,在action文件夹下新建Hello.phpgit

namespace Example\Action;

use TE\Mvc\Action\AbstractAction;

class Hello extends AbstractAction
{

    public function execute()
    {
        return array('content', 'Hello World');
    }
}

框架的主要想法是经过一个主出口返回各类须要的相应,好比content是指直接输出,换成template是把数据传到模板里,换成json就是把数据生成一个json。github

要先页面上显示咱们还须要写一下路由。
打开config\routes.php数据库


return array( '/' => 'Example\Action\Index', '/hello' => 'Example\Action\Hello' );

因为example中有用到数据库,咱们先注释掉。index.php文件中json

Base::setInjectiveObjects(require(ROOT . '/../config/injects.php'));

注释这行。
而后这样能够经过访问{fileroot}/portal/index.php/hello看到输出了hello world。框架

2.用模板输出

仍是Action\Hello.php里,咱们改execute函数函数

public function execute()
{
  $this->word = 'Hello World';

  return array('template', 'hello.php');
}

而后咱们在template中新建一个hello.php文件typecho

<?php echo $word; ?>

就能够看到页面输出hello worldui

3.把参数传入控制器

好比
http://192.168.33.10/framework-example/portal/index.php/hello?p=hello%20world
把p=hello world传入hello中

public function execute()
{
  $this->word = $this->request->get('p');
  return array('template', 'hello.php');
}

这样咱们就在页面上看到hello world。

先这样

相关文章
相关标签/搜索