load different views in one view |
[eluser]ramonskie[/eluser]
okay i'm still a beginner.. but we all need to start somewhere ![]() i have created different view files that have a div with forms like signup, login, etc etc now i have a main view that have on the left side a login view to begin with and on the right side it has a small list that we just bought (its a shopping cart kind of thing) now if i don't have a login yet i want to create a account this form is located in a different viewfile so when i press the button "register user" i want to show the registration form but i want to keep the list of course so what i want to achieve is to only change the login_form to the registration_form i hope you understand my question its a bit complicated to explain with my crappy english
[eluser]jdav3579[/eluser]
Hi With views there is an optional third parameter. $this->load->view(filename, data, [return]). I would perhaps put a variable in your main file called $sidepanel for example. I would then load the file which has the most appropriate view in (ie login or create) into a variable called $data['sidepanel] in your controller by setting the third parameter as true. Then simply in your main view output the contents of $sidepanel. Code: controller{ Of course if you want to have the two forms on the same page without reloading, then output them both and use Jquery etc to hide one of them!
[eluser]ramonskie[/eluser]
yes i want to show the forms without reloading.. do you know a good tutorial for Jquery to hid/show the views?
[eluser]jdav3579[/eluser]
I would do something like below - its ugly code and Im certain there are better ways, but gives the idea. Like you could just alter the text of the button on toggle. Checkout: http://api.jquery.com/toggle/ Code: <form class='formtoggle'>
[eluser]ramonskie[/eluser]
i still can't get it to work i load 2 view files in 1 view file called checkout <?php echo $this->view('cart/register'); ?> <?php echo $this->view('cart/login'); ?> and now i want to toggle these 2 views is that possible or maby create a tabbed view
[eluser]jdav3579[/eluser]
Could you post a section of the controller which loads the two views and also your view file that pulls it all together. I am not entirely clear on how this section of code works: Code: <?php echo $this->view(‘cart/login’); ?> The way I'd do it is in the controller, load each of the views into the variables: Code: $data['register']=$this->load->view('cart/register',null,true);#3rd parameter returns data as string Then in 'main' view; Code: <?=(isset($register))?$register:''?> I dont think you can load views directly within views, i have created code for doing this myself, but it breaks the paradigm a bit I think..
[eluser]jdav3579[/eluser]
Also post your forms and I will look at JQuery for them for you
[eluser]ramonskie[/eluser]
check out view Code: <head>
[eluser]ramonskie[/eluser]
what i want to achieve is that every view file becomes a kind of module that i can load whenever i want on some page and if i want to change layouts or something that i only need to edit one file
[eluser]jdav3579[/eluser]
I cheat a little myself sometimes for this reason - i am sure I will probably get told off for it, but here goes... Create file in helpers: general_helper.php - you will need to load in your controller: Code: function view($page,$data,$return=false){ Then in your view, this function will be accessible and you can load any view you like, just pass it the data and file name! |
Welcome Guest, Not a member yet? Register Sign In |