codeigniter-routing

Database driven routing in CodeIgniter 2.x

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-10 11:48:40
问题 I am creating a site that will have a lot of routes that will need to be added to the routes file (800+) - obviously I do not want to manually add these one by one into the routes config file. Can anyone suggest the best practice to have my routes loaded automatically from the database. Is there a suitable library/helper that will perform this task that works with version 2.x For instance.. $route['apple'] = 'brands/index'; $route['blackberry'] = 'brands/index'; $route['htc'] = 'brands/index'

How to load hook for particular controller

半世苍凉 提交于 2019-12-24 05:27:48
问题 I am new in codeigniter. I want to load hooks for admin panel controller. $hook['post_controller_constructor'][] = array( 'class' => 'AdminData', 'function' => 'myfunction', 'filename' => 'loginhelp.php', 'filepath' => 'hooks', 'params' => array() ); 回答1: The post_controller_constructor hook gets called after a $class is loaded. The class that gets loaded is based on the route parameters. system/core/Codeigniter.php /** *<code> * http://example.com/adminData/method *</code> * * $CI = new

CodeIgniter Paging 404

落花浮王杯 提交于 2019-12-23 03:32:00
问题 I've checked several threads on here regarding paging in CodeIgniter but I haven't found a solution to my problem. I have a controller class located at controllers/admin/index.php called 'Index' that contains the following code: class Index extends CI_Controller { public function __construct() { parent::__construct(); $this->load->helper("url"); $this->load->helper( 'events_helper' ); $this->load->helper( 'delegates_helper' ); $this->load->model( 'admin/event_model' ); $this->load->model(

Codeigniter routing and REST server

戏子无情 提交于 2019-12-21 05:15:12
问题 I'm trying to achieve the following URLs for my API (I'm using Codeigniter and Phil Sturgeon's REST server library): /players -> refers to index method in the players controller /players/rookies -> refers to rookies method in the players controller I don't want the URL to have a trailing "index" /players/index This is no problem at all when I define the routes like so: $route['players'] = 'players/index'; Everything works as expected. My problem is that I need additional URL segments like so:

get the requested controller in hook precontroller in codeigniter

杀马特。学长 韩版系。学妹 提交于 2019-12-13 01:34:01
问题 I'm trying to make a simple routing rule to allow only authenticated users to certain controllers. To achieve this, I would like to run precontroller hook and check if the user is logged in using ci session. However, I have to know which controller the user wants to access. How do I know this in a hook function? 回答1: $this->router->fetch_class(); Extend CI_Controller and this should work. 回答2: I dont think that hooks are best practice for what you want to achieve here you may try the

Customize dynamic URL.change ?id to name

左心房为你撑大大i 提交于 2019-12-12 04:55:55
问题 I'm using codeigniter for make dynamic website. In news page, I use url method like: http://test.com/test/test/news_details?id=27 how can i change my url to put news title within ?id=27 example: http://test.com/test/test/news_details/pass-this-url "pass-this-url" refer to id=27. Best Regards. 回答1: Use routes : http://www.codeigniter.com/user_guide/general/routing.html In your case it will be something like this : $route['pass-this-url'] = "test/test/news_details?id=27"; So http://www.example

CodeIgniter's form action is not working properly

大城市里の小女人 提交于 2019-12-11 13:09:57
问题 I have failed many times to figure out why the action attribute of my form is malfunctioning when I click the submit button. All I wanted to do is to pass the form data to the controller. But what's happening is that the browser is just redirecting me to another page (on localhost, even the URI is correctly supplied.) <form name = "employee" method = "post" action = "<?php echo base_url() .'employee/add_employee'; ?>"> First Name: <input type = "text" name = "F_Name"> Middle Name: <input type

Custom URI routing by query string with CodeIgniter?

坚强是说给别人听的谎言 提交于 2019-12-11 01:54:20
问题 I am looking to make a custom route using the CodeIgniter framework. I am trying to make the URL like so: http://localhost/accounts/Auth.dll?signin So far I have tried adding the following to my routes.php config file: $route['accounts/Auth.dll?signin'] = "accounts/signin"; but as you would guess, it doesn't work. I have also tried escaping the characters like this: $route['accounts/Auth\.dll\?signin'] = "accounts/signin"; and that doesn't work either. I've also tried including the leading

How to organize country/state/city browsing in MVC

风格不统一 提交于 2019-12-09 23:44:58
问题 I'm creating an ajax-based website that includes a country/state/city browsing interface. For SEO purposes, I want to include the name of the country/state/city in the URL. For example, the url may include additional variables, and would be something like: http://www.website.com/browse#!USA/NY/Albany http://www.website.com/browse#!USA/NY/Albany?Category=sports I need to fit this functionality into an MVC framework (specifically CodeIgniter) through AJAX. I'm not sure how to organize the major

Codeigniter: I would like create user URL's for my users when they create a username

杀马特。学长 韩版系。学妹 提交于 2019-12-08 11:56:35
问题 I wold like to create this kind of URL for my users when they register a username mysite.com/username I've search many posts on this site and I see people doing it like this mysite.com/user/username I would like to get rid of the user and just have it go directly to mysite.com/username What would be the best way to this? 回答1: I am not familiar with CodeIgniter but here is a general answer for why people don't use mysite.com/username: mysite.com/user/username is a good solution because usually