public static function main(array $args = array())
 {
     $tea = new Tea();
     $coffee = new Coffee();
     println("Making tea...");
     $tea->prepareRecipe();
     println("Making coffee...");
     $coffee->prepareRecipe();
 }
Пример #2
0
 /**
  * 从配置文件中创建表单
  * @param string $action     表单的url	
  * @param string $configName  配置文件的名字
  * @return Form_Tea $form
  */
 protected static function _createFormConfig($action, $configName)
 {
     $form = new Form_Admin_Tea('tea_form', $action);
     $filename = rtrim(dirname(__FILE__), '/\\') . DS . $configName;
     $form->loadFromConfig(Helper_YAML::load($filename));
     $form->addValidations(Tea::meta());
     //图片的路径
     $form['thumb_filename']->dir = Q::ini('appini/teapics/img_dir');
     //上传图片的限制
     $types = Q::normalize(Q::ini('appini/teapics/upload_allowed_types'));
     $size = intval(Q::ini('appini/teapics/upload_allowed_size') * 1024);
     $dim = Q::ini('appini/teapics/img_pic_width') . 'x' . Q::ini('appini/teapics/img_pic_height');
     $form['postfile']->_tips = sprintf($form['postfile']->_tips, implode('/', $types), $size / 1024, $dim);
     //        茶叶类别
     //       $teatype = new TeaType();
     //       $form['type_id']->items=$teatype->list;
     $form->selectUploadElement('postfile')->uploadAllowedSize($size)->uploadAllowedTypes($types)->enableSkipUpload();
     return $form;
 }
Пример #3
0
<?php

function __autoload($class_name)
{
    require_once $class_name . '.php';
}
$coffee = new Coffee();
$tea = new Tea();
$coffee->prepareRecipe();
$tea->prepareRecipe();
Пример #4
0
<?php

ini_set('display_errors', "On");
error_reporting(E_ALL | E_STRICT);
//自动加载类
set_include_path(get_include_path() . PATH_SEPARATOR . 'class/');
//设置加载路径
spl_autoload_extensions('.php');
//设置加载后缀名
function myAutoload($className)
{
    require_once $className . '.php';
    //直接根据类名跟文件关系包含文件
}
spl_autoload_register("myAutoload");
//注册自动加载函数
//测试代码开始
$myTea = new Tea();
$myTea->prepareRecipe();
echo '<hr>';
echo file_get_contents('./read.txt');
 /**
  * ajax 实现茶叶是否上架
  *
  */
 function actionAjaxIsShow()
 {
     if ($this->_context->isAJAX()) {
         //得到茶叶的信息
         $is_show = $this->_context->post('is_show');
         $tea_id = $this->_context->post('tea_id');
         try {
             //更新上架状态
             if (in_array($is_show, array(0, 1))) {
                 Tea::meta()->updateDbWhere(array('is_show' => $is_show), 'id =?', $tea_id);
                 echo true;
             }
         } catch (QDB_Exception $ex) {
             if ($ex->getCode()) {
                 echo false;
             }
         }
     } else {
         echo false;
     }
 }