This question already has answers here:
Fatal error: Call to undefined function form_open() in c
(5 answers)
Closed 5 years ago.
Hello I get this error when I try to run my code, I'm just trying to test it out and I got this error, I'm trying to create a account registration and I'm required to use Codeigniter and I saw a similar code in the net and I try to follow it but somehow I got error with this and I don't know what I'm missing sorry I'm new to Codeigniter
Fatal error: Call to undefined function form_open() in C:\xampp\htdocs\codeigniter_project\application\views\welcome_message.php on line 9
A PHP Error was encountered
Severity: Error
Message: Call to undefined function form_open()
Filename: views/welcome_message.php
Line Number: 9
Backtrace:
Here is my code for view
<html>
<head>
<title>Create Account</title>
</head>
<body>
<h3>Create Account</h3>
<?php
echo form_open(CreateAccount_Controller,submit_data);
echo form_label('User Name:', 'Vu_name' );
$data= array(
'name' => 'u_name',
'placeholder' => 'Please Enter User Name',
'class' => 'input_box'
);
echo form_input($data);
?>
</body>
</html>
Here is my code for controller
<?php
class CreateAccount_Controller extends CI_Controller
{
public function _construct ()
{
parent::_construct();
}
public function create_account ()
{
$this->load->view(CreateAccount_View);
}
public function submit_data ()
{
// return hi or something;
}
}
?>
Load the helper in your controller constructor and Your code will be as follows:
<?php
class CreateAccount_Controller extends CI_Controller
{
public function _construct ()
{
parent::_construct();
$this->load->helper('form');
}
public function create_account ()
{
$this->load->view(CreateAccount_View);
}
public function submit_data ()
{
// return hi or something;
}
}
?>
You have forgotten to load form helpers in your code.
Please load the helper in autoload.php under application/config
$autoload['helper'] = array('helper');
OR
Load the helper in your controller constructor.
<?php
class CreateAccount_Controller extends CI_Controller
{
public function _construct ()
{
parent::_construct();
$this->load->helper('form');
}
public function create_account ()
{
$this->load->view(CreateAccount_View);
}
public function submit_data ()
{
// return hi or something;
}
}
?>
Hope this helps you.
Related
AM trying to connect modal in controller but it showing error like
Fatal error: Call to undefined function customerslist() in C:\xampp\htdocs\CI\application\controllers\Customer.php on line 25
A PHP Error was encountered
Severity: Error
Message: Call to undefined function customerslist()
Filename: controllers/Customer.php
Line Number: 25
Backtrace:
My code is following:
controller : Customer.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Customer extends CI_Controller {
public function __construct(){
parent:: __construct();
$this->load->library('form_validation');
$this->load->model('admin');
$this->load->model('customers');
}
public function index()
{
if($this->session->userdata('Admin')==false)
{
redirect('login');
}
else
{
$data['title'] = "Customer";
$data['customerlist'] = $this->customers>customerslist();
$this->load->view('customer',$data);
}
}
}
Modal: Customers.php
<?php
class Customers extends CI_Model {
function __construct()
{
parent::__construct();
}
//view all Customers
function customerslist()
{
$res = $this->db->get('customers_list');
if($res->num_rows() >0){
foreach($res->result_array() as $row){
$customerlist[] = $row;
}
return $customerlist;
}
else
{
return false;
}
}
//view all Customers
}
How can i fix this issues?
Thanks in advance....
You're missing a - in $this->customers>customerslist();
This should be $this->customers->customerslist();
can someone help me with this?. It gives me following Fatal Error:
Fatal error: Call to undefined function getNombre() in C:\xampp\htdocs\CodeIgniter\application\views\vista.php on line 6
this is my controller(c1.php)
<?php
class c1 extends CI_Controller{
function _construct() {
parent::__construct();
$this->load->helper('mihelper');
}
function index(){
$this->load->view('headers');
$this->load->view('vista');
}
}
?>
this is in my helper(mihelper_helper.php)
<?php
function getNombre(){
return "<h1>Arturo</h1>";
}
?>
this is my view(vista.php)
<body>
<h1>Llamado desde controlador</h1>
<?php getNombre() ?>
</body>
</html>
You missed a underscore in the controller's construct function. So the helper is not able to load and the function is undefined. Updated code as below,
<?php
class c1 extends CI_Controller{
function __construct() {
parent::__construct();
$this->load->helper('mihelper');
}
function index(){
$this->load->view('headers');
$this->load->view('vista');
}
}
?>
Hello guys i am trying to connect my database to get some data using codeigniter , there is my code:
i am getting this error:
Fatal error: Class 'Model' not found in /Applications/MAMP/htdocs/ci/application/models/Data_model.php on line 3
A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/ci/application/models/Data_model.php:3)
Filename: core/Common.php
Line Number: 569
Backtrace:
A PHP Error was encountered
Severity: Error
Message: Class 'Model' not found
Filename: models/Data_model.php
Line Number: 3
Backtrace:
Models:
Data_model.php:
<?php
class Data_model extends Model {
function getAll(){
$q = $this->db->query("SELECT * from data");
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data [] = $row;
}
return $data;
}
}
}
views:
home.php
<htmL>
<body>
<div> view has been loaded</div>
<!--<p> <?php echo $myValue; ?> </p>
<p> <?php echo $anotherValue; ?> </p> -->
<pre>
<?php foreach ($rows as $r) {
echo '<h1>' . $r->title . '</h1>';
}
?>
</pre>
</body>
</htmL>
controllers:
site.php
<?php
Class Site extends CI_Controller {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function index(){
$this->load->model('data_model');
$data['rows'] = $this->data_model->getAll();
$this->load->view('home', $data);
}
}
Always make sure that you extends your model with CI_Model for it will be recognized .
class Model extends CI_Model {
//you can always put function construct
public function __construct (){
parent::__construct ();
}
}
In your controller :
class Sample extends CI_Controller {
public function __construct () {
parent:: __construct();
//you can load here the model that you will just often so will load it everytime to use it in a function
$this->load->model('nameofModel');
}
}
Remember : The name of the model or controller must be the same with its filename.
Make sure your class extends the base Model class. In CodeIgniter this is "CI_Model"...
class Data_model extends CI_Model {
// Your model class code here...
}
make sure you have already load Model
for that:
1.open application/config/autoload.php
and
2. edit
$autoload['model'] = array(''); with
$autoload['model'] = array('Model');
thats works
I am a beginner in codeigniter and currently I am working on a shopping cart, taking help from http://net.tutsplus.com/tutorials/php/how-to-build-a-shopping-cart-using-codeigniter-and-jquery/ tutorial. I am using codeigniter 2.1.3.
I am getting an error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Cart::$load
Filename: controllers/cart.php
Line Number: 7
Fatal error: Call to a member function model() on a non-object in D:\xampp\htdocs\ci\application\controllers\cart.php on line 7
Can someone please tell me why it is not working?
The name of my controller is cart.php
<?php
class Cart extends CI_Controller {
public function Cart()
{
//parent::CI_Controller(); // We define the the Controller class is the parent.
$this->load->model("cart_model"); // Load our cart model for our entire class
}
public function index()
{
$data['products'] = $this->cart_model->retrieve_products(); // Retrieve an array with all products
print_r($data['products']);
//$data['content'] = 'cart/products'; // Select view to display
//$this->load->view('index', $data); // Display the page
}
}
?>
and my model is cart_model.php
<?php
class Cart_model extends CI_Model{
//public function _construct(){
//parent::_construct();
//}
public function retive_products(){
$query = $this->db->get("products");
return $query->result_array();
}
}
/* End of file cart_model.php */
/* Location: ./application/models/cart_model.php */
?>
Codeigniter 2.1.3 is intended to support PHP 5.2.4 and newer.
Change the class constructor:
<?php
class Cart extends CI_Controller {
public function __construct()
{
parent::__construct();
}
instead of
public function cart()
{
parent::CI_Controller();
Try to review your code. You calling the retrieve_products function on model but in model you have retive_products function .
Controller
public function index() {
$data['products'] = $this->cart_model->retrieve_products(); // Retrieve an array with all products
print_r($data['products']);
//$data['content'] = 'cart/products'; // Select view to display
//$this->load->view('index', $data); // Display the page
}
Model
public function retive_products() {
$query = $this->db->get("products");
return $query->result_array();
}
I'm using the following from the controller to call a method from the model but receiving and error:
//from the controller:(main.php)
<?php
class Main extends CI_Controller {
public function __construct() {
parent::__construct();
}
function index() {
.....
$this->load->view('view_form');
}//END Fn index()
function get_th() {
//$the=$this->input->post('th', TRUE);
$d['shit']=$this->model_data->tst();
$this->load->view('view_form',$d);
}//END Fn get_th()
}//END Cls Main
?>
//from the model:(model_data.php)
<?php
class Model_data extends CI_Model {
function slider() {
...
}//END Fn slider()
function check_input($data) {
...
}//END Fn check_input()
function tst() {
$tsts= "hellos";
return $this->tsts;
}
}//END Cls model_data
?>
$autoload['model'] = array('model_data');
The error:
Fatal error: Call to undefined method Model_data::tst() in ... application\controllers\main.php...
i think you forgot to load the model in the controller.
$this->load->model('Model_name');
function get_th() {
$this->load->model('model_data');
$d['shit']=$this->model_data->tst();
$this->load->view('view_form',$d);
}
FIXED :/ can t believe I had an additional bracket at the the end of a long file :( wtf
"}"<-- this was the problem.
btw as I said #pramodhkumar use autoload.php.. I had the model autoload so no need for $this->load->...