Skip to content

Instantly share code, notes, and snippets.

@suin
Created August 26, 2012 13:40
Show Gist options
  • Save suin/3479460 to your computer and use it in GitHub Desktop.
Save suin/3479460 to your computer and use it in GitHub Desktop.
^_^)/ {/tmp/php-yaf/tools/cg) (master) (5.4.5)
$ php yaf_cg
Yaf Code Generetor Version 1.0.0
Usage:
yaf_cg ApplicationName [ApplicationPath]
^_^)/ {/tmp/php-yaf/tools/cg) (master) (5.4.5)
$ php yaf_cg foo
DONE
^_^)/ {/tmp/php-yaf/tools/cg) (master) (5.4.5)
$ ls
output/ templates/ yaf_cg*
^_^)/ {/tmp/php-yaf/tools/cg) (master) (5.4.5)
$ cd output/
^_^)/ {/tmp/php-yaf/tools/cg/output) (master) (5.4.5)
$ la
total 0
drwxr-xr-x 3 suin wheel 102B 8 26 22:36 ./
drwxr-xr-x 5 suin wheel 170B 8 26 22:36 ../
drwxr-xr-x 7 suin wheel 238B 8 26 22:36 foo/
^_^)/ {/tmp/php-yaf/tools/cg/output) (master) (5.4.5)
$ cd foo/
^_^)/ {/tmp/php-yaf/tools/cg/output/foo) (master) (5.4.5)
$ la
total 24
drwxr-xr-x 7 suin wheel 238B 8 26 22:36 ./
drwxr-xr-x 3 suin wheel 102B 8 26 22:36 ../
-rw-r--r-- 1 suin wheel 78B 8 26 22:36 .htaccess
drwxr-xr-x 8 suin wheel 272B 8 26 22:36 application/
drwxr-xr-x 3 suin wheel 102B 8 26 22:36 conf/
-rw-r--r-- 1 suin wheel 174B 8 26 22:36 index.php
-rw-r--r-- 1 suin wheel 424B 8 26 22:36 readme.txt
^_^)/ {/tmp/php-yaf/tools/cg/output/foo) (master) (5.4.5)
$ php index.php
Fatal error: Uncaught exception 'Yaf_Exception' with message 'There is no section 'devel' in '/private/tmp/php-yaf/tools/cg/output/foo/conf/application.ini'' in /private/tmp/php-yaf/tools/cg/output/foo/index.php on line 5
Yaf_Exception: There is no section 'devel' in '/private/tmp/php-yaf/tools/cg/output/foo/conf/application.ini' in /private/tmp/php-yaf/tools/cg/output/foo/index.php on line 5
Call Stack:
0.0002 227464 1. {main}() /private/tmp/php-yaf/tools/cg/output/foo/index.php:0
0.0003 228584 2. Yaf_Application->__construct() /private/tmp/php-yaf/tools/cg/output/foo/index.php:5
>_<) {/tmp/php-yaf/tools/cg/output/foo) (master) (5.4.5)
$ vim application/controllers/
Error.php Index.php
>_<) {/tmp/php-yaf/tools/cg/output/foo) (master) (5.4.5)
$ vim conf/application.ini
I added [devel : common] to application.ini
@suin
Copy link
Author

suin commented Aug 26, 2012

application/controllers/Index.php

<?php
/**
 * @name IndexController
 * @author suin
 * @desc 默认控制器
 * @see http://www.php.net/manual/en/class.yaf-controller-abstract.php
 */
class IndexController extends Yaf_Controller_Abstract {

    /** 
     * 默认动作
     * Yaf支持直接把Yaf_Request_Abstract::getParam()得到的同名参数作为Action的形参
     * 对于如下的例子, 当访问http://yourhost/foo/index/index/index/name/suin 的时候, 你就会发现不同
     */
    public function indexAction($name = "Stranger") {

        echo $aaaa; // I added this!

        //1. fetch query
        $get = $this->getRequest()->getQuery("get", "default value");

        //2. fetch model
        $model = new SampleModel();

        //3. assign
        $this->getView()->assign("content", $model->selectSample());
        $this->getView()->assign("name", $name);

        //4. render by Yaf, 如果这里返回FALSE, Yaf将不会调用自动视图引擎Render模板
        return TRUE;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment