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:

[Code..........]

ADVERTISEMENT

Code Igniter Controller/Model Name Conflicts?

May 3, 2011

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

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

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

Feb 6, 2011

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:

CONTROLLER

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

[code]....

(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?

Jun 14, 2010

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->from('cue_sheets');
$this->db->where('id', $id);
$data['get_cue_sheets'] = $this->db->get();
code....

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?

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

Model-View-Controller

Jan 2, 2007

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?

Mar 14, 2011

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

Jul 17, 2005

For those who you thought my method of implementing OO principles in PHP was
totally wrong - see http://www.tonymarston.co.uk/php-my...od-bad-oop.html
for details, you can now read
http://www.tonymarston.co.uk/php-my...controller.html 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?

Aug 28, 2010

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?

Oct 26, 2009

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()
{
parent::Controller();
[Code].....

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?

Nov 24, 2010

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()
[code]....

View 2 Replies View Related

Separate Codes According To Model View And Controller Objects?

Apr 23, 2010

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?

Sep 8, 2010

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

[Code]....

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?

Oct 5, 2010

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/controllers/UserController.php
application/modules/user/forms/UserForm.php
application/modules/user/models/User.php
application/modules/user/views/scripts/index.phtml
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?

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
);
$this->session->set_userdata($data);

View 3 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,
$flag=$_GET['is_owner'];

in view i want to access $flag...how 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

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

Pass A View Variable To The Controller In Codeigniter?

Jun 26, 2011

My View :-

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

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.

[Code...]

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

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.

[code]...

How can I print last articles in header view?

View 2 Replies View Related

CodeIgnitor Controller - Pass Status Back To Calling Function?

May 24, 2011

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 jQuery.post().

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('me@my.com','Website Email From: '.$senderName, $message);
$success = array('success'=>'Mail Sent');

[Code]...

View 2 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()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$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) {
console.log(data);
}
});

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

responseText:""
status:200
statusText:"OK"

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?

Sep 23, 2009

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?

Jun 3, 2011

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?

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);
$email->send();
The My_Email::specialWelcomeMessage() function would do something like this:
[coede]....

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?

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

Using A Model Function In Controller?

Jun 2, 2011

In my model named Profile_model I have this function which retrieves profile data for the logged in user.

function profile_read()
{
$this->db->where('user_id', $this->tank_auth->get_user_id());
$query = $this->db->get('user_profiles');
$data['row'] = $query->row();
}

In my controller I'm using $this->load->view('profile/edit_general_view', $data); to try and load the data from the model into the view.

function edit_profile()
{
//validation rules
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required|xss_clean|min_length[2]|max_length[20]|alpha');...........

What is the correct way to pass the data from the model function profile_read into my controller function?

View 1 Replies View Related

Access A Model From My Controller?

Jun 21, 2011

How can I access a model from my controller?

class NewsController extends AppController
{
/* ... */
function add()
{
/* Access model 'post' */
}
}

View 2 Replies View Related

MVC - Functionality In The Controller/model?

Apr 10, 2011

I'm trying to improve some PHP scripts using a OO design (it's procedural now with some OO parts). Just to be clear, I'm not trying to build a full MVC application, but I am trying to seperate parts as much as possible. I've never used MVC before in PHP (only a little bit in Java).When using Google, I find 100 different MVC approaches for PHP and I can't find a good book on this subject. If anyone could suggest me a good book on OO design in PHP, Currently, a part to add a user to the database (assuming a user only contains a firstname for now), looks like this (users.php):

$validator = new UserValidator();
if ($validator->validate($_POST['user_firstname']))
result = $db->execute("INSERT INTO `users` (`user_firstname`) VALUES (?)", $_POST['user_firstname']);

Knowing that adding users may be done at multiple places and I don't want code repeat, I will create a usermodel. This class will contain a method addUser(). The thing I'm a bit stuck with is the validation. The UserValidator will check if all fields are filled in correctly.I could do this:

$validator = new UserValidator();
f ($validator->validate($_POST['user_firstname']))
$result = $user->addUser($_POST['user_firstname']);

[code]...

View 2 Replies View Related

Difference Between Controller And Model In MVC?

Jun 21, 2011

I'm little confused about controller and model in MVC framework (codeIgniter). Its clear to me that controller methods calls the views and Model methods interact with database.However, I'm little confused about the following types of methods, which are called by methods in a controller.

hash_password //returns hash password.
valid_email //validates email format and return true or false
is_logged //check if session has a variable, returns true or false
generate_random_string //generates and hashes a random string

Should they be placed in controller or in a model?Currently I place all of the above functions in a controller. Is it correct?

View 5 Replies View Related

Use Zend_Auth, In Model Or Controller?

Dec 15, 2010

I'm working on my first user login in Zend, but I'm a little confused with Zend_Auth. All the articles I read about it use it directly in the controller. But to me, it makes more sense, to work with it in my User model, so that every controller can call these functions.

There's really very little documentation about models for the Zend Framework.

View 3 Replies View Related

Include The Controller In The Model?

Feb 1, 2010

is it usual to use controllers in models?

then you have to include the controller in the model?

View 2 Replies View Related

Refactoring Controller To Model In CodeIgniter?

Feb 1, 2011

It's come to my attention that my image processing code that I currently have in my controller would be better suited in a model, but I'm not sure even where to start to do this. I have a controller that handles uploading an image, renaming the file and storing it in the database using Doctrine:

<?php
class Addimage extends Controller
{
function index()

[code]....

I would like to be able to have most of this in a model, because I'm using a template system for the views where my uploadimage.php view is just the upload form so that it can be dropped on any page. Also, I only have experience using Doctrine models.

View 1 Replies View Related

Error Handling In The Model Or In The Controller?

Jul 12, 2010

I asked around on various IRC channels but was unable to get an answer with a definitive explanation behind it. Should errors (pertaining to the model, such as transaction failures) be handled in the model, or in the controller? EDIT Well, the confusing thing is that my code (in the model) looks something like this already:

try
{
// Connect to MongoDB
// Fetch a record
}
catch (MongoConnectionException $e)
{
// Handle this error
}
catch (MongoException $e)
{
// Handle this error
}

So, should I return exceptions based on the exceptions MongoDB returns? Or should I directly allow these exceptions to bubble up to the controller?

View 4 Replies View Related

5 - Cake 1.3 - Use Any Model In Any Controller And Views?

Nov 6, 2010

My question is that with example. I have to show all categories of books and with checkboxes in a page which I want to be posted to next view without interacting db and there I want to store them in a hidden field in a comma separated string.

Actually I have a tab for find a book. user clicks on it and it has a list of categories of books listed which I get from categories model and used categories controller index function. I want to post user selected categories to next view like where I will take more info regarding user filtration for books it is coming from another model and controller.

actually I want to know what I have to do I want to develop this find a book function.Should I have a model for this and a controller which they use some table for find a book or can I use any model in any controller for this function.

View 3 Replies View Related

CodeIgniter 2.0 Cannot Use Method Of A Model From Controller?

Feb 3, 2011

I'm trying to call a method of my model from my controller and I keep getting an error and I'm unsure as to what im doing wrong

PHP Version: 5.3
CodeIgniter Version: 2.0
/application/models/blog.php[code]....

Error Message: Fatal error: Call to a member function get_last_ten_entries() on a non-object

View 2 Replies View Related

Codeigniter Model Not Loading Into Controller?

Feb 1, 2011

I am having trouble with a models in Codeigniter. I setup a model called Usermodel in /models usermodel.php. and when I attempt to load it is stops the scrip and anything after it. When I purposely entered a wrong name in the ->load->model area CI throws up an error, saying it can't be found (like expected) When everything is correct nothing is loaded.

User model
class Usermodel {
function __construct()
{

[code]....

View 2 Replies View Related

Codeigniter Controller/model In Mysql?

Jun 18, 2009

<?php
class Sitemodel extends Model
[code]....

View 1 Replies View Related

Get Current Controller From Model In Cakephp?

Dec 15, 2010

Im creating a behavior tha need to log the current controller. How can I get the current controller from model in cakephp?

View 4 Replies View Related

Prevent Controller From Trying To Autoload Model?

Nov 8, 2009

beginning Cake user and trying to do some work on an already existing application. Running into a problem when I create a new controller. I have created StoreController and when I try to call methods inside it I get the error below. There is no table 'stores', but it seems like it's trying to automatically load a model relating to the controller. How can I prevent my application from trying to load a model for this controller?

Missing Database Table Error: Database table stores for model Store was not found.

View 3 Replies View Related

ADVERTISEMENT