Issue with View controller method |
Hi,
Having a strange issue that i can't seem to figure out or find the answer for When i use "public function view" in my controller to display my page i get a 404 error, when i use "public function index" the page displays no problem. However i want to use the "view to have a theme" This happens when i just try to browse to "index.php/controllername with public function view set, if I browse to "index.php/controller/view/page" i can see the page ok I have tried with no other routes except the default and adding in a route however it doesn't seem to make a difference, any thoughts? Using the latest version of codeigniter try creating another controller and view and they all seem to do the same thing.
If you don't include a method name after the controller name in your URL, the method name defaults to index. You should be able to setup a route to override this, but it's a fundamental feature of CodeIgniter's routing.
You might want to read through the docs: http://www.codeigniter.com/user_guide/ge...llers.html
Thanks mwhitney, but i believe I've done that correctly, however the "view" method doesn't display the page i want
eg. my controller looks like this class Ace extends CI_Controller { public function view($page = 'home' ) { if ( ! file_exists(APPPATH.'/views/ace/'.$page.'.php')) { // Whoops, we don't have a page for that! show_404(); } $data['title'] = 'Your title'; $this->load->view('acetemplate/header', $data); $this->load->view('acetemplate/nav', $data); $this->load->view('ace/'.$page, $data); $this->load->view('acetemplate/footer', $data); With no specific routes or with a specific route (eg.$route['(:any)'] = 'ace/view/$1' browsing the http://127.0.0.1/index.php/ace/ with the view method doesn't work
don't use "view" as a method name, because I think there will be a conflict with the core view() method.
Website: http://avenir.ro
CI's view() method is in the loader ($this->load->view()), so there shouldn't be a conflict. I have a controller which uses a view() method without any issues.
However, I'm not sure whether that route ($route['(:any)'] = 'ace/view/$1') would work. You might have better luck setting $route['default_controller'] = 'ace'; and using a _remap() method.
still no luck,
I'm not doing something crazy here right? The above controller is basically identical to the codeigniter tutorial and I have another instance running on a different server that use the same controller and "public function view" and it works fine So stumped as the why "public function view" doesn't work
I don't understand. You want that, when accessing 'index.php/controllername', your site to display the view() method? If this is the case, you can do that by creating a "remap":
PHP Code: public function _remap($method, $params = array()) See more here: http://www.codeigniter.com/user_guide/ge...s.html#id7 Website: http://avenir.ro
Just trying to follow what I've used before and what is in the tutorial, thought it might be something with my configuration at is easily fixed, even coping the tutorial doesn't work.
http://www.codeigniter.com/user_guide/tu...pages.html The line of code i seem to have issues with is just "public function view" with this in my controller browsing to example.com/index.php/controller - I get a 404 error However with "public function index" no change to any other code example.com/index.php/controller - work fine If the case is the "public function view" no longer exists for some reason than i can move on.
What you may have missed from that tutorial is the fact that you are to set the default controller to be "pages/view". you can set that inside the application/config/routes.php
$route['default_controller'] = 'pages/view'; Website: http://avenir.ro
(06-01-2015, 07:17 AM)mwhitney Wrote: If you don't include a method name after the controller name in your URL, the method name defaults to index. You should be able to setup a route to override this, but it's a fundamental feature of CodeIgniter's routing. He's right unless you can internal routing using "_remap" method.
NexoPOS 2.6.2 available on CodeCanyon.
|
Welcome Guest, Not a member yet? Register Sign In |