zoukankan      html  css  js  c++  java
  • symfony学习笔记

    1.symfony如何添加自己定义的错误验证信息。
    http://www.symfony-project.org/forms/1_2/en/02-Form-Validation
    $nameValidator=new sfValidatorDoctrineChoice(array('model' => 'User', 'column' =>'name'),array( 'invalid' =>'Name not exist' ));
    编辑默认的提示,如果默认提示为invalid 那么添加array('invalid'=>'your invalid message') 再比如Required array('Required'=>"This filed is required")
    添加自定义的时候需要声明一个数据array,保证有invalid这个键值。框架就是框架不明白就不知道在哪加,我找了好半天才找到添加方法。

    2. 有时候项目文件需要打包压缩和解压缩 记录一下
    把整个文件夹 folderTared 的内容打包成一个gz文件:
    tar czvf folderTared.tar.gz /theDir/folderTared
    把压缩的gz文件恢复到指定目录下:
    tar xzvf folderTared.tar.gz /theDir/

    3.在生成了默认的CRUD操作之后,如何修改默认的模板。
      因为symfony默认生成了CRUD后,比如在new操作的时候,就是默认的模板,如何修改这个模板呢?如果有一个表:user。字段name,password .

     首先看看 baseUserForm里的Function SetUp里
     $this->setWidgets(array(
          'name'       => new sfWidgetFormInput(),
          'password'       => new sfWidgetFormInput()
        ));
       $this->widgetSchema->setNameFormat('user[%s]');
     生成两个文本狂,文本框的名字为这样的样式。
    <input type="text" name="user[]" />
    <input type="text" name="user[password]" />
    所以只要自己的form是这样的格式,就可以了。
    至于如何绑定,就是symfony帮我们做的了。
    知道了数据格式是这样的,如果我们要加什么样式,那么就直接编辑html了。只要对应的input保持一样的就ok.

    4.Symonfy1.2版本文件上传。
      今天学习文件上传,找了好多例子,很多都是1.0的,可是symfony1.0的API在Symonfy1.2里面通不过,根本就没提供手动上传文件的方法,还是得借助PHP本身
    文件上传的方法。
     
    Code
     
    5. Symfony分页。
       symfony分页显得尤其简单,直接上代码。
     
       
    //excute里的代码
      public function executeIndex(sfWebRequest $request)
      {
        
    //对应的是User模块,也就是对应的是User表的记录。
        //????如果我这个分页要实现多个表单记录呢?有时间再学习下。

        $this->pager = new sfDoctrinePager('User',5);
        
    $this->pager->getQuery();
        
    $this->pager->setPage($this->getRequestParameter('page',1));
        
    $this->pager->init();      
      }

    //indexSuccess里的代码
    <table>
      
    <tbody>
          
    <?php foreach ($pager->getResults()as $user): ?>
         
    <tr>
          
    <td><a href="<?php echo url_for('user/show?id='.$user->getId()) ?>"><?php echo $user->getId() ?></a></td>
          
    <td><?php echo $user->getName() ?></td>
          
    <td><?php echo $user->getPassword() ?></td>
          
    <td><?php echo $user->getCreatedAt() ?></td>
          
    <td><?php echo $user->getUpdatedAt() ?></td>
        
    </tr>
        
    <?php endforeach?>
      
        
    <?php if ($pager->haveToPaginate()): ?>
        
    <tr>
        
    <td colspan="5">
         
    <?php echo link_to('First', 'user/index?page='.$pager->getFirstPage()) ?>
        
    <?php echo link_to('Pre', 'user/index?page='.$pager->getPreviousPage()) ?>
        
    <?php $links = $pager->getLinks(); foreach ($links as $page): ?>
          
    <?php echo ($page == $pager->getPage()) ? $page : link_to($page, 'user/index?page='.$page?>
          
    <?php if ($page != $pager->getCurrentMaxLink()): ?> - <?php endif ?>
        
    <?php endforeach ?>
        
    <?php echo link_to('Next', 'user/index?page='.$pager->getNextPage()) ?>
        
    <?php echo link_to('Last', 'user/index?page='.$pager->getLastPage()) ?>
      
    <?php endif ?>
        
    </td>
        
    </tr>
      
    </tbody>
    Title在这里输入文本...

    </table>
  • 相关阅读:
    rc-local.service服务启动失败,导致rc.local中的开机启动服务不能启动
    bacula快速部署
    配置github SSH公钥登录
    快速安装zabbix
    编译安装git
    linux系统日志中出现大量systemd Starting Session ### of user root 解决
    根据屏幕高度自适应元素高度
    git+github上传与管理
    ajax简单应用
    自己常用的webstrom快捷键
  • 原文地址:https://www.cnblogs.com/likwo/p/1563389.html
Copyright © 2011-2022 走看看