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
Related
To be very specific - there is CRM system written in Codeigniter called Rise. I would like to make (automatically) an expense entry ( call save() method of an Expenses class ) each time someone logs in ( inside save_timelog() method of a Projects class ) time manually.
Expense Controller:
function save() {
validate_submitted_data(array(
"id" => "numeric",
"expense_date" => "required",
"category_id" => "required",
"amount" => "required"
));
$id = $this->input->post('id');
$target_path = get_setting("timeline_file_path");
$files_data = move_files_from_temp_dir_to_permanent_dir($target_path, "expense");
$has_new_files = count(unserialize($files_data));
$data = array(
"expense_date" => $this->input->post('expense_date'),
"title" => $this->input->post('title'),
"description" => $this->input->post('description'),
"category_id" => $this->input->post('category_id'),
"amount" => unformat_currency($this->input->post('amount')),
"project_id" => $this->input->post('expense_project_id'),
"user_id" => $this->input->post('expense_user_id'),
"files" => $files_data
);
<.. ETC. CHECKING FILES ..>
$save_id = $this->Expenses_model->save($data, $id);
if ($save_id) {
echo json_encode(array("success" => true, "data" => $this->_row_data($save_id), 'id' => $save_id, 'message' => lang('record_saved')));
} else {
echo json_encode(array("success" => false, 'message' => lang('error_occurred')));
}
}
Projects Controller:
function save_timelog() {
$this->access_only_team_members();
$id = $this->input->post('id');
$start_time = $this->input->post('start_time');
$end_time = $this->input->post('end_time');
$note = $this->input->post("note");
$task_id = $this->input->post("task_id");
if (get_setting("time_format") != "24_hours") {
$start_time = convert_time_to_24hours_format($start_time);
$end_time = convert_time_to_24hours_format($end_time);
}
$start_date_time = $this->input->post('start_date') . " " . $start_time;
$end_date_time = $this->input->post('end_date') . " " . $end_time;
$start_date_time = convert_date_local_to_utc($start_date_time);
$end_date_time = convert_date_local_to_utc($end_date_time);
$data = array(
"project_id" => $this->input->post('project_id'),
"start_time" => $start_date_time,
"end_time" => $end_date_time,
"note" => $note ? $note : "",
"task_id" => $task_id ? $task_id : 0,
);
if (!$id) {
//insert mode
$data["user_id"] = $this->input->post('user_id') ? $this->input->post('user_id') : $this->login_user->id;
} else {
//edit mode
//check edit permission
$this->check_timelog_updte_permission($id);
}
$save_id = $this->Timesheets_model->save($data, $id);
if ($save_id) {
echo json_encode(array("success" => true, "data" => $this->_timesheet_row_data($save_id), 'id' => $save_id, 'message' => lang('record_saved')));
} else {
echo json_encode(array("success" => false, 'message' => lang('error_occurred')));
}
}
So now what I'm trying to do is inside Projects controller, save_timelog() method just below these lines:
<...>
if (!$id) {
//insert mode
$data["user_id"] = $this->input->post('user_id') ? $this->input->post('user_id') : $this->login_user->id;
} else {
//edit mode
//check edit permission
$this->check_timelog_updte_permission($id);
}
/* CREATING A SAMPLE ARRAY WITH STATIC DATA FOR AN EXAMPLE EXPENSE ENTRY */
$a = array(
"expense_date" => '2018-03-13',
"title" => 'Cat Food',
"description" => 'Sheba, Felix, KiteKat',
"category_id" => '85',
"amount" => '500',
"project_id" => '84',
"user_id" => '10',
"files" => $files_data
);
/* TRYING TO SAVE/SEND EXAMPLE ARRAY TO Expenses Class save() method (?) */
$b = $this->Expenses_model->save($a);
/* RESULT (?) */
$save_id = $this->Timesheets_model->save($data, $id);
if ($save_id) {
echo json_encode(
array(
array(
"success" => true,
"data" => $this->_timesheet_row_data($save_id),
'id' => $save_id,
'message' => lang('record_saved')
),
array(
"success" => true,
"data" => _row_data($b),
'id' => $save_id,
'message' => lang('record_saved')
)
)
);
} else {
echo json_encode(array("success" => false, 'message' => lang('error_occurred')));
}
<.. Closing save_timelog() method ..>
However it surely doesn't work and all I get is "POST http://rise.test/index.php/projects/save_timelog 500 (Internal Server Error)".
I also load Expenses model and Expenses categories model in Projects _construct():
Projects Controller:
public function __construct() {
parent::__construct();
$this->load->model("Project_settings_model");
$this->load->model("Expense_categories_model");
$this->load->model("Expenses_model");
}
I also contacted developers of Rise with following question/answer:
Me:
In Projects controller save_timelog() method I just want to call
Expenses controller save() method, and if save_timelog() is successful
I would like to save an Expense ( $this->Expenses_model->save($data,
$id); ) with appropriate data. Could be static values for now for
$data array in save() method - just to find out it's working.
Rise Devs:
Hi, You are doing almost right. Just remove the 2nd parameter $id. It
should be used only for update. $this->Expenses_model->save($data)
Would really appreciate any help and directions! Thanks.
I'm running:
- debian-linux-gnu
- codeigniter 2.2.0
- No physical links in db (legacy)
- version: 5.5.41-MariaDB-1~precise-log
Problem:
I'm writing a blog system for a webshop. After filling in the form (with ckeditor for the actual blog), I do a redirect to the reading page/view:
redirect("/blog/read/" . $blog_id, "refresh"); Only no data is found. When I refresh the page manualy imediatly after, the blog shows just fine.
I tried to sleep the process, but this didn't help. So I think it is not a db issue. Since the view is new for this particular post, no caching.
controller:
public function add_do() {
//Image handling
if (!empty($_FILES['blog_file_img'])) {
$path = $_FILES['blog_file_img']['name'];
$ext = pathinfo($path, PATHINFO_EXTENSION);
$fileData = $this->upload('blog_file_img', $this->now . '.' . $ext);
$fileNames = $this->resize($fileData);
}
//Create blog
$blog_data = array(
"blog_img_original" => $fileData['file_name'],
"blog_img_small" => $fileNames["small"],
"blog_img_medium" => $fileNames['medium'],
"blog_img_big" => $fileNames['big'],
"blog_date_added" => $this->now,
"blog_date_modified" => $this->now,
"blog_created_by" => $this->user['userid'],
"blog_modified_by" => $this->user['userid']
);
//Create blog description
$blog_description_data = array(
'language_id' => 1,
'blog_title' => $this->input->post('blog_title', true),
'blog_desc' => $this->input->post('blog_desc', true),
'blog_text' => $this->input->post('blog_text', false)
);
$data = array_merge($blog_data, $blog_description_data);
$blog_id = $this->blog_model->blog_new($data);
redirect("/blog/read/" . $blog_id, "refresh");
}
read controller:
public function read($id){
$this->_get_message();
$blog_data = $this->blog_model->blog_entry($id);
$this->load->view('header', $this->data_view);
$this->load->view('blog/blog_entry', array('blog_data' => $blog_data));
$this->load->view('blog/blog_right', array('blog_stats' => $this->blog_model->blog_most_popular()));
$this->load->view('footer');
$this->_debug();
}
model for add
public function blog_new($data) {
$this->db->trans_start();
//Blog data extraction
$blog_data = array(
"blog_img_original" => $data['blog_img_original'],
"blog_img_small" => $data["blog_img_small"],
"blog_img_medium" => $data['blog_img_medium'],
"blog_img_big" => $data['blog_img_big'],
"blog_date_added" => $data['blog_date_added'],
"blog_date_modified" => $data['blog_date_modified'],
"blog_created_by" => $data['blog_created_by'],
"blog_modified_by" => $data['blog_modified_by']
);
$blog_id = $this->new_blog($blog_data);
//Blog description extraction
$blog_description_data = array(
'blog_id' => $blog_id,
'language_id' => 1,
'blog_title' => $data['blog_title'],
'blog_desc' => $data['blog_desc'],
'blog_text' => $data['blog_text']
);
$this->new_blog_description($blog_description_data);
$this->db->trans_complete();
return $blog_id;
}
private function new_blog($data) {
$this->initialise('blog', 'blog_id');
return $blog_id = $this->create($data);
}
private function new_blog_description($data) {
$this->initialise('blog_description', 'blog_description_id');
return $blog_description_id = $this->create($data);
}
model for read
public function blog_entry($id) {
$this->db->select("*");
$this->db->from("blog");
$this->db->join("blog_description", "blog.blog_id = blog_description.blog_id");
$this->db->join("blog_stats", "blog.blog_id = blog_stats.blog_id");
$this->db->where("blog.blog_id", $id);
$query = $this->db->get();
//Add to views stats
$this->blog_add_view($id);
return $query->result_array();
}
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.
Here is my model file;
function yaklasan_maclar_tenis() {
$data = $this->cache->memcached->get('yaklasan_tenis');
if (!$data){
$this -> db -> limit(10);
$data = array();
foreach ($this->db->get_where('maclar', array('durum' => '1', 'sonuclandi' => '0', 'tarih >=' => time(), 'spor' => '5'))->result_array() as $row) {
$data[] = array(
'id' => $row['id'],
'matchid' => $row['matchid'],
'spor' => $row['spor'],
'ulke' => $row['ulke'],
'turnuva' => $row['turnuva'],
'takim1' => $row['takim1'],
'takim2' => $row['takim2'],
'tarih' => $row['tarih'],
'istatistik' => $row['istatistik'],
);
}
$this->cache->memcached->save('yaklasan_tenis',$data, 600);
}
return $data;
}
I'm sure that I installed memcached properly but getting this error when I call this function:
Fatal error: Call to a member function get() on a non-object in /home/mydomain/public_html/system/libraries/Cache/drivers/Cache_memcached.php on line 79
Here is the lines 77-82, Cache_memcached.php file:
public function get($id)
{
$data = $this->_memcached->get($id); //this line is 79
return is_array($data) ? $data[0] : $data;
}
I made my research on site but couldn't find anything about it. I just found something and tried the suggestion but nothing changed.
Thanks in advance.
Did you load the caching drive?
Something likes:
$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'file'));
This question is about Dashboard.addNews and Dashboard.publishActivity
Facebook has told the public about its new Dashboard API, however it hasn't provided any updates on its library to use the new code.
So I followed the advice in this link
http://forum.developers.facebook.com/viewtopic.php?pid=197753
to add the new functions to the facebookapi_php5_restlib.php
//dashboard functions
public function dashboard_addNews($uid, $news, $image = null) {
return $this->call_method('facebook.dashboard.addNews',
array('uid' => $uid,
'news' => $news,
'image' => $image));
}
public function dashboard_multiAddNews($uids, $news, $image = null) {
return $this->call_method('facebook.dashboard.multiAddNews',
array('uids' => $uids ? json_encode($uids) : null,
'news' => $news,
'image' => $image));
}
public function dashboard_addGlobalNews($news, $image = null) {
return $this->call_method('facebook.dashboard.addGlobalNews',
array('news' => $news,
'image' => $image));
}
public function dashboard_publishActivity($activity, $image = null) {
return $this->call_method('facebook.dashboard.publishActivity',
array('activity' => $activity,
'image' => $image));
}
public function dashboard_multiIncrementCount($uids) {
return $this->call_method(
'facebook.dashboard.multiIncrementCount', array('uids' => json_encode($uids)));
}
public function dashboard_removeActivity($activity_ids) {
return $this->call_method(
'facebook.dashboard.removeActivity', array('activity_ids' => json_encode($activity_ids)));
}
public function dashboard_setCount($uid, $count) {
return $this->call_method('facebook.dashboard.setCount',
array('uid' => $uid,
'count' => $count));
}
But now when I follow the sample code at
http://wiki.developers.facebook.com/index.php/Dashboard.addNews
$image = 'http://www.martialdevelopment.com/wordpress/wp-content/images/cheezburger-or-dim-mak.jpg';
$news = array(array('message' => 'Your friend #:563683308 just sent you a present!', 'action_link' => array('text' => 'Get Your Gift', 'href' => 'http://www.example.com/gifts?id=5878237')));
$facebook->api_client->dashboard_addNews($user_id, $news, $image);
However it will prompt this error:
[Wed Jan 27 03:42:27 2010] [error] [client 127.0.0.1] PHP Notice: Array to string conversion in /var/local/site/webroot/xxxx/facebookapi_php5_restlib.php on line 2009
the code at that php line is
if (is_array($val)) $val = implode(',', $val);
pls notice that I haven't altered the facebookapi_php5_restlib.php except pasting those suggested dashboard function code.
and when I follow the instruction at http://wiki.developers.facebook.com/index.php/Dashboard.publishActivity and try to use it:
$image = 'http://www.martialdevelopment.com/wordpress/wp-content/images/cheezburger-or-dim-mak.jpg';
$activity = array(array('message' => '{*actor*} just sponsored #:563683308!', 'action_link' => array('text' => 'Sponsor this cause', 'href' => 'http://www.example.com/games?id=5878237')));
$facebook->api_client->dashboard_publishActivity($activity, $image);
it throws out the same error too about "Array to string conversion"
Any suggestion to actually use the new Facebook Dashboard API?
If you don't assign into the same variable, the warning will likely go away:
if (is_array($val)) $stringval = implode(',', $val);
Okay, I found that no need to modify the php class at all.
All we need to do is use the call_method
$news = array(array('message' => 'There is a new level in the dungeon!', 'action_link' => array('text' => 'Play now.', 'href' => 'http://www.example.com/gifts?id=5878237')));
$facebook->api_client->call_method('facebook.dashboard.addGlobalNews', array('news' => $news));