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?


Pass A View Variable To The Controller In Codeigniter?

Jun 26, 2011

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 View Related

CodeIgniter - Pass Arguments From View To Controller?

Jun 11, 2011

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 View Related

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

Feb 9, 2011

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 View Related

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

Sep 23, 2009

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 View Related

Codeigniter : Pass Data To A View Included In A View

Dec 1, 2010

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 View Related

Pass Parameters From One Controller To Another In CakePHP?

Jun 1, 2010

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

View 2 Replies View Related

CodeIgniter Load Controller From View?

Apr 29, 2011

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 View Related

Load A View In Every Controller In CodeIgniter?

Jan 9, 2010

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 View Related

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

May 1, 2010

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 View Related

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

Jan 6, 2010

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 View Related

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

Apr 19, 2010

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 View Related

Codeigniter: Call A Function In View From Controller

May 26, 2011

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 View Related

Pass Values From A Controller Into A View Would Be?

Jul 29, 2009

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 View Related

Pass Parameter From Controller To View?

Nov 1, 2010

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 View Related

Pass Variables From View To Controller?

Jun 14, 2011

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 View Related

Does Loading A View Effectively Stop A Controller In CodeIgniter

Jul 12, 2010

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


View 1 Replies View Related

Calling Controller Methods From Inside View In Codeigniter

Jun 8, 2010

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 View Related

CodeIgniter Passing Dynamic Data From Controller To View?

Jul 3, 2010

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 View Related

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

Sep 29, 2010

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 View Related

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

Aug 18, 2009

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 View Related

Controllers Allowed To Pass Parameters Into View?

May 16, 2010

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 View Related

Pass Arguments In Codeigniter Controller Functions?

May 21, 2011

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 View Related

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

Sep 15, 2010

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 View Related

Codeigniter - Pass Parameters To Model?

Jul 19, 2009

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 View Related

Codeigniter Pass Parameters To Function?

May 7, 2011

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 View Related

Pass Controller Methods To An Auth Check In Codeigniter / It

Jul 14, 2011

i am using ion auth and codeigniter to build a web app, i would like to specifiy some methods of a controller to maybe an array or something that i can perform a authentication function- and some not, there must be an easier way of added a if/else statement to the function the reason being here is a very quick examplle

class employers extends MY_Controller{
function __construct (){
//i want these to be public
function index(){}
function signup(){}

View 1 Replies View Related

Retrieve Data Using A Model And Pass It To Be Used In A Controller Using CodeIgniter?

Jun 3, 2011

From a user login form i need to use their username ($this->input->post('username')) to query against the membership table in my database so that I can retrieve the users firstname and lastname, which I believe should be done via a model called from my controller. I then need to pass that data back to my controller to use the firstname and lastname to add in to my session userdata which is set in my controller, as shown below.

$data = array(
'username' => $this->input->post('username'),
'firstname' => //need to retrieve value from database,
'lastname' => //need to retrieve value from database,
'is_logged_in' => true

View 3 Replies View Related

Pass Additional Parameters To The Zend PartialLoop View Helper?

Nov 4, 2009

In a Zend view I can apply a partial template to an iterable element as follows:

$this->partialLoop('template.phtml', $iterable);

However inside the template, only the elements of the $iterable are available, is there another way of passing extra data to the partial?

View 2 Replies View Related

Codeigniter Load View Files And Pass Variables Through?

Mar 23, 2011

I've read through the source code but it seems a little cryptic. I'm just trying to get my head around how CI transforms an array into individual variables available to the view.

I gather that the view is included with include(), but the variables seem to only be effective for the view.


$this->load->view('about', array('title' => 'about'));


<?php echo $title; // shows 'about' ?>

View 1 Replies View Related

Codeigniter - Pass Multiple Data Arrays To A View?

Jun 24, 2010

I am trying to populate a dropdown menu on an events page with a list of locations.hat I wish to do is retrieve all names from a locations table, store them in an array in my event.php controller, pass this to a view which then lists all the locations in a dropdown menuHere is the loop in my controller which retrieves the locations..

$result = $this->locationModel->get_locations_list();
$arr[] = '';
foreach ($result as $val)

View 1 Replies View Related

Use The Zend Framework Partial View Helper Outside Of A Controller Or View?

Jul 16, 2010

I would like to create a custom class that will generate an HTML email. I want the content of the email to come from an "email view scripts" directory. So the concept will be that I can create an HTML email view script the same way I would create a normal view script (being able to specify class variables, etc), and the view script would be rendered as the HTML body of the email.For example, in the controller:

$email = My_Email::specialWelcomeMessage($toEmail, $firstName, $lastName);
The My_Email::specialWelcomeMessage() function would do something like this:

How would I call the partial view helper from outside of a view script or controller? Am I approaching this the right way? Or is there a better solution to this problem?

View 1 Replies View Related

Codeigniter Login To Controller - Protect Entire Admin Controller

Nov 24, 2010

I'm very new to Codeigniter, I'm trying to protect the entire admin controller. I figured I'd start here:

function Admin()

but this is obviously incomplete. How do I also stop the method that is trying to run ( ie index() ), and am I on the right track here?

View 2 Replies View Related

Codeigniter - Send All Requests That Do Not Match A Controller's Name To The Default Controller

Dec 22, 2010

I'm working on a project involving two kinds of URLs, one following the standard CI pattern[URl]..

And another presenting the following scheme:[URL].. I would like the second to call the default controller's handlecategory (or something like that) function with category as an argument.

Bonus love if you could also tell me how to let URLs like [URL].. call the same function passing just place as an argument if no category follows that URL, or both place and category if it does.

Additional datum: I already know the names of all controllers, places, categories.

View 1 Replies View Related

Passing Data From One Controller To A View In Another Controller?

Jun 10, 2011

In zend I'm interested in passing data from one controller to a view in another controller. For example, I have a search controller whose purpose is to use the search model to query SOLR, and I want to have Index Controller call it from the view (via ajax or other means) and have Search controller return data to that view.

View 1 Replies View Related

Call Controller Method In View Or Another Controller?

Oct 15, 2010

I have main controller, that print main page.


How can I print last articles in header view?

View 2 Replies View Related

Send Data From Controller To View Or Have Logic Within View?

Jun 28, 2011

I have a webpage where I am trying to create a contextual menu depending on the category of the page being browsed. If the category is on animals, the segment based url will contain animal, ie. http:[url].....To build the contextual menu, I will need to access my database table subcategory with columns subcat_id, subcat_name, cat_id and select all rows with cat_id corresponding to that of animals.

Should I access the database (via the model method) from the controller, then pass the array containing the subcategory names to the view? Or should everything be done within the view, where there is code that loads the model method that returns an array of subcatergories?Btw, I'm using PHP framework Codeigniter.

View 2 Replies View Related

Displaying Another Controller's View Inside A View?

Jun 25, 2010

I'm using cakephp and I want the login view for the controller 'users' to be displayed on the default.ctp for the layout controller. I can I do this?

For example:

<div id="leftNav">
<div id="login-block" class="block">
//render users/login here


View 2 Replies View Related

Call A Controller Function In Another Controller In CodeIgniter?

Jul 11, 2011

I have a controller "user" in my codeigniter application. This controller has a function called logged_user_only():

public function logged_user_only()

Now I would like to call this logged_user_only() function in a function of another controller to check if the user is logged in or not? PS. If this can not be done, or is not recommended, where should i place this function to access in multiple controllers?

View 2 Replies View Related

CodeIgniter: Sending Params To A View / Without Splitting The View Into Multiple Parts?

Apr 30, 2010

My controls receives some params from the user, I would like to place them inside the view I'm calling, how should I do this without splitting the view into multiple parts?

View 3 Replies View Related

MVC: Redirect A View To A Controller Which Will Go In Another View?

Mar 23, 2011

I follow the MVC model in PHP + JS + HTML + CSS Also, i use CodeIgniter as framework. I want to know, what do i need to do to redirect to another controller. I am in the Home page of my project.. and when i click "details" (div = prod_details) for a product, what is supposed to be the reference.

here's my code: MY HOME controller

class ordiDepot extends Controller {
function ordiDepot(){


View 1 Replies View Related

CodeIgniter: Load Controller Within Controller?

May 22, 2011

I have a home controller with an index action that displays a set of featured products. However, the products are managed through a product controller including a proprietary model and views.How do I access product information from within the index action in the home controller? Instancing product won't work as the class isn't loaded at runtime and CodeIgniter doesn't provide a way to dynamically load controllers. Putting the product class into a library file doesn't really work, either.To be precise, I need the product views (filled with data processed by the product controller) inserted in the index view. I'm running CodeIgniter 2.0.2.

View 1 Replies View Related

Include View Within View In Codeigniter Template Using Dwoo?

Jul 12, 2010

I am using Codeigniter 1.7.2 and Phil Sturgeon's wonderful Dwoo wrapper which allows me to use the Dwoo template library in Codeigniter -[URL].. I have a small question regarding the inclusion of other view template files within my template files. Say for example I have a dashboard.php file and I want to include a header and footer, what is the best way of doing that?

I usually would just do this:


And this seems to work, but the whole point of using a template library is to separate code from my html. Can I use Dwoo's include functionality and if so, how?

Update Since posting this I've worked out the ins and outs of Dwoo, you can include view files and use things like template inheritance to accomplish the same thing which is neater than assigning views to variables. I don't recommend the later unless you really need too.

View 1 Replies View Related

Codeigniter : Variables Scope When Calling A View From Within A View?

Oct 27, 2010

I am confused about variables scope when calling a view from within a view.I tested a bit and found: If the variables are originally passed from a controller, there is no need to do something to pass the variables from a view to a view. If the variables are declared in a view, I have to explicitly pass the variables from a view to a view. (e.g. : $this->load->view("hoge", $data);)I find it bit odd about the second case because my understanding was $this->load->view() is codeigniter version of the php include() which doesn't require me to pass variables explicitly.

View 1 Replies View Related

Passing Parameters To Controller's Constructor?

Dec 18, 2009

I have a controller which has several methods which should all share common informations. Let's say my URI format is like this:


I need to retrieve some informations from the database for id and have them available for all methods instead of writing a line in each of them to call the model. How can I do this?

View 3 Replies View Related