Creating a simple view help? |
[eluser]Haley[/eluser]
Well I'm new to CI. I'm trying to figure out how to create a simple view. It's sooner or later going to turn into a login/registration system so I might need help with that later on. But I have the model, view, and controller all setup. Here is my controller located at applications/controllers: Code: <?php Then here is my model located at applications/models: Code: <?php Then last but not least, my view located at applications/views/forms/: Code: <div class="generalForm"> I want the ending URL to be http://www.mysitename.com/register I feel like I have everything setup correctly. I've been looking at other MVC projects and I really don't see a problem, but I am new so I might not be able to catch these things as easily.
[eluser]Jason Stanley[/eluser]
This looks like what you are after. http://ellislab.com/codeigniter/user-gui...uting.html You want to make site.com/user/register appear at site.com/register right?
[eluser]Haley[/eluser]
Ok so in my routes, I have: Code: $route['forms/(:any)'] = 'user/view/$1'; No the URL is site.com/forms/register, but I want it to appear like site.com/register I changed the controller to this: Code: <?php Still won't work.
[eluser]Jason Stanley[/eluser]
What doesn't work exactly? You get a 404 message? If it is 404 use the APPPATH constant your file_exists call. Code: if ( ! file_exists(APPPATH.'/views/forms/'.$page.'.php')) I don't know offhand is APPPATH has a trailing slash. You would need to check.
[eluser]Haley[/eluser]
Ok still getting the 404 page. Here is my updated controller which is located at application/controllers/user.php: Code: <?php My updates routes.php: Code: $route['user/(:any)'] = 'user/view/$1'; My view is located at application/views/user/register.php
[eluser]Jason Stanley[/eluser]
I assume you have printed this path to confirm it is correct? Code: echo APPPATH.'/views/user/'.$page.'.php'; I don't see anything that is really wrong with the code you have provided.
[eluser]Haley[/eluser]
It won't echo because all I'm getting is a 404 error. I completely changed my controller and routes now so they match more efficiently. Controller: Code: <?php Here is the routes: Code: $route['default_controller'] = 'pages/view';
[eluser]InsiteFX[/eluser]
You routes are wrong! Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones. Code: $route['user/(:any)'] = 'user/view/$1'; So you need to figure out the order of how your routes will be called...
[eluser]Haley[/eluser]
What do you mean? I don't understand higher routes.. I put the default controller on top and nothing changed.. I don't fully understand routes. I took a look at the URL provided my someone earlier and it's hard for me to comprehend being so new to the MVC world. |
Welcome Guest, Not a member yet? Register Sign In |