标签 CodeIgniter 下的文章

利用.htaccess去除CodeIgniter的index.php

个人用的方法,感觉还不错:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /poster
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

如果在根目录,那么把/poster改成/就行了,如果在http://xxx.xxx/aaa 则把/poster改成/aaa

注:
第1行 第9行 判断rewrite模块是否加载,没有加载的话这几行代码不起作用
第2行设置Linux软连接
以上几行去掉无妨。

CodeIgniter 分页类的一点总结

这里我们以get与分页的结合为例,因为这点当时我纠结了很久,当然是在M-SHOW时候纠结完的,这次拿来主义了一次,记录一下。

        $this->load->library('pagination');
        $id = $this->input->get('id');

        /**
         *  pagination
         */
        $config['base_url'] = base_url().'poster_admin/works/search';
        $config['per_page'] = 5;
        $config['num_links'] = 7;
        $config['uri_segment'] = '4';
        $config['use_page_numbers'] = TRUE;
        $config['full_tag_open'] = '<ul class="pagination">';
        $config['full_tag_close'] = '</ul>';
        $config['cur_tag_open'] = '<li class="active"><a href="#">';
        $config['cur_tag_close'] = '</a></li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['prev_tag_open'] = '<li>';
        $config['prev_tag_close'] = '</li>';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['first_link'] = FALSE;
        $config['last_link'] = FALSE;
        $config['total_rows'] = $this->works_model->searchNum($id);

        $config['suffix'] = '?id='.$this->input->get('id');
        $config['first_url'] = base_url().'poster_admin/works/search'.'?id='.$this->input->get('id');

        $this->pagination->initialize($config);

- 阅读剩余部分 -

PHP 简单写个install.php

这次顺便做了一个install.php才发现难度其实并不大,还是文件写入操作而已,安装其实主要操作的还是数据库里的内容,先来看看文件里怎么写:(还是用的Codeigiter,对于使用其他框架或者手写而言,仅思路可参考,用了挺多CI自带的helper或者是library的)

                $content = "<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\n";
                $content .= '$active_group'. "= 'default';\n";
                $content .= '$active_record'." = TRUE;\n";
                $content .= '$db'."['default']['hostname'] = '".$this->input->post('hostname')."';\n";
                $content .= '$db'."['default']['username'] = '".$this->input->post('rootname')."';\n";
                $content .= '$db'."['default']['password'] = '".$this->input->post('pass')."';\n";
                $content .= '$db'."['default']['database'] = '".$this->input->post('book')."';\n";
                $content .= '$db'."['default']['dbdriver'] = 'mysql';\n";
                $content .= '$db'."['default']['dbprefix'] = '';\n";
                $content .= '$db'."['default']['pconnect'] = TRUE;\n";
                $content .= '$db'."['default']['db_debug'] = TRUE;\n";
                $content .= '$db'."['default']['cache_on'] = FALSE;\n";
                $content .= '$db'."['default']['cachedir'] = '';\n";
                $content .= '$db'."['default']['char_set'] = 'utf8';\n";
                $content .= '$db'."['default']['dbcollat'] = 'utf8_general_ci';\n";
                $content .= '$db'."['default']['swap_pre'] = '';\n";
                $content .= '$db'."['default']['autoinit'] = TRUE;\n";
                $content .= '$db'."['default']['stricton'] = FALSE;";

在文件里用\n来换行,因为里面包括了PHP的代码,这导致了我们只能用双引号避免冲突(否则的话就得用\了,感觉工作量更大),针对$db,直接显示必须要用单引号,于是就出现了这个。

- 阅读剩余部分 -