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:



Code Igniter Controller/Model Name Conflicts?

I have a controller and model both named "account" without getting "cannot redeclare class". I'd like to add a prefix to Models or Controllers, or preferably both.

View 2 Replies View Related

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

Passing Db Query Results From Controller Into View With Code Igniter?

I'm trying to pass a database query from my controller into a view and display the results in the view. The way I'm doing it now says "undefined variable, sql" when I load the view. This is what I have:


function make_login()
//Select list of departments for dropdown
$sql = $this->db->query('SELECT departmentName FROM department ORDER BY departmentName ASC');


(If I just echo it out in the controller, it displays the results)

View 4 Replies View Related

Creating Foreach Loops Using Code Igniter Controller And View?

This is a situation I have found myself in a few times and I just want clear it up once and for all.

Best just to show you what I need to do in some example code.

My Controller

function my_controller()
$id = $this->uri->segment(3);
$this->db->where('id', $id);
$data['get_cue_sheets'] = $this->db->get();

So basically I am trying to display a number of sheets and then within each of those sheets the clips that belong to that sheet.

View 4 Replies View Related

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


I'm getting really confused about this MVC thing. I tried searching the web for an explanation, but I haven't been able to really understand anything. I do know that the MVC somehow reduces the amount of coding needed (but adds to the complexity, IMHO).

It allows you to separate the mechanics of PHP and the website so that you can change the view of the webpage and put the functionality back with ease. I haven't really been able to find any simple examples of this. Personally, I feel it is adding alot of complexity to something that is user-friendly already.

View 1 Replies View Related

Validation In Model/View/Controller Model?

I am working on a PHP project which makes extensive use of the MVC design pattern. I am looking to add validation to a form and am curious as to what the right place for validation is.Due to the way that forms are generated, validation on postback data is a lot simpler and less repetitive in view components. Is it acceptable to have the view validating response data, or should this be implemented within the controller, or even the model

View 2 Replies View Related

An Implementation Of The Model-View-Controller Pattern In PHP

For those who you thought my method of implementing OO principles in PHP was
totally wrong - see
for details, you can now read and tell
me why my implementation of the MVC design pattern is totally wrong.

Go on, I dare you. Make my day.

View 2 Replies View Related

Call Model Or Controller Functions In View?

How to call model or controller functions in view.

Can we use functions operating database queries in helper ? How ? example ?

View 1 Replies View Related

Extend The Code Igniter Controller Class?

In my CI systemlibraries directory I have a new class named DD_Controller.php. This file looks like this:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class DD_Controller extends Controller
protected $ddauthentication;
function __construct()

The Inquiry class works fine when I extend Controller, but I get a Fatal error: Class 'DD_Controller' not found in C:developmentlocalhostapplicationsinquirycontrollersinquiry.php on line 4 When I extend DD_Controller. In the config file I have the prefix defined as such: $config['subclass_prefix'] = 'DD_';

View 2 Replies View Related

Call A Function In Another Controller In Code Igniter?

I want to call a function in another controller. for example if user try to log in with incorrect parameter then the application will redirect to another controller and passing a variable (array).

class User extends Controller {
function User()

View 2 Replies View Related

Separate Codes According To Model View And Controller Objects?

I'm an university student and I'm developing an ecommerce system using OOPHP in MVC architecture. I find it difficult to find related articles regarding PHP in MVC. provide me with any example or how i can code my system related to MVC and how i can separate the codes according to Model, View and Controller objects?

View 1 Replies View Related

Create A Flexigrid With Passed Variable From Another Controller In Code Igniter?

My problem is kinda silly but I don't know how to do it. I'm creating a standard flexigrid using standard structure:

//ver lib
* 0 - display name
* 1 - width
* 2 - sortable


is it possible to create a flexigrid WITH a parameter in third URI segment? For instance, I want to display a list, which user created and to do that I need his id. I can easily do that within the same controller but I want to pass it to different controller and create new flexigrid form there. So in 'index()' method can I have, for instance $get_id variable passed from different controller? Like this?

$grid_js = build_grid_js('flex1',site_url("admin/admin_lists/display_show_list/".$get_id),$colModel,'name','asc',$gridParams,$buttons);

View 1 Replies View Related

Throwing Exceptions From Model/view/controller In A Zend Framework Application?

In the Zend Framework library, the current practice (circa 1.10.8) is that library components throw exceptions that extend Zend_Exception. E.g. the Zend_Layout component throws a Zend_Layout_Exception

In my own ZF library, where I'm adding my own ZF components or extending existing components, I'm throwing a Mylibrary_Exception (it's not really called that of course :) I can see that they're going to change some of that in ZF 2.0[URL].. My actual question is this:

Throughout my MVC application in my controllers/models/views, if I need to throw an exception (and this will be rare, because obviously I'll be handling expected errors in a different way) - BUT if I do need to throw an exception here, what is the best practice in ZF? should I just throw new Exception("this is an exception"); or should I be creating Exception classes in my ZF modules, similar to how the ZF library is organised. i.e. they have exception classes for each library component, should I have exception classes for each application module?

application/modules/user/exceptions/Exception.php (class User_Exception)
application/modules/user/exceptions/SuperexampleException.php (class User_Exception_Superexample)

I've never seen anyone do anything like that before in ZF, so I'm not sure if it's a good idea or not.

UPDATE: To clarify my question further - when raising exceptions in the MVC part of the application (as opposed to the library) - are there any conventions regarding using specific exception classes (like the library does) vs just using the generic Exception class?

View 2 Replies View Related

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

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

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

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

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

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

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

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

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

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

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?

I have main controller, that print main page.


How can I print last articles in header view?

View 2 Replies View Related

CodeIgnitor Controller - Pass Status Back To Calling Function?

So I am posting some data to an action on a controller using the CI framework. The post completed successfully but I would like to return a status to the calling

Using firebug I can see that the post is completed successfully (200) but I don't see the json that I am returning. How come I am not getting the json returned?

public function sendMail()
$senderName = trim($_POST['senderName']);
$returnEmail = trim($_POST['returnEmail']);
$message = trim($_POST['message']);
if (valid_email($returnEmail))
send_email('','Website Email From: '.$senderName, $message);
$success = array('success'=>'Mail Sent');


View 2 Replies View Related

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

Render Part Of A View Before All The Controller Code Ends?

The scenario: A "forgot my password" for is filled with email. On submission email is sent to the user. Due to the way ZF is working, the email is sent in the controller, before anything is thrown to the browser. This makes it look like after the submission the site is stuck (if it takes a long time to send the email). Is there a way to echo a message to the screen, on the lines "Your request is being taken care of...".

I can use AJAX to submit this request, I can use cron to send the emails at a later time...

View 2 Replies View Related

Use Another-model In A Controller?

i want to use another model in a controller for example in users_controller.php,we use a model as User how i can use another model for example sports_controller model as Sport?

View 1 Replies View Related

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

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

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

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

Copyrights 2005-15, All rights reserved