Fatal error: Call to a member function loadByOption() on a non-object - joomla1.5

I am facing a problem. I have got following error "Fatal error: Call to a member function loadByOption() on a non-object in /var/www/Joomla/administrator/components/com_vodes/models/config.php on line 58". I am using Joomla 3.3.3 . I have upgraded it from 1.5 to 3.3.3
function save()
{
// initialize variables.
$table = JTable::getInstance('component');
$params = JRequest::getVar('params', array(), 'post', 'array');
$row = array();
$row['option'] = 'com_vodes';
$row['params'] = $params;
// load the component data for com_ajaxregister
if (!$table->loadByOption('com_vodes')) {
$this->setError($table->getError());
return false;
}
// bind the new values
$table->bind($row);
// check the row.
if (!$table->check()) {
$this->setError($table->getError());
return false;
}
// store the row.
if (!$table->store()) {
$this->setError($table->getError());
return false;
}
return true;
}
Please help to sought it out.

$table = JTable::getInstance('component');
you are passing the wrong parameter in your getInstance function the getInstance function returns null which makes the $table variable a non-object because it has no value. use your component name in setting the parameter.

Related

Promise working without resolving it in protractor

The below is my page object code
this.getRowBasedOnName = function (name) {
return this.tableRows.filter(function (elem, index) {
return elem.element(by.className('ng-binding')).getText().then(function (text) {
return text.toUpperCase().substring(0, 1) === name.toUpperCase().substring(0, 1);
});
});
};
the above function is called in the same page object in another function, which is
this.clickAllProductInProgramTypeBasedOnName = function (name) {
this.getRowBasedOnName(name).then(function (requiredRow) {
requiredRow.all(by.tagName('label')).get(1).click();
});
};
but the above code throws an error in the console as requiredRow.all is not a function
but when i do the following :
this.clickAllProductInProgramTypeBasedOnName = function (name) {
var row = this.getRowBasedOnName(name)
row.all(by.tagName('label')).get(1).click();
};
this works fine and clicks the required element.
But this.getRowBasedOnName() function returns a promise, which should and can be used after resolving it uisng then function. How come it is able to work by just assigning it to a variable?
When you resolve the result of getRowBasedOnName(), which is an ElementArrayFinder, you get a regular array of elements which does not have an all() method.
You don't need to resolve the result of getRowBasedOnName() at all - let it be an ElementArrayFinder which you can chain with all() as in your second sample:
var row = this.getRowBasedOnName(name);
row.all(by.tagName('label')).get(1).click();
In other words, requiredRow is not an ElementArrayFinder, but row is.

Cannot call method 'id' of undefined

My world.js looks like this:
var protractor = require('protractor');
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().usingServer('xxxxx').
withCapabilities(webdriver.Capabilities.firefox()).build();
driver.manage().timeouts().setScriptTimeout(100000);
module.exports.World = function World(callback) {
this.browser = protractor.wrapDriver(driver);
this.by = protractor.by;
callback();
};
then in steps.js:
{
element(by.id('username')).sendKeys("admin");
}
When I ran it using cucumber.js, the error is:
TypeError: Cannot call method 'id' of undefined
but if I remove world.js and run it using protractor, it works.
How can I fix this?
It looks like you're not exporting by globally. I'm not sure why you're able to use the element function at all - but in any case, you should probably be doing something like:
module.exports.World = function World(callback) {
global.browser = protractor.wrapDriver(driver);
global.by = protractor.by;
};

htmlspecialchars() expects parameter 1 to be string, array given in for zend

I have an error in file : Abstract.php
Warning: htmlspecialchars() expects parameter 1 to be string,array given in /usr/local/zend/share/ZendFramework/library/Zend/View/Abstract.php on line 905
I have this on line 905 :
public function escape($var)
{
if (in_array($this->_escape, array('htmlspecialchars', 'htmlentities'))) {
return call_user_func($this->_escape, $var, ENT_COMPAT, $this->_encoding);
}
if (1 == func_num_args()) {
return call_user_func($this->_escape, $var);
}
$args = func_get_args();
return call_user_func_array($this->_escape, $args);
}
i don't understand this...
Probably you added array to $this->escape() function.
If you don''t know where then add to file Abstract.php something like this:
if(is_array($var)){
Zend_Debug::dump($var);//this will print variable causing problem
//OR
throw new Exception(' ');//this will print debug backtrace showing which line caused problem
}
I was having same issue on lib/Varien/Data/Form/Element/Abstract.php
I did update below
protected function _escape($string)
{
return htmlspecialchars($string, ENT_COMPAT);
}
with
protected function _escape($string)
{
if(is_string($string)) {
return htmlspecialchars($string, ENT_COMPAT);
}
else
{
return $string;
}
}
Thing started to work.

Call to undefined method Application_Model_DbTable_Projects::lastInsertId()

I want to retrieve the id of the last inserted row. This is the code I use in the mapper:
public function save(Application_Model_Projects $project)
{
$data = array(
'id_user' => $project->getIdUser(),
'project_name' => $project->getProjectName(),
'project_description' => $project->getProjectDescription(),
'due_date' => $project->getDueDate(),
'id_customer' => $project->getIdCustomer()
);
if(($id = $project->getId()) === null) {
unset($data['id']);
$this->getDbTable()->insert($data);
return $this->getDbTable()->lastInsertId();
}else {
$this->getDbTable()->update($data, array('id = ?', (int) $id));
return $id;
}
}
According to the code above, it should return the id of the object. It is either the id after insertion or the current id.
The code where I use this function:
$currentUser = new Application_Model_UserAuth();
$project = new Application_Model_Projects();
$project->setProjectName($formValues['projectName'])
->setProjectDescription($formValues['projectDescription'])
->setDueDate(date("Y-m-d",strtotime($formValues['dueDate'])))
->setIdCustomer($formValues['assignCustomer'])
->setIdUser($currentUser->id);
$projectMapper = new Application_Model_ProjectsMapper();
$idProject = $projectMapper->save($project);
The error I get is:
Fatal error: Call to undefined method Application_Model_DbTable_Projects::lastInsertId()
What is wrong with this? Shouldn't that return the last id? Because it is triggered upon insertion. In another sequence of code I call the lastInsertId: $Zend_Db_Table::getDefaultAdapter()->lastInsertId(). The only difference is that now I call lastInsertIt on a dbTable, that extends Zend_Db_Table_Abstract.
The answer to my question above is that I should call getAdapter() before lastInsertId().
Updated code:
if(($id = $project->getId()) === null) {
unset($data['id']);
$this->getDbTable()->insert($data);
return $this->getDbTable()->getAdapter()->lastInsertId();
}
If it is an single-column Primary Key the return value is lastInsertId by default, so you also can use this:
return $this->getDbTable()->insert($data);

How to use the Zend_Log instance that was created using the Zend_Application_Resource_Log in a model class

Our Zend_Log is initialized by only adding the following lines to application.ini
resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.mode = "a"
So Zend_Application_Resource_Log will create the instance for us.
We are already able to access this instance in controllers via the following:
public function getLog()
{
$bootstrap = $this->getInvokeArg('bootstrap');
//if (is_null($bootstrap)) return false;
if (!$bootstrap->hasPluginResource('Log')) {
return false;
}
$log = $bootstrap->getResource('Log');
return $log;
}
So far, so good.
Now we want to use the same log instance in model classes, where we can not access the bootstrap.
Our first idea was to register the very same Log instance in Zend_Registry to be able to use Zend_Registry::get('Zend_Log') everywhere we want:
in our Bootstrap class:
protected function _initLog() {
if (!$this->hasPluginResource('Log')) {
throw new Zend_Exception('Log not enabled');
}
$log = $this->getResource('Log');
assert( $log != null);
Zend_Registry::set('Zend_Log', $log);
}
Unfortunately this assertion fails ==> $log IS NULL --- but why??
It is clear that we could just initialize the Zend_Log manually during bootstrapping without using the automatism of Zend_Application_Resource_Log, so this kind of answers will not be accepted.
This is the final solution. We basically shall not call the function _initLog()
Big thanks to ArneRie!
// Do not call this function _initLog() !
protected function _initRegisterLogger() {
$this->bootstrap('Log');
if (!$this->hasPluginResource('Log')) {
throw new Zend_Exception('Log not enabled in config.ini');
}
$logger = $this->getResource('Log');
assert($logger != null);
Zend_Registry::set('Zend_Log', $logger);
}
Possible it is not bootstraped at this time, try:
try {
$this->bootstrap('log'); // bootstrap log
$logger = $this->getResource('log');
} catch (Zend_Application_Bootstrap_Exception $e) {
$logger = new Zend_Log();
$writer = new Zend_Log_Writer_Null();
$logger->addWriter($writer);
}
$registry = Zend_Registry::set('logger', $logger);