Welcome Guest, Not a member yet? Register   Sign In
calling functions in controllers without same name as view with form_open
#1

[eluser]mayberightguy[/eluser]
I have a view (formView.php) that displays a form that is processed by a function (formProcessor()) in a controller (viewController.php). Shouldn't my form_open point to viewController/formProcessor? I get my 404 page when I submit (no pun intended). Is this happening because config/routes defaults to a view URL (and there is no view with the same name as the controller)? If so, can I not call the function with form_open?
#2

[eluser]SamoualSys[/eluser]
i will try to help in that
in your view
Code:
<?php echo form_open('your_controller_file_name'); ?>
and in the controller
you can put the code in the index example
Code:
class Controller_name extends CI_Controller {

function index()
{
  
  
  $this->load->model('your_model');
  $this->xtransfer->insert_trans() ;
  $this->load->view('your_View',$data);



}
I hope that help you
#3

[eluser]mayberightguy[/eluser]
SamoualSys: You seem to be telling me to try to use index() instead of my own function. That does not solve the problem but thanks for trying, anyway.
#4

[eluser]SamoualSys[/eluser]
can you put your code so i can try to help more
#5

[eluser]Samus[/eluser]
[quote author="mayberightguy" date="1333632531"]I have a view (formView.php) that displays a form that is processed by a function (formProcessor()) in a controller (viewController.php). Shouldn't my form_open point to viewController/formProcessor? I get my 404 page when I submit (no pun intended). Is this happening because config/routes defaults to a view URL (and there is no view with the same name as the controller)? If so, can I not call the function with form_open?[/quote]

If you're getting a 404 error, it's most likely you didn't set the form action properly. Maybe a typo or some sort.

Also not a good idea to camelCase your controller names / method names.

viewController is not the same as viewcontroller.

Post your code for more help though
#6

[eluser]mayberightguy[/eluser]
I have these lines in config/routes.php:
Code:
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';

In a controller called myController.php I have:
Code:
<?php

class myController extends Controller {

    function myFormFunction() {
        $test = $this -> _myFormFunction();
        }

        private function _myFormFunction() {
            $this->load->library('form_validation');
            if ($this->form_validation->run() == FALSE) {
                $this->load->view('myView');
            }
            else {
                $user = $this->input->post('myView');
                $this->load->view('myView', "");
            }
        }
    }
?>

And in a view called myView.php I have:
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
    &lt;head&gt;
        &lt;meta charset="utf-8" /&gt;
        &lt;title&gt;&lt;/title>
    &lt;/head&gt;
    &lt;body&gt;
    &lt;?php
        //$this->load->helper('form');
    
        echo form_open('myController/myFormFunction');
        echo form_input('username', 'johndoe');
        echo form_submit('userSubmit', 'Go');
        echo form_close();
    ?&gt;
        Some text...
    &lt;/body&gt;
&lt;/html&gt;

I have a bigger problem now, though. I was using WebMatrix as my IDE and I installed a trial of PhpED. Now when I test my php files, only the html before the php is rendered.
#7

[eluser]mayberightguy[/eluser]
Fixed the php processing problem...
#8

[eluser]Denzel[/eluser]
The reason you are seeing a 404 is because of your routes. Specifically:
Code:
$route['(:any)'] = 'pages/view/$1';
This will match anything, literally, anything! When you request yoursite.com/index.php/myController/myFunction it will be transformed to yoursite.com/index.php/pages/view/myController/myFunction because that route matches.

In plain english you are saying 'take any URI request that doesn't satisfy my default controller and prefix it with pages/view/'. That's bad in your case.

Change that route to something more sensible and your problem should be fixed.
#9

[eluser]mayberightguy[/eluser]
Thank you, Denzel. I'm just starting out and trying to wrap my head around CI. Tough to pin down problem causes.
#10

[eluser]Denzel[/eluser]
[quote author="mayberightguy" date="1333673274"]Thank you, Denzel. I'm just starting out and trying to wrap my head around CI. Tough to pin down problem causes.[/quote]
No problem. Trust me I know exactly how you feel. :-) After a while you will get the hang of it. Not to mention, you took a step in the right direction by coming to the forum for help.

Good luck with the rest of your endeavors.




Theme © iAndrew 2016 - Forum software by © MyBB