小编SPi*_*Pie的帖子

CakePHP自定义验证规则仅在创建时检查唯一字段组合

我有一个用户模型的数据库.这些用户的名字和生日应该是唯一的.所以我写了一个名为checkUnique的自定义验证函数

public function checkUnique($check){
        $condition = array(
            "User.name" => $this->data["User"]["name"],
            "User.lastname" => $this->data["User"]["lastname"],
            "User.birthday" => $this->data["User"]["birthday"]
        );

        $result = $this->find("count", array("conditions" => $condition));

        return ($result == 0);
}
Run Code Online (Sandbox Code Playgroud)

模型中的验证规则:

"name" => array(
       "checkUnique" => array(
            "rule" => array("checkUnique"),
            "message" => "This User already exists.",
            "on" => "create"
       ),
)
Run Code Online (Sandbox Code Playgroud)

我有两个问题.第一种:此验证规则也会在更新操作时触发,实现为

public function edit($id = null) {
        if (!$this->User->exists($id)) {
            throw new NotFoundException(__('Invalid User'));
        }
        if ($this->request->is(array('post', 'put'))) {
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('Update done.'));
                return $this->redirect(array('action' => 'index'));
            } else { …
Run Code Online (Sandbox Code Playgroud)

validation cakephp unique updatemodel

3
推荐指数
1
解决办法
6681
查看次数

Typo3将所有子页面的内容列为父页面的内容

正如标题所说,我需要在其自己的内容之后列出父页面上所有子页面的内容.或者我真正需要的是,一页内容和一个链接到内容的不同标题的菜单.例如athe parent-page with content:

**Parent Head**
parent text
*first subhead*
first subtext
*second subhead*
second subtext
Run Code Online (Sandbox Code Playgroud)

菜单应如下所示:

- 第一个小标题

- 第二个子标题

我认为如果父页面"收集"子页面的内容会更容易.另一个解决方案是,子页面将链接到外部URL,以及父页面的不同内容的特定c- ID.但我认为这对网站所有者来说并不容易,他不知道在网页源代码中哪里可以找到合适的c -ID.那你怎么做到的?或者我如何通过子页面内容实现这一点?

编辑:现在有一个解决方案.只需要修复,子菜单将在没有子页面的情况下显示.这是代码:

temp.contentnav = CONTENT
temp.contentnav {
  table = tt_content
  select {
    pidInList = 7
    orderBy = sorting
    where = colPos=0
    languageField=sys_language_uid

  }
  renderObj = TEXT
  renderObj {
    field = header
    wrap= <li>|</li>

    typolink.parameter.field=pid
    typolink.parameter.dataWrap=|#{field:uid}
    typolink.ATagParams = class="linkClass"
    if.isTrue.field=header
  }

  wrap = <ul id="submenuClass"> | </ul>
}

page.10.marks.MENU.2.NO.after.cObject < temp.contentnav
Run Code Online (Sandbox Code Playgroud)

menu typo3 parent-child typoscript

2
推荐指数
1
解决办法
3681
查看次数