codeigniter database error notice [closed] - codeigniter

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I have the following code in model:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Membership_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
public function register_user($info)
{
if(isset($info))
{
$data = array(
'fullname' => $info['fullname'] ,
'mobile' => $info['mobile'] ,
'telephone' => $info['home'] ,
'username' => $info['username'] ,
'password' => $info['password'] ,
'email' => $info['email'] ,
'member_type' => $info['memberType']
);
$this->db->insert('users', $data);
}
}
}
and am calling it this way in controller:
$info = array('fullname' => $fullname , 'mobile' => $mobile, 'home' => $home,
'username' => $username, 'password' => $password,
'memberType' => $memberType, 'email' => $email );
$this->membershipModel->register_user($info);
Nevertheless, I am getting this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Membership::$db
Filename: core/Model.php
Line Number: 51
Any idea what that means? regards,

In CodeIgniter, class and method names are case sensitive:
$this->membershipModel->register_user($info);
should read...
$this->Membership_model->register_user($info);
NOTE
Make sure you name your model file as: membership_model.php as specified in the CodeIgniter documentation.

Related

How to fetch Rapidapi in laravel Controller?

I am trying to fetch API using unirest in my laravel application. I followed all the steps given in the docs but it's showing me an error. If there is a better alternative for unirest please let me know. Thanks in advance!
Here is my controller,
public function store(Request $request)
{
Love::create(
request()->validate([
'name_1' => ['required','max:255'],
'name_2' => ['required','max:255'],
],
[
'name_1.required' => 'You have to Enter Your name',
'name_2.required' => 'You have to Enter Your Crush name'
]));
$headers = array('Accept' => 'application/json');
$response = Unirest\Request::post("API_URL",
array(
"X-RapidAPI-Key" => "API_KEY"
)
);
dd($response);
return view("result");
}
Error
Class 'App\Http\Controllers\Unirest\Request' not found
You need to import the Unirest\Request class.
<?php
namespace Your\Namespace;
use Unirest\Request;
class YourClass{
...
If you don't import it, it will by default look for the class in the current namespace (in your case, App\Http\Controllers).

How to configure CreditCard class in Omnipay?

I've been trying to configure Omnipay in CodeIgniter all day long, I think I'm finally cracking it up, but I'm stuck at the credit card validation part. For some reason when I run my I get the error message Fatal error: Class 'CreditCard' not found in C:\xampp\htdocs\trabajo\emarket\application\controllers\inicio.php on line 37
This is my controller:
use Omnipay\Omnipay;
class Inicio extends CI_Controller {
public function index()
{
$gateway = Omnipay::create('PayPal_Pro');
$gateway->setUsername('######');
$gateway->setPassword('######');
$gateway->setSignature('#####');
$gateway->setTestMode(true);
$gateway->initialize();
$cardInput = array(
'firstName' => 'buyer',
'lastName' => 'one million',
'number' => '4032031186341789',
'company' => 'Visa',
'billingAddress1' => 'bill me here',
'billingAddress2' => 'or maybe here',
'billingPhone' => '4085873015',
'billingCity' => 'chicago',
'billingState' => 'illinois',
'billingPostCode' => '646960',
'shippingAddress1' => 'ship it here',
'shippingAddress2' => 'or ship here',
'shippingPhone' => '98789987',
'shippingCity' => 'chicago',
'shippingState' => 'illinois',
'shippingPostCode' => '989898',
);
$card = new CreditCard($cardInput);
}
}
Thanks for your time, I'd really appreciate some pointers on what I'm doing wrong.
Classes are loaded, but you need to point at those. And you are doing that with keyword use. Otherwise you could pass something like:
$gateway = Omnipay\Omnipay::create('PayPal_Pro');//not quite sure if you need backslash infront of vendor name
Or same way you could invoke CreditCard instance:
$card = new Omnipay\Common\CreditCard($cardInput);
That is reason of having keyword use.
This is good topic source.

Expression Engine Module tables and datasort

I am currently working on a custom module add-on and I wanted to be able to use sorting and filtering on the a table in my control panel admin. I am using the EE table class and form helper. I'm trying to follow the documentation here for setting it up, but when I call try to call the '_datasource' method in my class I get this error
Fatal error: Call to undefined method Content_publish::_datasource() in /home/public_html/system/expressionengine/libraries/EE_Table.php on line 162
I have a feeling it's a scoping issue, but in the table class '$this->EE->table->datasource()' method you are supposed to just pass a string value with the name of your datasource function which is what I'm doing.
I don't seem to be the only one with this issue. There are more details and code examples on this EE Discussion forum thread
The documentation is not really clear. I also tried looking at EE's own comments module to see if i could figure it out, but no luck. Anyone have experience with this?
Here is the method I'm calling:
$data = $this->EE->table->datasource('_datasource');
And this is my function in my class:
function _datasource()
{
// ....
// $query comes from DB result set code above.
// I have omitted it here for brevity
$datarows = array();
foreach ($query->result_array() as $key => $row)
{
$datarows[] = array(
'entry_id' => $row['entry_id'],
'date' => date('Y-m-d',$row['entry_date']),
'author' => $row['screen_name'],
'payment' => $payment_amount,
'status' => $status,
'title' => $edit_href.$row['title']."</a>"
);
}
return $datarows;
}
Your datasource callback function must be on your Module_mcp class (looking at your forum thread you are trying to use it on a plugin which would explain the error).
If you want to put the datasource method on a different class, then just add this line right before you call datasource() to trick the table library into using the correct class:
// ensure table callbacks use this class rather than our MCP file
$this->EE->_mcp_reference =& $this;
$data = $this->EE->table->datasource('_datasource');
The table and form_validation libraries are the only two which use the special _mcp_reference variable, so I can't see any side effects to changing it, and have successfully done this in at least two modules.
On a side note, if you want a good example of how to use the built in tablesorter, take a look at system/expressionengine/controllers/cp/members.php. The documentation is pretty bad, but the source code always tells the truth :)
I've been having issues too and have a mixed solution of generate() and datasource working. Here it is here:
In my mcp file:
public function index()
{
$this->EE->cp->set_variable('cp_page_title', lang('my_module_name'));
$data = $this->EE->table->datasource('_datasource');
return $this->EE->load->view('index', $data, TRUE);
}
public function _datasource()
{
$headers = array(
'name' => array('header' => 'Name'),
'color' => array('header' => 'Color'),
'size' => array('header' => 'Size')
);
$rows = array(
array('name' => 'Fred', 'color' => 'Blue', 'size' => 'Small'),
array('name' => 'Mary', 'color' => 'Red', 'size' => 'Large'),
array('name' => 'John', 'color' => 'Green', 'size' => 'Medium'),
);
return array(
'rows' => $rows,
'headers' => $headers
);
}
In my index view file:
$this->table->set_columns($headers);
$this->table->set_data($rows);
echo $this->table->generate();
Seems to be working at the moment and I've not tried pagination yet, but sorting works.

Yii CGridView and dropdown filter [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I created dropdown filter, it's display, but don't worked right. As I anderstand trouble in search() method
view:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter' => $model,
'columns'=>array(
array(
'name' => 'client_id',
'filter' => CHtml::listData(Client::model()->findAll(), 'client_id', 'name'),
'value'=>'$data->client->name'
),
'task'
)
));
I have to tables, and they relations are shown down
model:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'client' => array(self::BELONGS_TO, 'Client', 'client_id'),
);
}
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->with = array('client');
$criteria->compare('task_id',$this->task_id);
$criteria->compare('client_id',$this->client_id);
$criteria->compare('name',$this->client->name);
$criteria->compare('task',$this->task,true);
$criteria->compare('start_date',$this->start_date,true);
$criteria->compare('end_date',$this->end_date,true);
$criteria->compare('complete',$this->complete);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
I anderstand my mistake, my controller should look like this:
public function actionIndex()
{
$model=new Tasks;
if(isset($_REQUEST['Tasks']))
$model->attributes=$_GET['Tasks'];
$this->render('index',array(
'model'=>$model
));
}
I forgout pass parametrs from controller to model. Thx all!
Check rules method. client_id should be in safe for search
public function rules()
{
return array(
array('client_id', 'safe', 'on'=>'search'),
);
}
Check this wiki, it explains exactly what you need in a detailed way.

CodeIgniter form validation multilanguage labels

I'm currently working on a website that can be viewed in 3 different languages. I've put all text into languages files and almost everything is working as expected.
Things like configuration for pagination I've put into a configuration file and into application/config, like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['num_links'] = 2;
$config['full_tag_open'] = '<p class="pagination">';
$config['full_tag_close'] = '</p>';
$config['first_link'] = '« ' . lang('first');
$config['last_link'] = lang('last') . ' »';
And it works great, but I've tried the same for my form validation configuration file, like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'login' => array(
array(
'field' => 'login_email',
'label' => lang('emailaddress'),
'rules' => 'trim|required|valid_email|min_length[6]'
),
array(
'field' => 'login_password',
'label' => lang('password'),
'rules' => 'trim|required'
),
),
But this doesn't seem to work. It looks like this configuration file gets loaded before the language files/library.
And to be honest, at the moment I don't really have an idea how to fix this other than taking everything out of the configuration file again, and put it into the controller, but I'd rather not do this.
Any ideas how to fix this?
if you check how field translation is done when defining form validation rules (see example below and consider the second argument):
$this->form_validation->set_rules('first_name', 'lang:first_name', 'required');
you can see where you are doing wrong in your actual code.
instead of:
array(
'field' => 'login_password',
'label' => lang('password'),
'rules' => 'trim|required'
),
the way to go is:
array(
'field' => 'login_password',
'label' => 'lang:password',
'rules' => 'trim|required'
),
#Krishna Raj K
i use a trans function like you. And i have fixed it.
one more thing that i use wiredesignz hmvc.
MY_Form_validation.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/** application/libraries/MY_Form_validation **/
class MY_Form_validation extends CI_Form_validation
{
public $CI;
protected function _translate_fieldname($fieldname)
{
// Do we need to translate the field name? We look for the prefix 'trans:' to determine this
if (sscanf($fieldname, 'trans:%s', $line) === 1 )
{
return trans($line);
}
return $fieldname;
}
}
rules in model
'parent_id' => array(
'field'=>'parent_id',
'label'=>'trans:main.taxonomy.column.parent_id.name',
'rules'=>'is_natural_no_zero',
),
and in controller, you must load according to this order
//helper
$this->load->helper(array('array','form','anhtocon','trans'));
//library
$this->load->library(array('Nested_set','form_validation'));
$this->form_validation->CI =& $this;
//model
$this->load->model('taxonomy_model');

Resources