I am trying to fix this for while but I can't. I found several tutorials but I couldn't fix it.
My friend and I are working on the same version, and it works on his PC without any problem - but for me it won't. We are using the same files, I copied mine from him.
What is the matter here and why won't this work on my PC?
Here is my index.php
<?php
/* #var $this SystemManagementController */
/* #var $dataProvider CActiveDataProvider */
?>
<?php
$this->breadcrumbs = array(
Yii::t('mainmenu', 'System Management'),
);
$contentTabUsers = $this->renderPartial('_tab_users', array(
'model' => $userModel,
'columns' => $userColumns,
), $return = true);
$contentTabStates = $this->renderPartial('_tab_states', array('model' => $stateModel), $return = true);
$contentTabPriorities = $this->renderPartial('_tab_priorities', null, $return = true);
$contentTabProperties = $this->renderPartial('_tab_properties', null, $return = true);
$upgradeLog = 'tbd'; //new UpgradeLog();
$systemInfo = new SystemInfo();
try
{
$systemInfoData = array(
'System Info' => $systemInfo->getServerInfo(),
'Apache' => $systemInfo->getApacheInfo(),
'MySQL Info' => $systemInfo->getMysqlInfo(),
);
}
catch (Exception $ex)
{
Yii::log('Could not retrieve system info, exception thrown with message: ' . $ex->getMessage(), CLogger::LEVEL_ERROR);
$systemInfoData = array();
}
$contentTabSysinfo = $this->renderPartial('_tab_sysinfo', array(
// 'model' => $upgradeLog,
// 'upgradeLogDataProvider' => $this->getUpgradeLogDataProvider(),
// 'upgradeScripts' => $this->getAllInfoUpgradeScripts(),
'systemInfo' => $systemInfoData,
'phpinfo' => $this->getBasicPhpInfo(),
), $return = true
);
// get the filter value to show max lines
$showMaxLines = (int) $this->getAppRequest()->getParam('log_show_max_lines', 50);
$contentTabLog = $this->renderPartial('_tab_log', array(
'applicationLog' => $this->getLog($showMaxLines),
'showMaxLines' => $showMaxLines,
// 'log_show_max_lines' is a placeholder for the js value in the template
'filterUrl' => $this->getYiiApp()->createUrl('systemManagement/index', array('log_show_max_lines' => null)),
), $return = true
);
Yii::app()->user->setState('activeSystemmanagementTab', 'system_info');
$tabs = array();
if (Yii::app()->user->checkAccess('Systemmanagement.users'))
{
$tabs[Yii::t('systemmanagement', 'Users')] = array('content' => $contentTabUsers, 'id' => 'users');
}
if (Yii::app()->user->checkAccess('Systemmanagement.states'))
{
$tabs[Yii::t('systemmanagement', 'States')] = array('content' => $contentTabStates, 'id' => 'states');
}
if (Yii::app()->user->checkAccess('Systemmanagement.priorities'))
{
$tabs[Yii::t('systemmanagement', 'Priorities')] = array('content' => $contentTabPriorities, 'id' => 'priorities');
}
if (Yii::app()->user->checkAccess('Systemmanagement.properties'))
{
$tabs[Yii::t('systemmanagement', 'Properties')] = array('content' => $contentTabProperties, 'id' => 'properties');
}
if (Yii::app()->user->checkAccess('Systemmanagement.sysinfo'))
{
$tabs[Yii::t('systemmanagement', 'System Info')] = array('content' => $contentTabSysinfo, 'id' => 'system_info');
}
if (Yii::app()->user->checkAccess('Systemmanagement.log'))
{
$tabs[Yii::t('systemmanagement', 'Log')] = array('content' => $contentTabLog, 'id' => 'log');
}
$this->widget('zii.widgets.jui.CJuiTabs', array(
'tabs' => $tabs,
// additional javascript options for the tabs plugin
'options' => array(
'collapsible' => true,
'hide' => 'fade',
'activeTab' => Yii::app()->user->getState('activeSystemmanagementTab'),
// 'show' => 'highlight',
//TODO #see http://www.bsourcecode.com/2012/11/how-to-handle-cjuitabs-in-yii/
'selected' => isset(Yii::app()->session['tabid']) ? Yii::app()->session['tabid'] : 0,
'select' => 'js:function(event, ui) {
var index=ui.index;
$.ajax({
"url":"' . Yii::app()->createUrl('site/tabidsession') . '",
"data":"tab="+index,
});
}',
)
)
);
?>
<script type="text/javascript">
function changeIsactive(id)
{
$.ajax({
type: 'post',
url: "<?php echo Yii::app()->createUrl('usp/AjaxSetuspOnOff') ?>",
datatype: 'json',
data: "MeId=" + id,
success: function (data) {
// if page access denied show the error msg
var hasError = $("<div></div>").append(data).find("#content div.error").length > 0;
if (hasError)
{
$("#flashmsg").show().addClass('flash-error').html('<?php echo Yii::t('systemwide', 'You Are Not Authorized to Turn On/Off this ELement'); ?>').animate({opacity: 0.9}, 3500).fadeOut("slow");
return false;
} else {
if (data != 'error')
{
if (data)
{
$('#onOff_' + id).addClass(data);
}
else {
$('#onOff_' + id).removeClass('checked');
}
}
else
{
$("#flashmsg").show().addClass('flash-error').html('<?php echo Yii::t('systemwide', 'You Are Not Authorized to Turn On/Off this ELement'); ?>').animate({opacity: 0.9}, 3500).fadeOut("slow");
}
return false;
}
},
error: function (jqXHR, exception) {
$("#flashmsg").show().addClass('flash-error').html('<?php echo Yii::t('systemwide', 'You Are Not Authorized to Turn On/Off this ELement'); ?>').animate({opacity: 0.9}, 3500).fadeOut("slow");
}
});
}
</script>
when I go to the server I get this error:
PHP notice Undefined variable: tabs /var/www/private/protected/views/systemmanagement/index.php(84)
and that is referring to :
'tabs' => $tabs,
in order to fix this I added, the following also on top of my file:
$tabs = array();
Now when I do this, it works and it doesn't give any error, but it just goes to the page and it doesn't show any content. Please help I am spending too much time on this.
if I put this in my code:
print_r($systemInfoData);
I get:
Array ( [System Info] => Array ( [OS] => Linux #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 [Machine Type] => x86_64 [Server Name] => 192.168.33.10 [Server IP Address] => 192.168.33.10 ) [Apache] => Array ( [version] => Apache/2.4.12 (Ubuntu) [Loaded Modules] => core, mod_so, mod_watchdog, http_core, mod_log_config, mod_logio, mod_version, mod_unixd, mod_access_compat, mod_alias, mod_auth_basic, mod_authn_core, mod_authn_file, mod_authz_core, mod_authz_groupfile, mod_authz_host, mod_authz_user, mod_autoindex, mod_cgi, mod_deflate, mod_dir, mod_env, mod_expires, mod_filter, mod_headers, mod_include, mod_mime, prefork, mod_negotiation, mod_php5, mod_reqtimeout, mod_rewrite, mod_setenvif, mod_status ) [MySQL Info] => Array ( [Server version] => 5.5.43-0ubuntu0.12.04.1 [Meta information] => Uptime: 11334 Threads: 1 Questions: 11476 Slow queries: 0 Opens: 76 Flush tables: 1 Open tables: 54 Queries per second avg: 1.012 ) )
The problem is caused by the variable $tabs not being defined.
You have two options, as rightly mentioned by the other contributos:
I. (preferable)
Define you variable before using it.
II. (not recommended)
The error is not shown on your friend's PC because of the error_reporting level set in his/her environment. Edit the error_reporting level defined in your php.ini.
In order to hide the php notices add or edit the following line in the php.ini
error_reporting = E_ALL & ~E_NOTICE;
Alternatively you can set your error reporting level directly from your script as follows:
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
Read more about error reporting in php here: http://php.net/manual/en/function.error-reporting.php
You are getting the Undefined variable error because your $tabs variable is not defined.
You have multiple if statements that could define it, but if they all evaluate to false, it will remain undefined.
Setting $tabs = array(); defines your variable, but it still has no content.
Related
I'm currently developing a fraud detection module for PrestaShop 1.6. In this module, I need to make a call to an API just after the customer presses the button to confirm their order, but before the payment is submitted, regardless of payment gateway.
At first, after looking through all the available hooks in 1.6, I thought about using the actionValidateOrder hook to do this, the problem is that this hook is executed right after the payment is submitted/processed by the payment gateway, which is not what I'm looking for.
I also thought about using javascript to intercept the execution and then calling to a validation controller to perform, but it becomes way too specific for each gateway and the data flow between prestashop objects/ajax/javascript seems like it could turn out to be problematic.
I know you can create a custom hook, but every example I see on internet is about display hooks, none of it shows how to create a custom action hook.
This is what I was using in the actionValidateOrder hook
public function hookActionValidateOrder($params)
{
include_once(_PS_MODULE_DIR_.'bayonet/sdk/Paymethods.php');
$this->order = $params['order'];
$cart = $this->context->cart;
$address_delivery = new Address((int)$cart->id_address_delivery);
$address_invoice = new Address((int)$cart->id_address_invoice);
$state_delivery = new State((int)$address_delivery->id_state);
$country_delivery = new Country((int)$address_delivery->id_country);
$state_invoice = new State((int)$address_invoice->id_state);
$country_invoice = new Country((int)$address_invoice->id_country);
$customer = $this->context->customer;
$currency = $this->context->currency;
$products = $cart->getProducts();
$product_list = array();
foreach($products as $product)
{
$products_list[] = [
"product_id" => $product['id_product'],
"product_name" => $product['name'],
"product_price" => $product['price'],
"product_category" => $product['category']
];
}
$request = [
'channel' => 'ecommerce',
'consumer_name' => $customer->firstname.' '.$customer->lastname,
"consumer_internal_id" => $customer->id,
"transaction_amount" => $cart->getOrderTotal(),
"currency_code" => $currency->iso_code,
"telephone" => $address_invoice->phone,
"email" => $customer->email,
"payment_gateway" => $this->order->module,
"shipping_address" => [
"line_1" => $address_delivery->address1,
"line_2" => $address_delivery->address2,
"city" => $address_delivery->city,
"state" => $state_delivery->name,
"country" => convert_country_code($country_delivery->iso_code),
"zip_code" => $address_delivery->postcode
],
"billing_address" => [
"line_1" => $address_invoice->address1,
"line_2" => $address_invoice->address2,
"city" => $address_invoice->city,
"state" => $state_invoice->name,
"country" => convert_country_code($country_invoice->iso_code),
"zip_code" => $address_invoice->postcode
],
"products" => $products_list,
"order_id" => (int)$this->order->id
];
foreach ($paymentMethods as $key => $value) {
if ($this->order->module == $key)
{
$request['payment_method'] = $value;
if ($this->order->module == 'paypalmx')
$request['payment_gateway'] = 'paypal';
}
}
if (Configuration::get('BAYONET_API_MODE') == 0)
{
$this->bayonet = new BayonetClient([
'api_key' => Configuration::get('BAYONET_API_TEST_KEY'),
'version' => Configuration::get('BAYONET_API_VERSION')
]);
}
else if (Configuration::get('BAYONET_API_MODE') == 1)
{
$this->bayonet = new BayonetClient([
'api_key' => Configuration::get('BAYONET_API_LIVE_KEY_KEY'),
'version' => Configuration::get('BAYONET_API_VERSION')
]);
}
$this->bayonet->consulting([
'body' => $request,
'on_success' => function($response) {
$this->dataToInsert = array(
'id_cart' => $this->context->cart->id,
'order_no' => $this->order->id,
'status' => $response->decision,
'bayonet_tracking_id' => $response->bayonet_tracking_id,
'consulting_api' => 1,
'consulting_api_response' => json_encode(array(
'reason_code' => $response->reason_code,
'tracking_id' => $response->bayonet_tracking_id
)),
'is_executed' => 1,
);
Db::getInstance()->insert('bayonet', $this->dataToInsert);
if ($response->decision == 'decline')
{
$this->module = Module::getInstanceByName('bayonet');
Tools::redirect($this->context->link->getModuleLink($this->module->name,'rejected', array()));
}
},
'on_failure' => function($response) {
$this->dataToInsert = array(
'id_cart' => $this->context->cart->id,
'order_no' => $this->order->id,
'status' => $response->decision,
'bayonet_tracking_id' => $response->bayonet_tracking_id,
'consulting_api' => 0,
'consulting_api_response' => json_encode(array(
'reason_code' => $response->reason_code,
)),
'is_executed' => 1,
);
Db::getInstance()->insert('bayonet', $this->dataToInsert);
}
]);
}
And after detecting the issue with the hook, this is what I tried with JavaScript, which calls a validation page using ajax, this page has almost the same code as what it was in the hook
$('#form-pagar-mp').submit(function(event) {
if (lock == 1) {
params = {};
$.ajax({
url: url,
type: 'post',
data: params,
dataType: 'json',
processData: false,
success: function(data) {
if (data.error == 0) {
lock = 0;
}
else {
window.location.href = data.url;
}
}
});
}
});
I still think using a hook is the best option, but out of all available hooks, none of them meets my needs. Right now, I don't really know that else to try, that's why I need your help in how to approach this situation, any ideas are welcome and will be highly appreciated. Thank you.
You can use a hook which executes before an order payment creation
public function hookActionObjectOrderPaymentAddBefore($params)
{
/** OrderPayment $orderPayment */
$orderPayment = $params['object'];
$cart = $this->context->cart;
// to stop order payment creation you need to redirect from this hook
}
Or before order is created
public function hookActionObjectOrderAddBefore($params)
{
/** Order $order */
$order = $params['object'];
$cart = $this->context->cart;
// to stop order creation you need to redirect from this hook
}
I'm trying to get a complex type from a php server with an operation to get an array of animals (complex type defined in the wsdl), this array is defined as ConjuntAnimals as an array of Animal objects.
But when I do the $result = $client->call('consulta_gossos', $params); I get returned a bool (false). I've been debugging and logging for a long time, and I've seen that inside the soap operation, just before returning, its value is an array of animals (what it should return), but in the client I don't get this returned.
After realizing it, I guess maybe it is the complexType definitions which I have wrong, but I've compared with a lot of examples and shouldn't be this...
Also, (maybe it helps) I get this error logged:
[10-Dec-2016 12:59:11 America/New_York] PHP Catchable fatal error: Object of class stdClass could not be converted to string in /home/cabox/workspace/lib/nusoap.php
on line 6132
[10-Dec-2016 12:59:11 America/New_York] Response not of type text/xml: text/html
I understand it expects an xml response, so I've tried to return json_encode($gossos) instead of just $gossos, but then it logs this:
[10-Dec-2016 13:11:34 America/New_York] XML error parsing SOAP payload on line 2: Invalid document end
Here I add both client and server code:
client:
<?php
require_once('./lib/nusoap.php');
$wsdl='http://php-ad-msk1416368101.codeanyapp.com/soapserver.php?wsdl';
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
$client = new nusoap_client($wsdl,'wsdl');
$client->encode_utf8 = false;
$client->decode_utf8 = false;
$client->soap_defencoding = 'utf-8';
$err = $client->getError();
if ($err) {
echo "Constructor error" . $err;
exit();
}
$edat = $_GET['edat'];
$raca = $_GET['raca'];
$vacunat = $_GET['vacunes'];
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
$result = $client->call('consulta_gossos', array('edat' => $edat, 'raca' => $raca, 'vacunat' => $vacunat));
$err = $client->getError();
error_log($err);
error_log(json_encode($result));
echo 'Type: '.gettype($result).', size: '.sizeOf($result);
?>
`
<?php
require_once('./lib/nusoap.php');
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
error_log( "Hello, errors!" );
$server = new nusoap_server;
$server->soap_defencoding = 'utf-8';
$server->encode_utf8 = false;
$server->decode_utf8 = false;
$server->configureWSDL('server','urn:server');
$server->wsdl->schemaTargetNamespace = 'urn:server';
$server->wsdl->addComplexType('Animal',
'complexType',
'struct',
'all',
'',
array(
'xip' => array('name' => 'xip', 'type' => 'xsd:int'),
'nom' => array('name' => 'nom', 'type' => 'xsd:string'),
'edat' => array('name' => 'edat', 'type' => 'xsd:int'),
'vacunat' => array('name' => 'vacunat', 'type' => 'xsd:string'),
'menjar' => array('name' => 'menjar', 'type' => 'xsd:string'),
'data_entrada' => array('name' => 'data_entrada', 'type' => 'xsd:string'),
)
);
$server->wsdl->addComplexType('ConjuntAnimals',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType',
'wsdl:arrayType'=>'tns:Animal[]')
),
'tns:Animal'
);
$server->register('consulta_gossos',
array('edat' => 'xsd:string',
'raca' => 'xsd:string',
'vacunat' => 'xsd:string'),
array('return' => 'tns:ConjuntAnimals'), //output
'urn:server', //namespace
'urn:server#consulta_gossos', //SOAP action
'rpc',
'encoded',
'Consultar els gossos que compleixen el filtre');//description
function consulta_gossos($edat, $raca, $vacunat) {
$servername = 'localhost';
$username = 'root';
$password = 'root';
$dbname = 'bd_refugi';
$vacunes = ($vacunat =='si') ? 1 : 0;
$sql_edat = ($edat == 'gran') ? ' edat > 5 ' : ' edat <= 5 ';
$connection = new mysqli($servername, $username, $password, $dbname);
$sql = 'select * from gossos where '.$sql_edat.' and raca="'.$raca.'" and vacunat='.$vacunes;
$res = $connection->query($sql);
$gossos = array();
while ($row=$res->fetch_assoc()) {
$gos->xip=$row['xip'];
$gos->nom=$row['nom'];
$gos->edat=$row['edat'];
$gos->vacunat=$row['vacunat'];
$gos->menjar=$row['menjar'];
$gos->data_entrada=$row['data_entrada'];
array_push($gossos,$gos);
}
error_log(json_encode($gossos));
error_log('-----------------------------------------');
return json_encode($gossos);
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
`
Sorry for the indenting, my eyes are bleeding too after copy-pasting the code here.
Edit: leaving aside the errors shown above, the question intends to focus more on why returning a "correct" array, in the client I get an empty array once I've get rid off all these errors.
After several hours of debugging and testing each type individually, I've finally managed to solve this.
I was returning an array composed by what I would call structs (sorry I'm new to PHP, still don't know the slang) build from what I was getting from the mysql query. The thing is that they should have been arrays, so I add the code I've changed:
Before (not working):
$res = $connection->query($sql);
$gossos = array();
while ($row=$res->fetch_assoc()) {
$gos->xip=$row['xip'];
$gos->nom=$row['nom'];
$gos->edat=$row['edat'];
$gos->vacunat=$row['vacunat'];
$gos->menjar=$row['menjar'];
$gos->data_entrada=$row['data_entrada'];
array_push($gossos,$gos);
}
return json_encode($gossos);
After (working):
$res = $connection->query($sql);
$gossos = array();
while ($row=$res->fetch_assoc()) {
$gos = array('xip' => intval($row['xip']),
'nom' => $row['nom'],
'edat' => intval($row['edat']),
'vacunat' => $row['vacunat'],
'menjar' => $row['menjar'],
'data_entrada' => $row['data_entrada'],
'sexe' => $row['sexe'],
'raca' => $row['raca']
);
array_push($gossos,$row);
}
return $gossos;
I also was returning the json encoding (I really don't know why, I guess for trying things...), now I can return the array without getting those errors I had.
Edit: Oh! And commented line 6132 in nusoap.php, without doing it, would still get errors!
im creating a new module for prestashop 1.5.6 and im having some problems with it.
The module has to send sms to the costumers and it has to be an option of the back-Office menu.
I have created the module with the install and uninstall functions and added the tabs to the back-office menu, but im a newbie in prestashop so i don´t know how to make the AdminMyModuleController.php and when i try to click the tab of the module it says "INVALID SECURITY TOKEN", i don´t know how resolve this issue because i don´t know much of security.
If someone can add me on facebook or whatever to help me would be amazing.
Here is the code of the mymodule.php:
private function _createTab()
{
// Tab Raiz
$data = array(
'id_tab' => '',
'id_parent' => 0,
'class_name' => 'Empty',
'module' => 'mymodule',
'position' => 14, 'active' => 1
);
/* Insert the data to the tab table*/
$res = Db::getInstance()->insert('tab', $data);
//Get last insert id from db which will be the new tab id
$id_tabP = Db::getInstance()->Insert_ID();
//Define tab multi language data
$data_lang = array(
'id_tab' => $id_tabP,
'id_lang' => Configuration::get('PS_LANG_DEFAULT'),
'name' => 'SMS a clientes'
);
// Now insert the tab lang data
$res &= Db::getInstance()->insert('tab_lang', $data_lang);
// Tab Configuracion
$data = array(
'id_tab' => '',
'id_parent' => $id_tabP,
'class_name' => 'AdminMymodule',
'module' => 'mymodule',
'position' => 1, 'active' => 1
);
$res = Db::getInstance()->insert('tab', $data);
$id_tab = Db::getInstance()->Insert_ID();
$data_lang = array(
'id_tab' => $id_tab,
'id_lang' => Configuration::get('PS_LANG_DEFAULT'),
'name' => 'Configuracion'
);
$res &= Db::getInstance()->insert('tab_lang', $data_lang);
// Tab Enviar Sms
$data = array(
'id_tab' => '',
'id_parent' => $id_tabP,
'class_name' => 'AdminEnviar',
'module' => 'mymodule',
'position' => 1, 'active' => 1
);
$res = Db::getInstance()->insert('tab', $data);
$id_tab = Db::getInstance()->Insert_ID();
$data_lang = array(
'id_tab' => $id_tab,
'id_lang' => Configuration::get('PS_LANG_DEFAULT'),
'name' => 'Enviar SMS'
);
$res &= Db::getInstance()->insert('tab_lang', $data_lang);
return true;
}
Thanks
As Lliw said, you must use InstallModuleTab function.
private function installModuleTab($tabClass, $tabName, $idTabParent)
{
$pass = true;
$tab = new Tab();
$tab->name = $tabName;
$tab->class_name = $tabClass;
$tab->module = $this->name; // defined in __construct() function
$tab->id_parent = $idTabParent;
$pass = $tab->save();
return($pass);
}
You can put all in your Install function. For example for your first tab:
public function install()
{
if(!parent::install()
|| !$this->installModuleTab('Empty', array(1 => 'SMS a clientes'), $idTabParent = 0))
return false;
return true;
}
You can set languages with the following array:
array(1 => 'SMS a clientes', 2 => 'Language 2', 3 => 'Language 3')
Then you must create the AdminMyModuleController.php file
It's the wrong way to create a module tab. You should use this function in your install() :
$this->installModuleTab('AdminMyModule', array(1 => 'Attribute description'), $idTabParent = 9);
Then create an AdminMyModuleController.php in your module folder/controllers/admin/AdminMyModuleController.php
But you will need to set some function to see something displayed, i'll make a tutorial for that but until i do it, you can look in another admincontroller from the prestashop core and do the same.
I have two controllers:
test.php
public function trackback()
{
$this->load->library('trackback');
$tb_data = array(
'ping_url' => 'http://www.citest.com/addtrackback/receive/777',
'url' => 'http://www.citest.com/test/trackback/',
'title' => 'Заголовок',
'excerpt' => 'Текст.',
'blog_name' => 'Название блога',
'charset' => 'utf-8'
);
if ( ! $this->trackback->send($tb_data))
{
echo $this->trackback->display_errors();
}
else
{
echo 'Trackback успешно отправлен!';
}
}
function trackback() sends the trackback information
addtrackback.php
public function receive()
{
$this->load->library('trackback');
if ($this->uri->segment(3) == FALSE)
{
$this->trackback->send_error("Не указан ID записи ");
}
if ( ! $this->trackback->receive())
{
$this->trackback->send_error("Trackback содержит некорректные данные!");
}
$data = array(
'tb_id' => '',
'entry_id' => $this->uri->segment(3),
'url' => $this->trackback->data('url'),
'title' => $this->trackback->data('title'),
'excerpt' => $this->trackback->data('excerpt'),
'blog_name' => $this->trackback->data('blog_name'),
'tb_date' => time(),
'ip_address' => $this->input->ip_address()
);
$sql = $this->db->insert_string('trackbacks', $data);
$this->db->query($sql);
$this->trackback->send_success();
}
function receive() gets trackback and writes it into a table called 'trackbacks' in the database.
But when I try to view the page, it results in the following error:
An unknown error was encountered.
What's causing this error?
are you referencing the library or the function you're in? if ( ! $this->trackback->send($tb_data))
try changing it to something like
public function trackback(){
$this->load->library('trackbackLibrary');
what are you trying to accomplish because it seems like you're attempting to do an if statement for the same process.
if ($this->uri->segment(3) == FALSE)
{
$this->trackback->send_error("Не указан ID записи ");
}
if ( ! $this->trackback->receive())
{
$this->trackback->send_error("Trackback содержит некорректные данные!");
}
Also,
Check your error_log file to see what the actual error its throwing. /var/log or some other places. Depending on your OS
I am using fancy box iframe to display my page which has the file upload button. when i click form submit i got the "File exceeds the defined ini size". i checked some of links under google and stackoverflow. But not able to find. I have enctype="multipart/form-data" in my form. Following is my code
public function createForm($data = array())
{
$this->setMethod(Zend_Form::METHOD_POST);
$this->setEncType(Zend_Form::ENCTYPE_MULTIPART);
$this->setAttrib('id', 'createsub');
$this->setAction(
$this->getView()->getHelper('url')->url(array(
'controller' => 'test',
'action' => 'create'
))
);
$this->setDecorators(array(
'Description',
'FormElements',
'Form'
));
$fnameNotEmpty = new Zend_Validate_NotEmpty();
$fnameNotEmpty->setMessage('Name cannot be empty.');
$fnameStrlen = new Zend_Validate_StringLength(1, 20);
$name = new Zend_Form_Element_Text('name', array(
'label' => 'Name:',
'value' => '',
'class' => 'text-size text',
'tabindex' => '1',
'required' => true,
'validators' => array(
array($fnameNotEmpty, true),
array($fnameStrlen, true)
),
'decorators' => $this->requiredElementDecorators,
'description' => '<img src="../../'.$baseurl.'/images/star.png" alt="required" />',
'filters' => array('StringTrim')
));
$this->addElement($name);
.... ..... .....
$brochure = new Zend_Form_Element_File('brochure', array(
'label' => 'Brochure:*',
'value' => '',
'class' => 'text-size text',
'tabindex' => '3',
'required' => true,
'filters' => array('StringTrim')
));
$this->addElement($brochure);
$submit = $this->createElement('button','addtbtn',array('class'=>'Test','label'=>'Create'));
$submit->setIgnore(true);
$this->addElement($submit);
return $this;
}
Also if i did not use iframe, I can able to upload my image...Very Strange.
I make the validation using Ajax by following code ,
<script type="text/javascript">
var Path="<?php echo $this->eurl; ?>"
$(function()
{
vReg=0
$("#addtbtn").click(function()
{
if(vReg == 1)
{
return true;
}
else{
var url = 'validateform';
var data = {};
$("input").each(function()
{
data[$(this).attr('name')] = $(this).val();
});
$("select").each(function()
{
data[$(this).attr('name')] = $(this).val();
});
$("textarea").each(function()
{
data[$(this).attr('name')] = $(this).val();
});
$.post(url,data,function(resp)
{
vError=""
for(id in resp){
oResp=resp[id];
for(key in oResp){
vError +=oResp[key]+"\n"
}
}
if(vError == ''){
vReg=1
$("#createform").attr('target','_top');
$("#createform").submit();
return true;
}
else{
$("#createform").attr('target','_self');
alert(vError)
return false;
}
},'json');
}
});
});
</script>
Also Has the following function in my controller
public function validateformAction()
{
$this->_helper->viewRenderer->setNoRender();
$this->_helper->getHelper('layout')->disableLayout();
$p = new Admin_Model_DbTable_Test();
$p = $p->getData();
foreach($p AS $k => $v)
{
$p[$v['catid']] = $v['name'];
}
$form = new Admin_Model_Form_SubTest();
$f = $form->createForm(array('parents' => $p));
$f->isValid($this->_getAllParams());
$json = $f->getMessages();
echo Zend_Json::encode($json);
}
So this will call the function which i gave on the top of the post and do the validation and return the error.But here i always getting "File exceeds the defined ini size " What I done wrong this code.
Kindly help me on this.
Check the upload_max_filesize setting in your .ini file(s). That's where this error comes from.
When you call .val() on your file input, you get the path of the file you have selected, while your validator will be expecting the file itself, hence the strange error. Most people opt to skip file inputs when doing ajax validation, and just check it on submit.