返回列表 回复 发帖

新手学习 Zend Framework 框架连载(二)[原创]

[入门]新手学习 Zend Framework 框架

本帖最后由 七月十五 于 2009-5-16 13:48 编辑

前言:Zend Framework 对于有些新手来说.觉得很难,其实只要明白其中的一些原理就可以,轻松自在的学好它.
对于一些新手,写程序,往往,没办法有规划,而用Zend Framework 你可以让你少走很多弯路!好了废话少说.开始学习Zend Framework 了,以下Zend Framework 简称:ZF

第一章:Zend Framework简单配置,测试文件!

1.首先去下载最新版本的 Z F [url]http://framework.zend.com/download/zip[/url](注意.好象官方的0.15的版本有点问题, SVN里面的,我放到自己的空间上了:http://www.phpwb.com/library.rar

2.解压后把library文件夹放在网站根目录下

这里我讲解的是让ZF在子目录下运行.
在test子目录下建立如下文件夹
test目录下建立
  Application
   Controllers
   Models
   Views



3.写一个index.php放在test目录下index.php

<?

set_include_path
('../library');//根目录下的库文件

include 'Zend.php';

function 
__autoload($class)//自动加载类

{

  
Zend::loadClass($class);

}

$view = new Zend_View;

$view->setScriptPath('./Application/Views');  //放显示的文件的地方

Zend::register('view'$view);              //注册对象



//下面这些的作用是在子目录下。新手不管它,能用就行

$router = new Zend_Controller_RewriteRouter();

$controller Zend_Controller_Front::getInstance();

$controller->setRouter($router);



$controller->setControllerDirectory('./Application/controllers');//简单的说是放我们设计php控制文件的地方

$controller->dispatch();

复制代码
4.在controllers写一个Indexcontroller.php(注意,一定要记得是:Indexcontroller.php,不要保存错了变成index.php)

Indexcontroller.php

<?

//首页控制

class IndexController extends Zend_Controller_Action 

{

      

    public function 
indexAction()

    {

    
$view=Zend::registry('view');//取出对象

    
echo $view->render('test.php');//显示数据

    
}

     public function 
noRouteAction() //这个在每个IndexController都要记得加上去。才不会出现错误!   

      
{       

       
$this->_redirect('../');//转到首页

      
}



}

?>

复制代码
5.在Views文件夹里建立个test.php和上面的文件名一样

test.php
这是一个简单的ZF例子!

这里你想写什么都行.^_^

复制代码
6.打开浏览器运行下http://localhost/test/index.php

是不是看到上面的test.php里面的内容...高兴吧....^_^ ^_^


7.传递变量i
高兴的话,接着下一个传递变量i的值得512
http://localhost/test/index.php/Love/index/i/512

I.在controllers下写一个Controller.php

LoveController

<?php

//传递512

class LoveController extends Zend_Controller_Action 

{

      

    public function 
indexAction()

    {

     
$view=Zend::registry('view');//取出对象

     
$love=$this->_getParam('i');//取得i的值512;

     
$view->i="$love";

     echo 
$view->render('love.php');//显示512的数据

    
}



   function 
__call($action,$args)//这个除了在IndexControlle不需要放。其他的每写个,都要放。。

    


     
$this->_redirect('../');

    }



}

?>

复制代码
II.同样在Views文件夹里面建立个love.php
love.php

<?php echo $this->escape($this->i); ?>//escape是一个过滤函数,把数据过滤.和php里面的htmlspecialchars()一样

复制代码
III.在浏览器打开:http://localhost/test/index.php/Love/index/i/512

是不是看到浏览器上显示出512


好了。今天就到这里.有什么不明白的地方,可以提出来..^_^
下一章预告:
ZF中mysql数据库连接操作以及一些技巧性操作!
(这一章,数据库操作连接可以去看下,论坛上的文章*,主要是看下技巧性操作)
MVMMALL首席CEO
www.mvmmall.com

新手学习 Zend Framework 框架连载(二)[原创]

第二章:ZF中mysql数据库连接操作以及一些技巧性操作!

1.正确加载了PDO扩展.
以下引用Haohappy 的
在看这些之前请确保你正确加载了PDO扩展。

作法是编辑php.ini
手动增加下面这两行(前面要没有分号;):
extension=php_pdo.dll
extension=php_pdo_mysql.dll

然后要把extension_dir
指向php_pdo.dll及php_pdo_mysql.dll所在目录,如
extension_dir = "C:\php5\ext"

OK,let's go..
2.连接mysql数据库
本人的做法是把所有的数据库操作在进行2次封装,
这样的好处是,逻辑性很强!
纯属个人观点!

上一章中也许有人会问Models文件夹有什么用.
我是用来放一些类,和数据库操作类.

I.在Models文件夹下建立Datebase.php
Datebase.php

<?php

class Database

 
{

   private 
$db;

   public function 
__construct() 

        {

          
Zend::loadClass('Zend_Db');

          
$params = array ('host' => 'localhost',                //主机

                       
'username' => 'root',                    //用户名

                       
'password' => '123456',               //密码

                       
'dbname'   => 'xgwork');              //数据库名称

          
$this->db Zend_Db::factory('pdo_Mysql'$params);

        }

  public function 
insert($table,$row)//插入数据行

       
{

         
$this->db->insert($table$row);

         
$id $this->db->lastInsertId();

         return  
$id;

       }

  public function 
onerow($table,$uid,$id)//取得 单个数据行

       
{

        
$rows=$this->db->fetchRow("SELECT * FROM `$table` where $uid = :id" , array('id' =>$id));

        return 
$rows

       }

  public  function 
Del($table,$uid,$id// 删除特定行

        
{

         
$where $this->db->quoteInto("$uid = ?""$id");

         return 
$this->db->delete($table$where);



        }

   public  function 
getUpdate($table,$set,$uid,$id// 更新特定行

        
{

         
$where $this->db->quoteInto("$uid = ?"$id);

         return 
$this->db->update($table,$set,$where);



        }

    public  function 
count($table,$uid,$id,$where='T'// 特定行数据计算

        
{

         
$select=$this->db->select();

         
$select->from($table'COUNT(*)');

         
$select->where(" $uid= ? ",$id);

         if(
$where=='T')

         {

         
$select->where(" lend_estate= ? ",'1');

         }

         
$total=$this->db->fetchOne($select);  

         return 
$total;

        } 

   public  function 
post() //防止外部提交数据

        
{

         
$servername=$HTTP_SERVER_VARS['SERVER_NAME']; 

         
$sub_from=$HTTP_SERVER_VARS["HTTP_REFERER"]; 

         
$sub_len=strlen($servername); 

         
$checkfrom=substr($sub_from,7,$sub_len); 

         if(
$checkfrom!=$servername)

         { 

         echo 
"<script>alert(\"数据来源有误!请从本站提交!\");</script>";

         echo 
"<script>javascript:history.back()</script>";

         exit; 

         }

        }

    function 
getIP()//获得ip

        
{

            if(
getenv('HTTP_CLIENT_IP'))

            {

                
$ip=getenv('HTTP_CLIENT_IP');

            }

            else if(
getenv('HTTP_X_FORWARDED_FOR'))

            {

                
$ip=getenv('HTTP_X_FORWARDED_FOR');

            }

            else if(
getenv('REMOTE_ADDR'))

            {

                
$ip=getenv('REMOTE_ADDR');

            }

            else

            {

                
$ip=$_SERVER['REMOTE_ADDR'];

            }

            return 
$ip;

        }

 }

 
?>
复制代码

注意:上面的只是部分的。需要的操作可以自己添加....


II.在index.php里面注册对象

<?

set_include_path
('../library');//根目录下的库文件

include 'Zend.php';

include 
'./Application/Models/Datebase.php';  //数据库操作类

function __autoload($class)//自动加载类

{

  
Zend::loadClass($class);

}

$view = new Zend_View;

$view->setScriptPath('./Application/Views');  //放显示的文件的地方

Zend::register('view'$view);              //注册对象



$db = new Database();

Zend::register('db'$db);                                      // 注册数据库超作对象到对象仓库



//下面这些的作用是在子目录下。新手不管它,能用就行

$router = new Zend_Controller_RewriteRouter();

$controller Zend_Controller_Front::getInstance();

$controller->setRouter($router);



$controller->setControllerDirectory('./Application/controllers');//简单的说是放我们设计php控制文件的地方

$controller->dispatch();

?> 

复制代码
III.数据库操作.

在controllers下写一个Lovecontroller

<?php

//数据库操作

class LoveController extends Zend_Controller_Action 

{

      

    public function 
indexAction()

    {

      
$db=Zend::registry('db');//取出对象

      
$row = array 

      (

          
'love_name'        => '爱',

       );

      if(
$db->insert('love',$row))//写入数据库,love是表,$row是数组,返回插入的id号

        
{

        die(
'恭喜您,操作成功!!,按这里<a href=javascript:history.back() style="color:#FF0000;font-size:12px"> 返 回</a>');

        }

    }



   function 
__call($action,$args)//这个除了在IndexControlle不需要放。其他的每写个,都要放。。

    


     
$this->_redirect('../');

    }



}

?>

复制代码

    以上可以看出.这样操作起来,方便.只要传入,数据库的表,和写入的数组.就可以。
如要取得单个数据行只要$db->onerow($table,$uid,$id)//传入的表,where的条件
以后做项目的时候,只要这样做.省得每次都得写sql语句.
当然了。对于一些复杂性的超作,还得另外写的。对于一般性的语句可以这样写的。
具体的一些sql的详细操作,可以看下手册.www.phpeye.com

  一般的项目用DB类操作,已经够你用的.

下一章预告: Zend Framework 常见过滤数据的方法!

[ 本帖最后由 xgwork 于 2006-8-11 12:54 编辑 ]
MVMMALL首席CEO
www.mvmmall.com

新手学习 Zend Framework 框架连载(三)

第三章,Zend Framework 常见过滤数据的方法!

我们知道,在php中最常用的传值方式是:$_GET ,$_POST .
而好多初学者,经常直接$_GET['name'],$_POST['name']这样直接使用了。
而ZF提供的一些常见数据的过滤方法,使得您的数据写入数据库更加的安全.

1.$_GET传值过滤.

<?php

Zend
::loadClass('Zend_Filter_Input');

class 
UserController extends Zend_Controller_Action

{

public  function 
indexAction()

    {

     ...

    ... 

    }



public function 
__call($id,$arguments)

     {

    
$id=Zend_Filter::getDigits($id)

    }

}



?>

复制代码
getDigits是只取数字的,也就是过滤掉其他的不是数字的字符.

如你在url中打入http://localhost/User/33ete/

而这里你echo $id;的时候就会只取33这个数字了。.

2.$_POST方法

<?php

Zend
::loadClass('Zend_Filter_Input');

class 
UserController extends Zend_Controller_Action

{

public  function 
indexAction()

    {

     
$filterPost = new Zend_Filter_Input($_POST);

     
$id=$filterPost->getDigits('id');

     
//一样得到表单传过来的值'id'

    
}



public function 
__call($action,$arguments)

     {

    
$this->_redirect('../');

    }

}



?>

复制代码
其实一样的。只是换了下方式而已


下面是列出一些常用的过滤数据的方法.

<?php

$a 
Zend_Filter::getAlpha('love512you');

//得到的数据是:loveyou

$id=Zend_Filter::getDigits('512love');

//得到的数据是512

$a=Zend_Filter::getDir('C:/Zend')

//得到的数据是: c:\

$a=Zend_Filter::getAlnum('512love我爱你');

//得到数据 512love

$a=Zend_Filter::getInt('512love我爱你');

//得到数据512 相当于(int)



....还有很多。具体可以看下原代码或者手册.. 

?>

复制代码
还有更多过滤内容可以参照下http://framework.zend.com/manual/zh/zend.filter.input.html

我把ZF中的一些常见过滤的原代码也贴出来,使用方法同上面的一样.

<?php

/**

 * Zend Framework

 *

 * LICENSE

 *

 * This source file is subject to the new BSD license that is bundled

 * with this package in the file LICENSE.txt.

 * It is also available through the world-wide-web at this URL:

 * [url]http://framework.zend.com/license/new-bsd[/url]

 * If you did not receive a copy of the license and are unable to

 * obtain it through the world-wide-web, please send an email

 * to [email]license@zend.com[/email] so we can send you a copy immediately.

 *

 * @category   Zend

 * @package    Zend_Filter

 * @copyright  Copyright (c) 2006 Zend Technologies USA Inc. ([url]http://www.zend.com)[/url]

 * @license    [url]http://framework.zend.com/license/new-bsd[/url]     New BSD License

 */





/**

 * Zend_Filter_Exception

 */

require_once 'Zend/Filter/Exception.php';





/**

 * @category   Zend

 * @package    Zend_Filter

 * @copyright  Copyright (c) 2006 Zend Technologies USA Inc. ([url]http://www.zend.com)[/url]

 * @license    [url]http://framework.zend.com/license/new-bsd[/url]     New BSD License

 */

class Zend_Filter

{

    
/**

     * Options for isHostname() that specify which types of hostnames

     * to allow.

     *

     * HOST_ALLOW_DNS:   Allows Internet domain names (e.g.,

     *                   example.com).

     * HOST_ALLOW_IP:    Allows IP addresses.

     * HOST_ALLOW_LOCAL: Allows local network names (e.g., localhost,

     *                   [url]www.localdomain)[/url] and Internet domain names.

     * HOST_ALLOW_ALL:   Allows all of the above types of hostnames.

     */

    
const HOST_ALLOW_DNS   1;

    const 
HOST_ALLOW_IP    2;

    const 
HOST_ALLOW_LOCAL 4;

    const 
HOST_ALLOW_ALL   7;



    
/**

     * Returns only the alphabetic characters in value.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function getAlpha($value)

    {

        return 
preg_replace('/[^[:alpha:]]/'''$value);

    }



    
/**

     * Returns only the alphabetic characters and digits in value.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function getAlnum($value)

    {

        return 
preg_replace('/[^[:alnum:]]/'''$value);

    }



    
/**

     * Returns only the digits in value. This differs from getInt().

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function getDigits($value)

    {

        return 
preg_replace('/[^\d]/'''$value);

    }



    
/**

     * Returns dirname(value).

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function getDir($value)

    {

        return 
dirname($value);

    }



    
/**

     * Returns (int) value.

     *

     * @param mixed $value

     * @return int

     */

    
public static function getInt($value)

    {

        return (int) 
$value;

    }



    
/**

     * Returns realpath(value).

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function getPath($value)

    {

        return 
realpath($value);

    }



    
/**

     * Returns value if every character is alphabetic or a digit,

     * FALSE otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isAlnum($value)

    {

        return 
ctype_alnum($value);

    }



    
/**

     * Returns value if every character is alphabetic, FALSE

     * otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isAlpha($value)

    {

        return 
ctype_alpha($value);

    }



    
/**

     * Returns value if it is greater than or equal to $min and less

     * than or equal to $max, FALSE otherwise. If $inc is set to

     * FALSE, then the value must be strictly greater than $min and

     * strictly less than $max.

     *

     * @param mixed $key

     * @param mixed $min

     * @param mixed $max

     * @param boolean $inclusive

     * @return mixed

     */

    
public static function isBetween($value$min$max$inc TRUE)

    {

        if (
$value $min &&

            
$value $max) {

            return 
TRUE;

        }



        if (
$value >= $min &&

            
$value <= $max &&

            
$inc) {

            return 
TRUE;

        }



        return 
FALSE;

    }



    
/**

     * Returns value if it is a valid credit card number format. The

     * optional second argument allows developers to indicate the

     * type.

     *

     * @param mixed $value

     * @param mixed $type

     * @return mixed

     */

    
public static function isCcnum($value$type NULL)

    {

        
/**

         * @todo Type-specific checks

         */



        
$length strlen($value);



        if (
$length 13 || $length 19) {

            return 
FALSE;

        }



        
$sum 0;

        
$weight 2;



        for (
$i $length 2$i >= 0$i--) {

            
$digit $weight $value[$i];

            
$sum += floor($digit 10) + $digit 10;

            
$weight $weight 1;

        }



        
$mod = (10 $sum 10) % 10;



        return (
$mod == $value[$length 1]);

    }



    
/**

     * Returns $value if it is a valid date, FALSE otherwise. The

     * date is required to be in ISO 8601 format.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isDate($value)

    {

        list(
$year$month$day) = sscanf($value'%d-%d-%d');



        return 
checkdate($month$day$year);

    }



    
/**

     * Returns value if every character is a digit, FALSE otherwise.

     * This is just like isInt(), except there is no upper limit.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isDigits($value)

    {

        return 
ctype_digit($value);

    }



    
/**

     * Returns value if it is a valid email format, FALSE otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isEmail($value)

    {

        
/**

         * @todo RFC 2822 ([url]http://www.ietf.org/rfc/rfc2822.txt)[/url]

         */

    
}



    
/**

     * Returns value if it is a valid float value, FALSE otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isFloat($value)

    {

        
$locale localeconv();



        
$value str_replace($locale['decimal_point'], '.'$value);

        
$value str_replace($locale['thousands_sep'], ''$value);



        return (
strval(floatval($value)) == $value);

    }



    
/**

     * Returns value if it is greater than $min, FALSE otherwise.

     *

     * @param mixed $value

     * @param mixed $min

     * @return mixed

     */

    
public static function isGreaterThan($value$min)

    {

        return (
$value $min);

    }



    
/**

     * Returns value if it is a valid hexadecimal format, FALSE

     * otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isHex($value)

    {

        return 
ctype_xdigit($value);

    }



    
/**

     * Returns value if it is a valid hostname, FALSE otherwise.

     * Depending upon the value of $allow, Internet domain names, IP

     * addresses, and/or local network names are considered valid.

     * The default is HOST_ALLOW_ALL, which considers all of the

     * above to be valid.

     *

     * @param mixed $value

     * @param integer $allow bitfield for HOST_ALLOW_DNS, HOST_ALLOW_IP, HOST_ALLOW_LOCAL

     * @throws Zend_Filter_Exception

     * @return mixed

     */

    
public static function isHostname($value$allow self::HOST_ALLOW_ALL)

    {

        if (!
is_numeric($allow) || !is_int($allow)) {

            throw new 
Zend_Filter_Exception('Illegal value for $allow; expected an integer');

        }



        if (
$allow self::HOST_ALLOW_DNS || self::HOST_ALLOW_ALL $allow) {

            throw new 
Zend_Filter_Exception('Illegal value for $allow; expected integer between ' .

                                            
self::HOST_ALLOW_DNS ' and ' self::HOST_ALLOW_ALL);

        }



        
// determine whether the input is formed as an IP address

        
$status self::isIp($value);



        
// if the input looks like an IP address

        
if ($status) {

            
// if IP addresses are not allowed, then fail validation

            
if (($allow self::HOST_ALLOW_IP) == 0) {

                return 
FALSE;

            }



            
// IP passed validation

            
return TRUE;

        }



        
// check input against domain name schema

        
$status = @preg_match('/^(?:[^\W_](?:[^\W_]|-){0,61}[^\W_]\.)+[a-zA-Z]{2,6}\.?$/'$value);

        if (
$status === false) {

            throw new 
Zend_Filter_Exception('Internal error: DNS validation failed');

        }



        
// if the input passes as an Internet domain name, and domain names are allowed, then the hostname

        // passes validation

        
if ($status == && ($allow self::HOST_ALLOW_DNS) != 0) {

            return 
TRUE;

        }



        
// if local network names are not allowed, then fail validation

        
if (($allow self::HOST_ALLOW_LOCAL) == 0) {

            return 
FALSE;

        }



        
// check input against local network name schema; last chance to pass validation

        
$status = @preg_match('/^(?:[^\W_](?:[^\W_]|-){0,61}[^\W_]\.)*(?:[^\W_](?:[^\W_]|-){0,61}[^\W_])\.?$/',

                              
$value);

        if (
$status === FALSE) {

            throw new 
Zend_Filter_Exception('Internal error: local network name validation failed');

        }



        if (
$status == 0) {

            return 
FALSE;

        } else {

            return 
TRUE;

        }

    }



    
/**

     * Returns value if it is a valid integer value, FALSE otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isInt($value)

    {

        
$locale localeconv();



        
$value str_replace($locale['decimal_point'], '.'$value);

        
$value str_replace($locale['thousands_sep'], ''$value);



        return (
strval(intval($value)) == $value);

    }



    
/**

     * Returns value if it is a valid IP format, FALSE otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isIp($value)

    {

        return (bool) 
ip2long($value);

    }



    
/**

     * Returns value if it is less than $max, FALSE otherwise.

     *

     * @param mixed $value

     * @param mixed $max

     * @return mixed

     */

    
public static function isLessThan($value$max)

    {

        return (
$value $max);

    }



    
/**

     * Returns value if it is a valid format for a person's name,

     * FALSE otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isName($value)

    {

        return (bool) !
preg_match('/[^[:alpha:]\ \-\']/'$value);

    }



    
/**

     * Returns value if it is one of $allowed, FALSE otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isOneOf($value$allowed NULL)

    {

        
/**

         * @todo: Consider allowing a string for $allowed, where each

         * character in the string is an allowed character in the

         * value.

         */



        
return in_array($value$allowed);

    }



    
/**

     * Returns value if it is a valid phone number format, FALSE

     * otherwise. The optional second argument indicates the country.

     * This method requires that the value consist of only digits.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isPhone($value$country 'US')

    {

        if (!
ctype_digit($value)) {

            return 
FALSE;

        }



        switch (
$country)

        {

            case 
'US':

                if (
strlen($value) != 10) {

                    return 
FALSE;

                }



                
$areaCode substr($value03);



                
$areaCodes = array(201202203204205206207208,

                                   
209210212213214215216217,

                                   
218219224225226228229231,

                                   
234239240242246248250251,

                                   
252253254256260262264267,

                                   
268269270276281284289301,

                                   
302303304305306307308309,

                                   
310312313314315316317318,

                                   
319320321323325330334336,

                                   
337339340345347351352360,

                                   
361386401402403404405406,

                                   
407408409410412413414415,

                                   
416417418419423424425430,

                                   
432434435438440441443445,

                                   
450469470473475478479480,

                                   
484501502503504505506507,

                                   
508509510512513514515516,

                                   
517518519520530540541555,

                                   
559561562563564567570571,

                                   
573574580585586600601602,

                                   
603604605606607608609610,

                                   
612613614615616617618619,

                                   
620623626630631636641646,

                                   
647649650651660661662664,

                                   
670671678682684700701702,

                                   
703704705706707708709710,

                                   
712713714715716717718719,

                                   
720724727731732734740754,

                                   
757758760763765767769770,

                                   
772773774775778780781784,

                                   
785786787800801802803804,

                                   
805806807808809810812813,

                                   
814815816817818819822828,

                                   
829830831832833835843844,

                                   
845847848850855856857858,

                                   
859860863864865866867868,

                                   
869870876877878888900901,

                                   
902903904905906907908909,

                                   
910912913914915916917918,

                                   
919920925928931936937939,

                                   
940941947949951952954956,

                                   
959970971972973978979980,

                                   
985989);



                return 
in_array($areaCode$areaCodes);

                break;

            default:

                throw new 
Zend_Filter_Exception('isPhone() does not yet support this country.');

                return 
FALSE;

                break;

        }

    }



    
/**

     * Returns value if it matches $pattern, FALSE otherwise. Uses

     * preg_match() for the matching.

     *

     * @param mixed $value

     * @param mixed $pattern

     * @return mixed

     */

    
public static function isRegex($value$pattern NULL)

    {

        return (bool) 
preg_match($pattern$value);

    }



    public static function 
isUri($value)

    {

        
/**

         * @todo

         */

    
}



    
/**

     * Returns value if it is a valid US ZIP, FALSE otherwise.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function isZip($value)

    {

        return (bool) 
preg_match('/(^\d{5}$)|(^\d{5}-\d{4}$)/'$value);

    }



    
/**

     * Returns value with all tags removed.

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function noTags($value)

    {

        return 
strip_tags($value);

    }



    
/**

     * Returns basename(value).

     *

     * @param mixed $value

     * @return mixed

     */

    
public static function noPath($value)

    {

        return 
basename($value);

    }

}


复制代码
MVMMALL首席CEO
www.mvmmall.com
楼主能否先说说这个东东有什么用啊?
来自一个失真世界!
ZF 的使用还是太复杂了,如果大家不忙又有闲心,可以看看这个:

http://www.fleaphp.org/node/32
:D :D :D :D :D :D :D :D :D :P :P :P :P :P
我怎么连第一个例子都不行啊???郁闷啊!
不行啊
爽挺
谢谢分享
返回列表