我正在使用 codeigniter 2.1.0 和 mysql 数据库。在我的管理面板中,我有一个页面,我想在其中向所有用户显示分页 View 。但它不工作。在尝试了很多东西之后
这是我的更新代码
Controller :
function accounts() // controller to view all users
{
$this -> load -> library('pagination');
$config['base_url'] = site_url('admin/home/accounts/');
$config['total_rows'] = $this->db->get('user')->num_rows();
$config['per_page'] = 2;
$config['num_links'] = 2;
$config['full_tag_open'] = '<p id="pagination">';
$config['full_tag_close'] = '</p>';
$offset = $this->uri->segment(4,0);
$this->pagination->initialize($config);
$this->load->model('admin_model');
$data['user_data']=$this->admin_model->all_user($config['per_page'],$offset);
$data['links']=$this -> pagination -> create_links();
$data['main_content']='admin/accounts';
$this->load->view('includes/admin/admin_template',$data);
}
查看:
<?php foreach ($user_data as $data) {?>
<?php echo 'Name:' . ' ' ?>
<?php echo ($data['name']).'<br/>'; ?>
<?php echo 'E-mail:' . ' ' ?>
<?php echo ($data['email']).'<br/>'; ?>
<br />
<?php } ?>
<?php echo $links;?>
型号:
function all_user($per_page,$offset) //shows all uer info
{
$query = $this->db->get('user', $per_page, $offset);
$row=$query->result_array();
return $row;
}
这是路线:
$route['default_controller'] = "site";
$route['404_override'] = '';
$route['admin']='admin/admin';
我已经使用 .htaccess mod_rewrite 删除了我的 index.php 并使用 $config['url_suffix']='.html' 添加了 .html 的后缀,这使得 url 看起来像这样
'http://localhost/project/admin/home/accounts.html'
而不是 'http://localhost/project/index.php/admin/home/accounts'
但如果我删除 config.php 中的 url_suffix
*/
$config['url_suffix'] = '';
/*
分页效果很好。但我想使用 url_suffix
*/
$config['url_suffix'] = '.html';
/*
但如果我这样做,分页不起作用,并显示 404 页面未找到错误。我该如何解决这个问题?
最佳答案
我在您的代码中发现了很多问题。但是第一件事第一。
放
$this->uri->segment(4)
在您的查询中的偏移量。
更新:如果您还没有完成 mod_rewrite,请将 'index.php' 添加到您的 $config['base_url']。
例如
$config['base_url']=base_url().'index.php/admin/....';
在上面的代码中添加你的路径。
关于php - 分页在带有 url_suffix 的 codeigniter 2.1.0 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9066222/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
从给定URL下载文件并立即将其上传到AmazonS3的更直接的方法是什么(+将有关文件的一些信息保存到数据库中,例如名称、大小等)?现在,我既不使用Paperclip,也不使用Carrierwave。谢谢 最佳答案 简单明了:require'open-uri'require's3'amazon=S3::Service.new(access_key_id:'KEY',secret_access_key:'KEY')bucket=amazon.buckets.find('image_storage')url='http://www.ex
我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
使用Ruby1.9.2运行IDE提示说需要gemruby-debug-base19x并提供安装它。但是,在尝试安装它时会显示消息Failedtoinstallgems.Followinggemswerenotinstalled:C:/ProgramFiles(x86)/JetBrains/RubyMine3.2.4/rb/gems/ruby-debug-base19x-0.11.30.pre2.gem:Errorinstallingruby-debug-base19x-0.11.30.pre2.gem:The'linecache19'nativegemrequiresinstall