How / Where To Pass Parameters From View To Controller In CodeIgniter

May 18, 2011

I'm new to PHP and Codeigniter; I did a login page without using Codeigniter, and it worked. Now I'm trying to do it under the MVC design and Codeigniter. I have a controller which directs to the view of the login page. Then I submit - but I don't understand how and where to send the user name and password I got, to handle it. I know it should be sent to a controller - but i don't understand how. Should i just do this in my login view?

<form name="loginForm" method="post" action="/controllers/checklogin.php" id='loginForm' dir="rtl">

Is there a better - or more elegant way to pass the params for a controller that will handle the login?

View 1 Replies


Pass A View Variable To The Controller In Codeigniter?

My View :-

<?= link_tag(base_url().'css/simple.css'); ?>
<?php $this->load->helper('form'); ?>
<?php $this->load->view('commentform'); ?>
<?php $id=$this->uri->segment(3);?>
<?php echo $id;?>

i would like to use the variable $id in my controller.I'm using codeigniter by the way, and am a beginner.

View 2 Replies

CodeIgniter - Pass Arguments From View To Controller?

With the code below now, I am unsure on how to print out the bookmarks and the tags correctly I am completely new to CI and I have recently hit a road block. I am very unsure how I would go about passing a function argument from the view file to the controller so I could use it on a function? I have a foreach loop on the view going through the all the items passed by function get_latest_bookmarks. That function returns a ID for each item and I am wanting to use this with another function called get_bookmark_tags which will get the tags of the bookmark from another table. I have provided the code I have done so far below.


View 2 Replies

Pass A Post Value From View To Controller To Model And Back To Controller In Code Igniter

I'm creating a login form with Codeigniter, and I have a controller that collects the inputs from the form, then I want to check to make sure what the user entered is in the database, so I'm collecting those values in the post and want to send them to the model for the database connection.

Then if the results are in the database I want to send something back to the controller with a yes or no and then I can go from there. I'm kind of stuck, but this is what I have so far: The controller:


View 3 Replies

General On Mvc ... Should Controller Pass Data To View Or View Should Grab It Directly From Model

I'm trying to learn and fully understand mvc pattern and learn php at the same time. I decided to built basic mvc framework that I could use on various projects later on. Having read lots of posts in here regarding mvc and coupling between models/views/controllers I'm a bit lost.. At the moment my understanding is that in web application controllers deal with coming request from browser and, if necessary, calls methods on model classes telling models to change its state. Then controller instantiate appropriate view class that will be responsible for displaying interface.

Now should controller pass appropriate model object to view and view should pull out all the data from model when needed? Or controller should grab data from model and pass it to view, possibly wrapping it all into single wrapper object that view will access and grab data from there? Or view should simply instantiate appropriate model when needed and pull out data directly from model object? From what I read here [URL]

I'd lean towards the 3rd option where controller doesn’t pass anything to view and view instantiates model it needs. This is because: view and controller should have same access to model controller shouldn't act simply as mediator in between view and model......

View 7 Replies

Codeigniter : Pass Data To A View Included In A View

I have a controller and including two views from one function as below


The view file view_destinations.php including a php menu file as follows

<? $this->load->view('includes/top_menu'); ?>

My question is, how can I pass data that is fetched from the controller to this included top_menu.php ?

View 2 Replies

Pass Parameters From One Controller To Another In CakePHP?

Can anyone tell me how to pass parameters to a function in another controller in cakephp?

View 2 Replies

CodeIgniter Load Controller From View?

Is there a way to load a controller from a view ? Here is what i am affter.. I want to use one view multiple times, but this view is being loaded by separate controller that gives the view, information from the db.So becouse of that information from the model i can't just set $this-load->view(); and etc. Is there a way to do this thing, or it has a better way ?

View 4 Replies

Load A View In Every Controller In CodeIgniter?

Because I thought of ajax posting my form to a specific function in my controller and do a sql-insert, but I want to stay on the same page. So is it necessary to load a view in the posted url (=destination)?

View 1 Replies

CodeIgniter: Page Not Found When Passing Parameters To A Controller?

I'm trying to pass parameters to a control in codeigniter, but I'm getting 404 page not found error, I don't get it, I did what the guide says: [URL]....

When I remove the params in the index function and just access the controller everything works fine, but I can't pass a value to it...

Here is the code the way I'm trying to send a param:

class Main extends Controller {
function index($username) {
echo $username;

How can I get more info regarding this error from codeigniter?

View 2 Replies

Write A Function In A CodeIgniter Controller Which Can Take Optional Parameters?

I'm trying to write a function in a CodeIgniter controller which can take optional parameters. However, I always get Missing Argument warnings. I'm not trying to suppress the warnings - I'm trying to declare the parameters as optional (maybe they could be empty strings if they don't exist, or something).

View 1 Replies

Return A Value Not An Array From A Controller To View Codeigniter?

I use this in my controller,

function phpcalview()
$year = $this->input->post('yearvv');
$year1 = $year+1;
//echo $year1;

How to $year1 value to my view phpcal and get that value in the textbox yearvv

View 2 Replies

Codeigniter: Call A Function In View From Controller

I am New to Codeigniter. In my Sample Application I add a new Tab called "RegForm" in my Main.php(View Folder). When i Click the RegForm Tab it load the New Window(width='800px' height='500px'). i understand the concept but i dont know how to write coding in Codeigniter. Basicall i call a function in Controller file when i Clicked the RegForm tab. and i need to call a function in View where i load a window with properties.

View 1 Replies

Pass Values From A Controller Into A View Would Be?

what the best way to pass values from a controller into a view would be? If anyone has played with codeignitor, they will know what I mean. I have looked at CIs code but can't find the file that handles this. I'd LOVE to know how this is done.

View 3 Replies

Pass Parameter From Controller To View?

i am passing

$router->map('Owner', 'Owner/:is_owner','null', array('controller' => 'companies', 'action' => 'index','is_owner'=>'1'));
$router->map('Client', 'Client/:is_owner','null', array('controller' => 'companies', 'action' => 'index','is_owner'=>'0'));
in controller i m getiing it by,

in view i want to access $ to do tht??

View 1 Replies

Pass Variables From View To Controller?

I have a Codeigniter view which does some processing and creates some variables which I need in my controller.

How can I access the variables created in my view from my controller? Is it even possible to do so?

I can pass variables from the controller to the view, Can I pass variables back from the view to the controller? Just to make things more clear. I have a main controller which takes multiple views and forms a complete page. In this complete page I just need to pass some data. This data is again, don't flame or blame me for this, is processed in a view. Now I need to set up meta data, title keywords etc, for every page which is set by a main controller method setPageMetaData and it accepts a key value pair. For some pages its easy to setPageMetaData inside controller but in one particular case the title and keywords are generated by some processing in view. I need that information in my controller. My question was regardless of this particular case, can I pass variables from View to my Controller? Is it even possible? I could have added, "is it recommended?" to earn some applauses.

View 2 Replies

Does Loading A View Effectively Stop A Controller In CodeIgniter

Would the following code in a controller prevent the nextFunction() from running?


View 1 Replies

Calling Controller Methods From Inside View In Codeigniter

Is there a way to call a method inside the controller from our view using codeigniter.I know it is a bad practice but, now I force to do this.

View 2 Replies

CodeIgniter Passing Dynamic Data From Controller To View?

I am passing an array to a view from a controller. Simple stuff. Should work, but is behaving rather too strangely and I cannot figure out the bug.This is the controller-

$link = "http://" . $server . "" . $name;
$data = array(

View 3 Replies

Pass Information A Controller To A View In PHP (no Framework)?

Using PHP, If I have a model (a class) where I various queries, whatever I need, and in my controller, I use myModel = new CustomerModel(); and later in the controller, say I call myMyodel in the controller (I know looks like codeigniter but I am not using a framework) to:

$data['query'] = myModel.OrderByLastName();

how do I pass that $data['query'] to a view, a separate .php page?I don't wan to echo anything from my contoller.Also, was hoping this design, the way I explained it makes sense. Or am I wasting time with the model class?

View 2 Replies

Access POST- Parameters In The Model Or Pass As Method Arguments From Controller?

I have to process about 20 POST-parameters, and I am not sure where to do that. I could define each as an argument of the method on the model, and pass them from the controller when the method is called. This would result in quite a bit of work and make the function call less readable, due to the number of arguments.

Or I could call the method on the model, and just directly access the parameters. Passing the parameters as arguments would give me more control over which parameters the function accesses, and the documentation would more self-explanatory. But if new parameters were added later on, they would have to be added to the end of the method call, as not to break every existing call. I imagine that this would become quite confusing if it happens a few times, as the arguments can't be logically grouped.

If I access the parameter in the model, no parameters have to be passed from the controller to the model, making the method call terser. But I have no control over the parameters that are accessed, as they can easily and without restrictions be added or removed. This would require greater discipline from the other developers, and I dislike to depend on that, because sooner or later someone is bound to "just (add|change|fix) this real quick".

I'm not sure which way to go. I tend to just do it all in the model, as this is faster to write, seems easier to maintain (no argument chaos) and conceptually fits better into my view of a model. On the other hand, I'm not sure my view of a model is correct, and if it will end in chaos if I depend on the other developers to always update the documentation after each change. So, what should I do?

View 4 Replies

Controllers Allowed To Pass Parameters Into View?

I'm about to do a PHP website using the MVC pattern. I am not using a framework as the site is fairly simple and I feel that this will give me a good opportunity to learn about the pattern directly. I have a couple questions.

Question 1: How should I organize my views? I'm thinking of having a Page view which will have the header and footer, and which will allow for a Content view to be nested between them.

Question 2: If I have 5 Content pages, should I make 5 different views that can be used as the content that is nested within the Page view? Or, should I make them all extend an abstract view called AbstractContent?

Question 3: What about controllers? I think there should be one main controller at least. But then where does the request go from there? To another controller? Or should I just call the Page view and leave it at that? I thought that controllers were supposed to handle input, possibly modify a model, and select a view. But what if one of the views nested within the view that a controller calls requires additional input to be parsed?

Question 4: Are controllers allowed to pass parameters into the view? Or should the controller simply modify the model, which will then affect the view? Or is the model only for DB access and other such things?

View 3 Replies

Pass Arguments In Codeigniter Controller Functions?

i have this function to show all articles, i am writing this function again and again for different categories, because codeigniter arguments are related to url how do i pass arguments so that i can reuse this function ?This is my controller function to show all news.

function all_news(){

//do some pagination
$config['base_url'] = 'http://localhost/news/all_news';[code].....

View 1 Replies

Zend Framework - Generate Data In Controller And Pass To View For Use In Javascript?

I have a bit of data that I want to use to build a form's select field. The JS that generates the form (it's part of the jqgrid plugin) is in the view. How do I get the data from the controller into the javascript so I can use it?

To just get something working I tried the following...

In the controller I created an action to return some sample data:

public function testAction()
$a = "0:Select";
return Zend_Json::encode($a);

In the view I make an ajax call to that action:

var testselect = $.ajax({
url: '/admin/sites/test',
dataType: "json",
complete: function(data) {

And this returns an XMLHTTPRequest object that contains, in part:


Shouldn't the responseText be whatever was returned by the call to /admin/sites/test?

In my mind this is what is happening:

the view makes an ajax request to the test action of the sites controller in the admin module the test action JSON encodes the contents of $a and returns it the complete callback function of testselect logs the result to the console and should have the contents of $a in the responseText.

Where am I misunderstanding this? Is there a better way to do this? Like, could the controller pass the needed data to the view object and then I somehow access that in the javascript (though how, without making an ajax request or putting the data into some superglobal like $_SESSION I don't know)?

View 1 Replies

Codeigniter - Pass Parameters To Model?

I am using the following code to initialize a model from within my controller:


Is it possible to modify the above line somehow so that the model constructor recieves a parameter? I want to use the following code in the model constructor:

function __construct($param_var) {
$this->$param_var = $param_var; //I'm not even sure this works in PHP..but different issue

View 2 Replies

Codeigniter Pass Parameters To Function?

I've created a library in Codeigniter (Template), which I pass some parameters when loading it, but I want to pass those parameters to the functions of the library.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Template {
public function __construct($params)
echo '<pre>'; print_r($params); echo '</pre>';


View 4 Replies

Copyrights 2005-15, All rights reserved