Load view from Controller issue |
Hi there,
I am new to CodeIgniter framework and needs someone help, please. I have an issue to redirect user back to Contact Us form after its submission. My default controller is defined as below. PHP Code: <?php Now my view pages are in the sub-directory called pages, for example /views/pages/contact-us.php. So when I access this page like https://www.mysite.com/contact-us then it works fine and loads the contact us form as expected. Look at my .htaccess file that removes index.php from the URL. Code: RewriteEngine on And also look at my routes.php file. PHP Code: <?php Now after user submits the contact us form it goes to controller called SendEmail.php and then I want user to come back to Contact Us form with message either successful or failed. I am getting an email to my gmail account but when it comes to loading VIEW it does not work. Look at code of SendEmail.php PHP Code: <?php I am getting below error. As I said above I manage to get email to my gmail account but loading a view does not work. An Error Was Encountered Unable to load the requested file: contact-us.php Can you please help me? Thanks - Hitesh
(06-11-2018, 01:34 PM)hiteshpatel1979 Wrote: Yes Dave...its in the /application/views/pages folder. If the path to the file is /application/views/pages/contact-us.php Then this line PHP Code: $this->load->view('contact-us', $data); should be PHP Code: $this->load->view('pages/contact-us', $data);
(06-11-2018, 03:20 PM)dave friend Wrote:Thanks Dave.(06-11-2018, 01:34 PM)hiteshpatel1979 Wrote: Yes Dave...its in the /application/views/pages folder. I will try today and let you know how it goes.
Your controller is pages/view/$1 because if you look you have no default index method.
So you need to access it like this. PHP Code: // wont work If that wont work you can try this method below. PHP Code: // ----------------------------------------------------------------------- Place it into one of your CodeIgniter helper files. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Hi Dave,
In fact I had to put as below in the controller while redirecting back to contact us form. PHP Code: /*1*/ $this->load->view('templates/header'); If I only add line#2 then contact us form does not include header and footer views in the final rendering of the view. So I had to do it that way. I find it annoying. Is there any better way so I will not have to include header and footer templates while loading view from the controller? With above code I manage to load contact-us view but then in the address bar it does not show contact-us (http://localhost:8080/42patidarsamaj-staging/contact-us) rather it shows controller name (http://localhost:8080/42patidarsamaj-staging/sendemail). Please advise. Thanks.
Hi there,
Thanks for taking off time to post your reply. I tried as you said but it did not work. PHP Code: $this->load->view('pages/view/contact-us', $data); At the moment in /application/helpers folder there is not any file. Do you mean I need to create a new PHP file and place the redirect code there? If yes, then will be a PHP class file or regular PHP template? Kindly advise. PHP Code: // Try changing this PHP Code: $route['translate_uri_dashes'] = FALSE; What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Hi there,
After I made a change in routes.php as you suggested now my hyperlinks/direct URLs for all the views stopped working. For example: Code: http://localhost:8080/42patidarsamaj-staging/directory Sorry but now I am putting back what was before....I did not think it was this tough to load VIEW from Controller. Please help if you can. Thanks. |
Welcome Guest, Not a member yet? Register Sign In |