Fatal error: Call to undefined function text_view - call

I have a basic code here:
<?
include("inc_dblib.php");
include("inc_ecs.php");
$db = dbconnect();
$id = 10;
?>
<?php echo text_view($db,$id,"<h3><br />^lead^</h1> <br />^text^");?>
<br />
inside inc_ecs.php i have:
function text_view($dblink,$id,$code) {
if( !$rset = dbquery($dblink,"article_view",$id) )
return FALSE;
$item = mysql_fetch_assoc($rset);
$text=$item["text"];
$title=$item["title"];
$lead=$item["lead"];
$capelo=$item["capelo"];
$author=$item["author"];
$vowels = array("^text^","^title^","^capelo^","^lead^", "^author^");
$yummy = array($text, $title, $capelo, $lead,$author);
$code = str_replace($vowels,$yummy,$code);
return $code;
}
however every time I run my script it tells me
Fatal error: Call to undefined function text_view
. Any ideas? Thanks.
Ok
so I found an other problem.
I have tried to insert the echo "Hello World!"; in the code of the inc_ecs.php.
When I browsed the page, I realised that a major part the code it is shown as text.
I turned back to the remote version and it shows a blank page when called in a browser.
the inc_ecs.php page start showning the code from "return $outputVar;" and the remaining hole code of the page is shown:
function graphical_counter ($db, $id){
$str = counter($db, $id);
$visitors_split = chunk_split ($str,1,'');
$visitors = strlen($str);
for ($i ; $i< $visitors ; $i++){
$outputVar .= "<img src='./images/counter/".$visitors_split[$i].".gif' width='15' height='20' border='0' align='absmiddle'>";
}
return $outputVar;
}
/*
End Counter Functions
Is there an error in this code ?

your include(); should be inside of the tag:
<?php
include("inc_ecs.php");
echo text_view($db,$id,"<h3><br />^lead^</h1> <br />^text^");
?>

Related

Codeigniter Model: How to use values from a query for further calculations?

i have a function in a model with the following query, and i want to make some calculations with value1, value2 and value3 outside the query. how to get the values out of this result()?
function ($id,$username$) {
$this->db->select("id,value1,value2,value3,value4");
$this->db->from("table1");
$this->db->where("username=$username and id = $id");
$query=$this->get();
$result = $query->result();
$result['$testvalue'] = (value1 * value2/113) + value3;
return $result; }
can someone help? i already found out how to use values from a table, but not from a query!
ok now i know how to use row_array.
i call the row_array in the controller
$data = $this->model_testmodel->testfunction($id, $username);
...
$this->load->view('pages/view_test', $data);
now i wanna know how the view would look like.
i tried many different ways.
in the moment i am stuck with ...
<?php foreach $data as $value: ?>
<label>Value1:</label>
<input type="text" name="value1" value="<?php echo $value['value1']; ?>">
<label>Value2:</label>
<input type="text" name="value2" value="<?php echo $value['value2']; ?>">
...
<?php endforeach; ?>
but i get two errors:
Message: Undefined variable: data
Message: Invalid argument supplied for foreach()
Try this...
function ($id,$username)
{
$this->db->select("id,value1,value2,value3,value4");
$this->db->from("table1");
$this->db->where(array('id'=>$id,'username'=>$username));
$query=$this->db->get();
$result = $query->row();
$testvalue = (($result->value1 * $result->value2/113) + $result->value3);
//test here
echo $testvalue;
$res = array();
$res['testvalue'] = $testvalue;
$res['value1'] = $result->value1;
$res['value2'] = $result->value2;
$res['value3'] = $result->value3;
return $res;
}
It returns $res as array.Easy to execute of you got problem comment.. if it works accept.Lets enjoy..
Then make a function call and accept array in a variable..like this..
first load model then make function call.from your controller
$this->load->model('model_name');
$data= $this->model_name->function_name($id,$username);
//Fetch returned array like this..
echo $data['testvalue'];
echo $data['value1'];
//so on

Find all in CakePHP is dumping a semicolon in my view

I don't know what exactly is happening with my CakePHP app. It worked last week and I have literally changed nothing with that particular file.
When I use find 'all' in my controller it dumps a semi-colon in my view even if there is nothing in the view file.
Here is my code
$evts = $this->Event->find('all');
There is nothing in my view file. I don't know if it makes a difference but I'm using a json view.
As requested here is the complete code for the action
public function search(){
$this->Event->recursive = 2;
$conditions = array();
if(!empty($this->request->query['name'])){
$conditions = array('Event.name LIKE ' => "%" . str_replace(" ","%", $this->request->query['name']) . "%");
}
if(!empty($this->request->query['home'])){
$conditions = array('Event.home_team_id' => $this->request->query['home']);
}
if(!empty($this->request->query['away'])){
$conditions = array('Event.away_team_id' => $this->request->query['away']);
}
$limit = 25;
if(!empty($this->request->query['limit'])){
$limit = $this->request->query['limit'];
}
//$evts = $this->Event->find('all',array('conditions'=>array($conditions),'order' => array('Event.start_time'),'limit'=>$limit));
$evts = $this->Event->find('all');
$this->set('events',$evts);
}
Everything in the view has been commented out ... but here is the code anyway
$results = array();
$i = 0;
foreach ($events as $event) {
$results[$i]['id'] = $event['Event']['id'];
$results[$i]['label'] = $event['Event']['name'] . "(" . date_format(date_create($event['Event']['start_time']), 'D, jS M Y') . ")";
$results[$i]['value'] = $event['Event']['name'];
$results[$i]['home_team_name'] = $event['HomeTeam']['name'];
$results[$i]['away_team_name'] = $event['AwayTeam']['name'];
$results[$i]['sport_name'] = $event['Sport']['name'];
$results[$i]['tournament_name'] = $event['Tournament']['name'];
$results[$i]['start_time'] = $event['Event']['start_time'];
$results[$i]['img'] = $event['Event']['img_path'];
$results[$i]['listener_count'] = 0; //TODO Get the follower count
$i++;
}
echo json_encode($results);
Display
If you changed nothing with that particular file then perhaps you have installed callbacks (either in the controller or in the model) that echo that ";". Look for 'afterFind' calls...
Search your model and your controller folders for "echo statement". In fact you should search your entire app folder except for the Views folder.

JRequest::getVar is keeping previous values even after refreshing

I am writing a mail function as a module in joomla 3. e mail works fine, but when i reload the page and insert a different email and send, but it seemed to return the previous email by JRequest::getVar function. Is there a way to solve this issue? thanks in advance..
this is the code i used:
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
require_once(dirname(__FILE__) . DS . 'helper.php');
//declaration
$input = JFactory::getApplication()->input;
$form_send = $input->get('form_send', 'notsend');
$fanme = $input->get('firstName');
$lname = $input->get('lastinput');
$email = $input->get('email', 0 , 'STRING');
$mail=false;
$emailexist=false;
echo '<script>
var php_var = "chk is first:'.$email.'";
alert(php_var);
</script>';
switch ($form_send) {
case 'send':
if ((is_null($fanme) || is_null($lname) || is_null($email)) || (!filter_var($email, FILTER_VALIDATE_EMAIL))) {
echo '<div> Fields are empty or not valid. <br></div>';
} else {
$mail = ModLittleContactHelper::SendMail($email, $fanme, $lname);
echo '<script>
var php_var = "chk when mail sending:'.$email.'";
alert(php_var);
</script>';
$input = JFactory::getApplication();//i have tried $app also
$input ->setUserState('mod_mycontact.email', null);
}
//echo $respond
if (!$mail) {
echo 'Error sending email:';
require(JModuleHelper::getLayoutPath('mod_myecontact', 'default_tmpl'));
}else{
require(JModuleHelper::getLayoutPath('mod_mycontact', 'sendok_tmpl'));
break;
}
default:
require(JModuleHelper::getLayoutPath('mod_littlecontact', 'default_tmpl'));
unset($var);
}
?>
#Mario this is the helper code:
class ModLittleContactHelper{
public function SendMail($email, $fname, $lname) {
$body = "<p style='font-family:arial;font-size:20px;'>Hi " . $fname . " " . $lname . ",</p>";
$body.="<p style='font-family:arial;font-size:20px;'>Welcome to Crowd Logistics! Please verify your email address below.</p><br/><br/>";
$body.= "<hr><br/>";
$body.= "<p style='align:center;background-color:#40B3DF;font-family:arial;color:#FFFFFF;font-size:20px;'><a href='http://suriyaarachchi.com/crowdlogistics/index.php?option=com_content&view=article&id=192' target='_blank'>Verify " . $email . "</a></p>";
$body.= "<br/><hr><br/>";
$body.="<p style='text-align:right;font-family:arial;font-size:20px;'>Or, paste this link into your browser:<br/>";
$body.= "http://crowdlogistics/index.php?option=com_content&view=article&id=192<br/><br/>";
$body.= "Thanks.<br/>";
$body.= "CrowdLogistics</p><br/>";
$mailer = & JFactory::getMailer();
$mailer->setSender('info#crowdlogistics.com');
$mailer->addRecipient($email);
$mailer->setSubject('Mail from CrowdLogistics - Confirm your email');
$mailer->setBody($body);
$mailer->IsHTML(true);
$send = & $mailer->Send();
return $send;
}
Since you're trying to run your code on Joomla 3, there are a few things that are wrong. Below os your code, corrected where I was able to correct it. Now you have to test it in your module environment with the class being instantiated (in other words, test the below code in your module).
<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'helper.php');
//declaration
$doc = JFactory::getDocument();
$app = JFactory::getApplication();
$input = $app->input;
$form_send = $input->get('form_send', 'notsend');
$fanme = $input->get('firstName');
$lname = $input->get('lastinput');
$email = $input->get('email', 0 , 'STRING');
$mail=false;
$emailexist=false;
$doc->addScriptDeclaration('
var php_var = "chk is first:'.$email.'";
alert(php_var);
');
switch ($form_send) {
case 'send':
if ((is_null($fanme) || is_null($lname) || is_null($email)) || (!filter_var($email, FILTER_VALIDATE_EMAIL))) {
echo '<div> Fields are empty or not valid. <br></div>';
} else {
$mail = ModLittleContactHelper::SendMail($email, $fanme, $lname);
$doc->addScriptDeclaration('
var php_var = "chk when mail sending:'.$email.'";
alert(php_var);');
$app->setUserState('mod_littlecontact.email', null);
}
//echo $respond
if (!$mail) {
echo 'Error sending email:';
require(JModuleHelper::getLayoutPath('mod_littlecontact', 'default_tmpl'));
break;
}else{
require(JModuleHelper::getLayoutPath('mod_littlecontact', 'sendok_tmpl'));
break;
}
default:
require(JModuleHelper::getLayoutPath('mod_littlecontact', 'default_tmpl'));
unset($var);
}
?>
First, JRequest class is deprecated in J3. You should use JInput:
$input = JFactory::getApplication()->input;
$your_var = $input->get('your_var');
Then, regarding the email, you probably need to unset the session variables when the success is achieved (mail sent), or in other words, when you don't need them any longer.
$app = JFactory::getApplication();
// your_var is the variable you want to unset
$app->setUserState('mod_your_module.your_var', null);
Hope it helps
you can use this code
$email = $input->get('email', 0 , 'STRING','');
4th argument for the default value,

detect if core flash messages in cakephp is an error or success message

I have copied the SesionHelper from the core into myapp/View/Helper so I can alter the div structure around the message outputted.
My problem is that I cant seem to detect if the message is an error or success message from the default cakephp message. I know I can set a flash message in my controller and add an attribute. But there doesn't seem to be any extra data that I can see from the core messages.
Example if the data is saved to the database i wish to show the message as green. Or if the data could not be saved then as red message.
public function flash($key = 'flash', $attrs = array()) {
$out = false;
if (CakeSession::check('Message.' . $key)) {
$flash = CakeSession::read('Message.' . $key);
$message = $flash['message'];
unset($flash['message']);
if (!empty($attrs)) {
$flash = array_merge($flash, $attrs);
}
if ($flash['element'] === 'default') {
$class = 'message';
if (!empty($flash['params']['class'])) {
$class = $flash['params']['class'];
}
$out = '<div id="' . $key . 'Message" class="' . $class . '">' . $message . '</div>';
} elseif (!$flash['element']) {
$out = $message;
} else {
$options = array();
if (isset($flash['params']['plugin'])) {
$options['plugin'] = $flash['params']['plugin'];
}
$tmpVars = $flash['params'];
$tmpVars['message'] = $message;
$out = $this->_View->element($flash['element'], $tmpVars, $options);
}
CakeSession::delete('Message.' . $key);
}
return $out;
}
What you are doing is reinventing the wheel as far as CakePHP is concerned.
You can specify an element as the second argument when you set a flash message in your controller method:
$this->Session->setFlash('Your record has been saved', 'flash_success');
Then in elements create an element Element/flash_success.ctp like this:
<div class="alert-success"><?php echo $message;?></div>
And finally in your view:
<?php echo $this->Session->flash()?>
Here is the section that deals with this in detail from the official documentation:
http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#creating-notification-messages

PHP After every NTH in DIV LOOP

Hi I want to add content after every 3rd div in the loop. Here is below code but I am not getting even render content "Hi this is the 3d div"
Its not detecting every 3rd div.
<?php
function q_list_item($q_item)
{
$count = 0;
$this->output('<DIV>');
$this->my_items;
$this->output('</DIV>');
$count++;
if($count % 3 == 0) {
echo 'Hi this is the 3rd div';
}
}
?>
----[Actual Function]-----------------------------------------------
<?php
function q_list_item($q_item)
{
$this->output('<DIV CLASS="qa-q-list-item'.rtrim(' '.#$q_item['classes']).'" '.#$q_item['tags'].'>');
$this->q_item_stats($q_item);
$this->q_item_main($q_item);
$this->q_item_clear();
$this->output('</DIV> <!-- END qa-q-list-item -->', '');
}
?>
You are resetting the $count to 0 at the top of this function, so it will always be 1 when you run the if statement at the end of the function.
This may help with your issue, although I can't tell if your code is in a class or not as it doesn't look like it is, but you are using $this-> in there. Essentially, move the instantiation of the counter outside of the function:
<?php
$q_list_count = 0;
function q_list_item($q_item)
{
$q_list_count++;
$this->output('<DIV>');
$this->my_items;
$this->output('</DIV>');
if($q_list_count % 3 == 0) {
echo 'Hi this is the 3rd div';
}
}
?>
<?php
$count = 0;
function q_list_item($q_item)
{
$this->output('<DIV>');
$this->my_items;
$this->output('</DIV>');
$count++;
if($count % 3 == 0) {
echo 'Hi this is the 3rd div';
}
}
?>
initialize the $count outside the loop, otherwise count will always be 1 when it reaches the if statement

Resources