Message: Call to undefined method CI_Input::manufacturer() - codeigniter

can somebody tell me what's wrong with this code? This is located in my controller. I have an error message "Message: Call to undefined method CI_Input::manufacturer()"
public function edit_manufacturer(){
$this->load->helper("security");
$id = $this->uri->segment(3);
if($this->input->manufacturer('submit')){
$manufacturer_name = $this->security->xss_clean($this->input->manufacturer('manufacturer_name'));
$this->asset_model->edit_manufacturer($manufacturer_id, $manufacturer_name);
}
}

input is a reserved class from CodeIgniter and the methods are the following
$this->input->post();
$this->input->get();
$this->input->cookie();
$this->input->server();
therefore, manufacturer method doesn't exist unless you modified this class and created the method.
Maybe what you want to do is:
$this->input->post('manufacturer');
or
$this->input->post('submit');
For more information visit Input Class Documentation

Related

Accessing Property of a method from another method inside a class in Laravel

I want to Access the property "na" of "ha" public method from "test" method in same class. But I am getting error "Trying to get property 'ni' of non-object"
public function ha(){
$ni = 'fs';
$nin = 'adfsfsfs';
}
public function test()
{
echo $this->ha()->ni;
}
Variables inside a method are only available inside that method. You should either define on your class or return the values from the method and call the method to get the values. Also please note that this is not about laravel, but it's about php. For more information about variable scope: check this

why im getting error count(): Parameter must be an array or an object that implements Countable in laravel?

I tried to define a local scope in my project to show popular(most downloaded)in my Home Page...so this is my File Model codes:
public function scopePopular($query)
{
return $query->orderBy('file_download_num');
}
As you know "file_download_num" is the field in database im trying to get data from...
so this is how I used this scope in my HomeController:
$popularFiles = File::Popular()->get();
I didn't use count() method in my Controller or Model!But still getting Error!so any suggestion?
notice:php version is 7.3
I found that adding a toArray() method in controller can help count() method work correctly...it worker for me...so controller should be like this:
$popularFiles = File::Popular()->get()->toArray();

Joomla Ajax Request Error

I got following error
Method get_slotsAjax does not exist
my call in healper file
xmlhttp.open("GET","?option=com_ajax&module=quickcontact&method=get_slots&format=json",true);
my function call
public function get_slots()
{
....
}
Went by this documentation.
What am I Missing?
Your method name must end with "Ajax" as mentioned in the documentation.
NOTE: All methods must end in Ajax.
For example:
method=mySuperAwesomeMethodToTrigger will call
mySuperAwesomeMethodToTriggerAjax
So your method name would be as there in the error
get_slotsAjax

Extending Form Validation in Codeigniter call to a member function on a non-object error

I know this has been asked before, and I've looked through every answer posted, but to no avail. Basically, I am trying to extend the Codeigniter form validation library on a CI2+ project, but every single time I get the error:
Fatal error: Call to a member function get_errors_array() on a non-object
Below is my code:
application/core/CB_Form_validation.php
class CB_Form_validation extends CI_Form_validation{
function __construct($rules = array()) {
parent::__construct($rules);
log_message('debug', "CB_Form_validaiton class initialized");
}
public function get_errors_array() {
return $this->_error_array;
}
}
and then in my ajax file I have the construct etc.
public function save(){
if($this->form_validation->run() == FALSE){
}
}
and inside that if statement I have tried the following:
echo $this->form_validation->get_errors_array();
echo $this->cb_form_validation->get_errors_array();
echo get_errors_array();
I have also tried placing the CB_Form_validation.php in application/libraries as well. Just as well, I have also tried this in my construct of my ajax controller
$this->load->library('CB_Form_validation');
$this->load->library('core/CB_Form_validation');
And I have set CB_ as my custom class prefix
Turns out that to fix this, you should do the following:
Move your custom form validation class to the application/libraries folder
You can keep the construct of your custom class how it is
Use $this->form_validation->method() to access the function you would like
As long as your loading the form_validation library, you don't need to perform $this->load->library('custom_class') because CI picks up on your custom prefix anyways
Hope this helps someone

Zend Framework: Incomplete object error when passing a value from controller to view

I'm passing a user object from the controller to the view, then calling a method on that controller. I've done a print_r on the object in the view, so I know it's the right object with the right values. The current_user variable is an instance of the user class.
Here is the line in the layout that gives the error.
<?php echo $this->current_user->get_avatar_url(); ?>
Here is the method in the user class it's calling
public function get_avatar_url()
{
return !empty($this->avatar) ? $this->avatar : $this->fb_userid != '' ? "http://graph.facebook.com/".$this->fb_userid."/picture" : "/public/images/pukie.jpg";
}
This is the error I get
Fatal error: main() The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "User" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /home/breathel/public_html/application/views/layouts/layout.phtml on line 48
I'm including the full controller base where this in called in case it makes a difference
<?php
Zend_Loader::loadClass('Zend_Controller_Action');
Zend_Loader::loadClass('User');
class BaseController extends Zend_Controller_Action
{
protected $auth;
protected $current_user;
protected $db;
protected function initialize_values()
{
$auth = Zend_Auth::getInstance();
if($auth->hasIdentity())
{
$this->current_user = $auth->getIdentity();
$this->view->current_user = $this->current_user;
}
$this->db = Zend_Registry::get('dbAdapter');
$this->view->controller_name = $this->_request->getControllerName();
$this->view->view_name = $this->_request->getActionName();
}
}
Zend Framework's authorisation module uses sessions to preserve identity across page load and is probably serialising the User model under the covers (especially if you're just assigning the result of a Zend_Auth_Adapter call).
Try including the User class before the first call to getIdentity() and see if that fixes it (even if you're confident you're not serialising it yourself).

Resources