我正在尝试将index.php文件重定向到root /,我已经搜索过并发现了几个类似于以下代码的代码片段:
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.domain.com/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
但是,这不适用于子域,例如:
有谁知道如何调整上面的htaccess所以它会考虑子域并将它们重定向到适当的位置?
例如,如果用户访问http://subdomain.domain.com/index.php,他们将访问http://subdomain.domain.com/
奖励积分:
是否有可以将此规则应用于所有文件夹的htaccess?
所以对于任何带有index.php的文件夹,它们只会重定向到它的根目录,例如http://subdomain.domain.com/folder1/folder2/index.php会自动转到http://subdomain.domain.com/folder1 /文件夹2 /
我正在尝试创建一个用户可以注册并创建配置文件的站点,因此我在数据库中使用两个MySQL表,例如users和user_profile.
该users表有一个auto increment primary key叫user_id.
该user_profile表具有相同的primary key名称,user_id但它不是auto increment.
*请参阅说明为什么我有多个表格.
当用户注册时,来自注册表单的数据被插入到用户中,然后last_insert_id()输入到表的user_id字段中user_profile.我使用事务来确保始终发生这种情况.
我的问题是,这是不好的做法吗?
即使一个用户只能拥有一个配置文件,我是否可以unique auto increment primary key使用该user_profile表?
也许创建像这样的数据库有其他缺点?
我很感激,如果有人能解释为什么这是一个问题,或者它是好的,我想确保我的数据库尽可能高效.
注意:我正在为user和user_profile使用单独的表,因为user_profile包含可能为null的字段,并且由于数据显示在公共配置文件中,因此将比用户表请求更多.
也许这也是不好的做法,他们应该被归为一张桌子?
我目前正在尝试将cakephp登录名从使用用户名字段更改为使用电子邮件字段.
使用用户名字段时,登录工作正常,这是使用用户名登录的代码:
login.ctp
<?php
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end(__('Login'));
?>
Run Code Online (Sandbox Code Playgroud)
UsersController.php
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add', 'login'); // Letting users register themselves
$this->Auth->fields = array('username' => 'username', 'password' => 'password');
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->Session->setFlash(__('worked'));
} else {
debug($this->data);
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
Run Code Online (Sandbox Code Playgroud)
AppController的
public $components = array('Session', 'Auth');
Run Code Online (Sandbox Code Playgroud)
所以一切正常,我可以登录测试细节.
因此,要将此更改为使用电子邮件,我所做的就是:
将login.ctp中的输入从用户名更改为电子邮件
echo $this->Form->input('email');
Run Code Online (Sandbox Code Playgroud)将userscontroller中的fields数组从username更改为email
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
Run Code Online (Sandbox Code Playgroud)将数据库字段从用户名更改为电子邮件 …
我目前正在尝试通过FormAuthenticate类在CakepPHP(在cake\lib\Cake\Controller\Component\Auth文件夹中)扩展BaseAuthenticate类,我在扩展构造函数时遇到了麻烦.
我正在尝试扩展构造函数以声明一个可以在整个类中使用的新对象.
//BaseAuthenticate.php
public function __construct(ComponentCollection $collection, $settings) {
$this->_Collection = $collection;
$this->settings = Hash::merge($this->settings, $settings);
}
//ExtendedFormAuthenticate.php
public function __construct()
{
parent::__construct(ComponentCollection $collection, $settings);
}
Run Code Online (Sandbox Code Playgroud)
如果我在ExtendedFormAuthenticate.php中使用上面的__construct,我会收到错误消息 syntax error, unexpected T_VARIABLE
public function __construct()
{
parent::__construct($collection, $settings);
}
Run Code Online (Sandbox Code Playgroud)
如果我在ExtendedFormAuthenticate.php中使用上面的__construct,我会收到undefined variable错误消息,因为我没有填充这些变量,但我不知道填充它们的内容.
有谁知道我如何成功扩展BaseAuthenticate.php构造函数?或者,有没有人知道如何声明一个对象在一个类中使用而不在__construct函数中?