在cakephp中使route参数可选

时间:2016-08-23 10:14:43

标签: cakephp cakephp-2.0 cakephp-routing

我在CakePHP中创建了以下路线:

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.slf4j.Logger;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public void legacyEncryption(String salt, String clearPassword) throws UnsupportedEncodingException, NoSuchAlgorithmException {
  // Get digester instance for algorithm "SHA-512" using BounceCastle
  MessageDigest digester = MessageDigest.getInstance("SHA-512", new BouncyCastleProvider());

  // Create salted password string
  String mergedPasswordAndSalt = clearPassword + "{" + salt + "}";

  // First time hash the input string by using UTF-8 encoded bytes.
  byte[] hash = digester.digest(mergedPasswordAndSalt.getBytes("UTF-8"));

  // Loop 5k times
  for (int i = 0; i < 5000; i++) {
    // Concatenate the hash bytes with the clearPassword bytes and rehash
    hash = digester.digest(ArrayUtils.addAll(hash, mergedPasswordAndSalt.getBytes("UTF-8")));
  }

  // Log the resulting hash as base64 String
  logger.info("Legace password digest: salt=" + salt + " hash=" + Base64.getEncoder().encodeToString(hash));
}

在这条路线中,我想让部分Router::connect( '/design-idea-projects/:filtertype--:id', array('controller' => 'ourwork', 'action' => 'designideaprojects'), array( 'pass' => array('filtertype', 'id'), 'id' => '[0-9]+' ) ); 成为可选的。这该怎么做?我在/:filtertype--:id之后没有提供任何内容,它显示缺少控制器错误。我真的不知道。

感谢。

1 个答案:

答案 0 :(得分:0)

你可以试试这个,希望它能起作用

Router::connect(
            '/design-idea-projects/*',
            array('controller' => 'ourwork', 'action' => 'designideaprojects'),
            array(
                'pass' => array('filtertype', '[0-9]+')
            )
        );