Fatal error: Call to a member function getKeyName() - joomla

I am new in joomla . i have created a joomla component and when i click on new button in admin then i am getting such error.
Fatal error: Call to a member function getKeyName() on a non-object in C:\xampp\htdocs\Joomla1\libraries\joomla\application\component\modeladmin.php on line 801
Please help

The problem is cause by your JTable class. Make sure you have correct filename and class name in administrator/components/com_YOUREXTENSION/tables/
You can find example in any core Joomla extension.

public function getTable($type = 'Category', $prefix = 'CatalogTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
Check your $prefix param!I also just this faulty. My component is: com_catalog, and the $prefix = 'CatalogTable'

Related

How can i get current module name [nwidart/laravel-modules]

How can i get current module name, or current namespace. of laravel
I use this library [nwidart/laravel-modules].
I trid this code but not solve problem
$module_name = basename(__FILE__, '.module');
To get module entity: $module = Module::find('blog');
To get module name: $module->getName();
This is documented pretty well by package author here:
https://nwidart.com/laravel-modules/v1/advanced-tools/module-methods
Add this to your modules __construct controller :
private $module_name;
public function __construct()
{
$class = get_called_class(); // or $class = static::class;
$arr_class = explode("\\", $class);
$this->module_name = $arr_class[1];
}
public function index()
{
echo $this->module_name;
}

Laravel error "Declaration of model/model_name should be compatible with Illuminate\Database\Eloquent\Model"

i am facing a strange issue regarding laravel application. after updating the composer on my production server i am getting this error. My login page showing fine and when i am entering the credentials its showing this error either the credentials wrong or right its always showing the same error.
Error is
Declaration of App\Models\User::update($a_data = NULL, $a_conditions = NULL) should be compatible with Illuminate\Database\Eloquent\Model::update(array $attributes = Array, array $options = Array)
i have searched on internet but found nothing. Please do help. will be thankful.
When overriding a method from parent class - the signature of the method must be exactly the same in terms of parameters and their types
In the parent class, both $attributes and $options are set to be of type array, so you must also set set them this way in your class
namespace App\Models;
class User extends \Illuminate\Database\Eloquent\Model {
...
public function update(array $attributes = [], array $options = []) {
// ... your implementation
return parent::update($attributes, $options);
}
...
}

Issue in dynamic model loading in Laravel 5.6

I am trying to load models dynamically in my controller based on route type. But when I run program I get a message saying "class not found". Here is my code and a link of stackoverflow which I used to fix my issue.
Code:
$model = $this->getModelName($request->matchType);
$class = "App\Models\$model";
if($model && class_exists($class))
{
$data = $class::where('type_id',$type)->firstOrFail();
}
else
{
$data = MyModel::find($type);
}
return $this->showOne($data);
Link:
Load in models dynamically in Laravel 5.1
This is a good link but not working for me and why simple $model::all() not working.
You need to use double backslashes:
$class = "App\\Models\\$model";
Try using the app helper to resolve the model:
$data = app($class)->where('type_id',$type)->firstOrFail();
Add another slash to your class name:
$class = "\App\Models\$model";
instead of :
$class = "App\Models\$model";

Fatal error: Class 'CI_Model' not found on production server, works locally

We're building a web application with CodeIgniter 2.1.4. It's in the crawling stages. Right now, it only has a basic logging and registering system.
What we've so far functions as expected locally, but when we try it online, we get the following error:
Fatal error: Class 'CI_Model' not found in /home4/csurmeli/public_html/other/ems/system/core/Common.php on line 174
It doesn't make any sense since we haven't changed any of the core files. And our online server is well established.
Any suggestions?
The controller calling login:
function login(){
if($this->session->userdata('userid') !== false){
redirect(base_url()."index.php/users/success");
}
$data['error'] = 0;
if($_POST){
$this->load->model('user');
$username = $this->input->post('username',true);
$password = $this->input->post('password',true);
$user = $this->user->login($username,$password);
if(!$user){
$data['error']=1;
redirect(base_url()."index.php/users/error");
}else{
$this->session->set_userdata('userid',$user['userid']);
$this->session->set_userdata('privilege',$user['privilege']);
redirect(base_url()."index.php/users/success");
}
}
$this->load->view('header');
$this->load->view('login',$data);
$this->load->view('footer');
}
Model:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class User Extends CI_Model{
public function __construct(){
parent::__construct();
}
function create_user($data){
if($data['is_sent']){
$query = array("username" => $data['username'],
"password" => $data['password'],
"email" => $data['email']
);
$this->db->insert('users',$query);
}
}
function login($username,$password){
$where = array(
'username'=>$username,
'password'=>$password
);
$this->db->select()->from('users')->where($where);
$query = $this->db->get();
return $query->first_row('array');
}
}
?>
if it works locally - its probably just an issue on the main index.php page
in index.php find the banners: SYSTEM FOLDER NAME and APPLICATION FOLDER NAME
then double check that the file path and the folder names are correct for your server.

difference between Mage::app and Mage:: in Magento

Can any body say what is the difference between
Mage:app and Mage::
eg:
Mage::getModel('catalog/product');
Mage::app->getLayout->createBlock('catalog/product_view');
if i try like this
Mage::app->getModel('catalog/product');
it throws a fatal error
What is the basic difference?
As a more general explanation and further to Alan's answer Mage::app() and Mage::getModel() are both static methods of the Mage class (app/Mage.php).
The Mage::app() function is used to bootstrap your Magento application (setting up configuration, autoloading etc) and is useful when wanting to access Magento models in your own custom script for example.
It is a static method so it can also be called at any point in your application to return the current Mage_Core_Model_App object which you can use for example to get current configuration values e.g. Mage::app()->getStore() will return the current Mage_Core_Model_Store store object.
Mage::app() is similar to Mage::run() found in your index.php file. The difference is that Mage::run() will amongst other things also invoke the MVC, routing etc part of your application as per default and control the request/response directing you to a page and instantiating the blocks and layout template rendering.
Mage::getModel() is simply a factory method that will return a new instance of a class based on the class alias you provide. For example Mage::getModel('customer/customer') will return a new Mage_Customer_Model_Customer object. If you want the same object back each time throughout your request you can use Mage::getSingleton() instead.
When you say
Mage::getModel('catalog/product');
You're calling the static method getModel on the class Mage
#File: app/Mage.php
public static function getModel($modelClass = '', $arguments = array())
{
return self::getConfig()->getModelInstance($modelClass, $arguments);
}
When you say
Mage::app->getModel('catalog/product');
you're going to get a fatal error, because that's invalid PHP.
However, if you say
$app = Mage::app();
You're calling the static method app on the Mage class
public static function app($code = '', $type = 'store', $options = array())
{
if (null === self::$_app) {
self::$_app = new Mage_Core_Model_App();
self::setRoot();
self::$_events = new Varien_Event_Collection();
self::$_config = new Mage_Core_Model_Config();
Varien_Profiler::start('self::app::init');
self::$_app->init($code, $type, $options);
Varien_Profiler::stop('self::app::init');
self::$_app->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
}
return self::$_app;
}
which will return a Mage_Core_Model_App object, which will let you call any method on the class/object at
app/code/core/Mage/Model/App.php

Resources