Undefined property: stdClass::$contactno in C:\..\..\Joomla\administrator\components\com_helloworld\views\helloworlds\tmpl\default.php on line 92 - joomla3.0

i add a contactno field in helloworld component backend. i add a no. of line code same as a Adding categories.
the files loactions:
admin/sql/install.mysql.utf8.sql... i add a contactno field
admin/models/forms/helloworld.xml... i add a contactno field below greeting field
<field name="contactno" type="text" default="Some text"
description="COM_HELLOWORLD_HELLOWORLD_CONTACT_DESC"
label="COM_HELLOWORLD_HELLOWORLD_CONTACT_LABEL"
size="10" />
admin/models/fields/helloworld.php i add a query in protected function getOptions()
$query->select('#__helloworld.id as id,greeting,#__helloworld.contactno as contactno,#__categories.title as category,catid');
admin/views/helloworlds/tmpl/default.php...i add a contactno field th in table below author field
<th width="30%">
<?php echo JHtml::_('searchtools.sort', 'COM_HELLOWORLD_CONTACTNO', 'contactno', $listDirn, $listOrder); ?>
</th>
and td below author
<td align="center"> <?php echo $row->contactno; ?> </td>
when i run a helloworld component i got error
Notice: Undefined property: stdClass::$contactno in C:\xampp\htdocs\Joomla\administrator\components\com_helloworld\views\helloworlds\tmpl\default.php on line 92
what is my mistake...where define a new field...?

i solve by adding in associative array of configuration settings.
file location is: admin/models/helloworlds.php
i add a new fields contactno in array and updating in query
of getListQuery()
$query->select('a.id as id, a.greeting as greeting, a.contactno as contactno, a.published as published, a.created as created')

Related

How to get results in form of tables with column titles in wordpress?

<form action="" method="post" name="myForm">
Filter <input id="isbn" type="text" name="isbn" />
<input type="submit" name="submit" value="Submit" /> </form>
<?php
if(isset($_POST['submit']))
{
global $wpdb;
$table_name = "isbn"; // change this to your table name
$field = $_POST['isbn']; // change this to your isbn field $_POST['ISBN'];
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name where isbn = '".$field."'");
foreach ($retrieve_data as $retrieved_data) {
echo $retrieved_data->Title;
echo $retrieved_data->Image; // for image
echo $retrieved_data->Isbn;
}
}
// I have this php code for accessing data from my database table. but the result is not coming in desired form. i am sending some screenshots which are describing my situations.
This image contain my database table structure and record containing title, image and isbn column.
This is the output which i am getting after applying above query and image is also not displaying in browser.
This type of output i want in my browswer after someone enter isbn number of book in search form.
Can someone please provide me code for this?
Try adding ARRAY_A in the get_results method argument like below.
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name where isbn = '".$field."'", ARRAY_A);
and then for displaying image try
foreach ($retrieve_data as $retrieved_data) {
echo $retrieved_data['Title'];
echo '<img src="data:image/jpeg;base64,'.base64_encode( $retrieved_data['Image'] ).'"/>'; // for image
echo $retrieved_data['Isbn'];
}

Codeigniter foreach Select Menu 'Selected' Option

I am creating a theme select option for an App. I want the user to choose from a select option which theme they want, light or dark.
I am storing theme names in the database like so:
I am then calling all themes in the Model and returning the array with this code:
public function getThemes() {
$query = $this->db->query('SELECT * FROM theme');
return $query->result_array();
}
I am using my Constructor to grab the data and Render it to my settings view like so: (I am sending a few things at the same time in $this->data that's why it is in an array but I cut that code out)
$this->data = [
'themes' => $this->model_setting->getThemes()
];
$this->render('backend/standart/administrator/setting/setting_general', $this->data);
In my HTML View I have the following HTML which successfully displays the correct 2 themes available:
<div class="col-sm-12">
<label>Select Your Desired Theme</label><br>
<select class="form-control" name="site_color_theme" id="site_color_theme">
<?php foreach ($themes as $theme): ?>
<option value="<?= $theme['theme']; ?>" ><?= $theme['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
When I save the settings form I am updating my options table in the database with the theme name. The Html Body Class calls on this options table and finds the chosen theme and uses this to render a specific CSS Stylesheet.
The problem I am having is when I save my settings, the Select Option does not display the saved theme name to show that this is the active theme chosen.
How can I get the Select Option to display the chosen theme when the user visits the settings page to select another theme?
You should have active_theme column in the theme table
active_theme set to 1 when form dropdown site_color_theme is submitted (the rest theme records set to 0)
You should use Codeigniter Form Helper to do that : https://www.codeigniter.com/user_guide/helpers/form_helper.html#form_dropdown
// $themes = Theme list array [id => theme-name, id => theme-name]
// $active_theme = Record of "active_theme" with value equal to "1"
// $extra = Custom HTML attributes e.g. class="something" onclick="function(js)"
echo form_dropdown('site_color_theme', $themes, $active_theme, $extra);

CakePHP : Show database view

I have a view in my database and i want to show the value. but i confused how to call the name of view in my controller. i have made a model, but still i can't show the view. my view database’s name is Vtotaleks. Please help me T_T
here my controller
class HomesController extends AppController{
var $uses = array(
'Vtotaleks',
'SiswaMonitoring',
'Siswa',
'AuthUser',
'PerusahaanOrder');
public function index(){
$this->Lib->cekprivilege();
$totalEks = $this->Vtotaleks->find('all', array('cache' => true));
and this my model
<?php
class Vtotaleks extends AppModel
{
public $usetable = 'vtotaleks'; }
and this my view
<tbody>
<?php $totalEkstrainee=0;foreach($totalEks as $datatotalEks){
$totalEkstrainee+=$datatotalEks['Vtotalekstrainee']['siswa_total'];
?>
<tr>
<td><?php echo $datatotalEks['Vtotalekstrainee']['city_name']?></td>
<td align="right"><strong><?php echo $datatotalEks['Vtotalekstrainee']['siswa_total']?></strong></td>
</tr>
<?php }?>
<tr class="danger">
<td><em>Total</em></td>
<td align="right"><strong><?php echo $totalEkstrainee?></strong></td>
</tr>
</tbody>
and here the error
Notice (8): Undefined variable: totalEks [APP\View\Homes\index.ctp, line 142]
Warning (2): Invalid argument supplied for foreach() [APP\View\Homes\index.ctp, line 142]
Add this line after query
$this->set(compact('totalEks'));

Retrive number from database and pass it on as a search parameter

When someone search for a particular CITY in my real estate website, I need to retrieve the matching cityID from a .csv database and pass the retrieved cityID to my vendor website as one of the search parameters, like http;//www.vendor.com?cityID=9999
The list of cityID and the cityName is in a file called myproperty.csv
Below are the current html codes that i have now.
<form action="vendor.com" method="get" target="_blank">
<label>Please enter city name:-</label>
<input type="text" id="cityName" name="cityName">
<!-- Please help me to add some codes here -->
<input type="submit" value="Submit">
</form>
Can someone please help me with the codes to achieve the objective above?
I have searched high and low for answers, still nothing works. Please help. Thanks in advance for all your help
Hafiz
I assume you run your site on a PHP enabled web server, don't you? In that case here's one solution for you, which uses PHP to read the csv file line by line and create an html dropdown for the user to select the city by name.
Also, if you don't have PHP running on your server it is possible to do the same using JavaScript, if you need that rather than PHP let me know.
That's probably the most simple solution, you can get further by implementing a javascript autocomplete function if you want to use a text input rather than a list of cities in a dropdown.
<form action="vendor.com" method="get" target="_blank">
Please select city:
<?php
// Set filename to read from
$csvFile = 'dummy.csv';
// Open file handle
$fp = fopen($csvFile, "r");
// In case the file don't exist, exit
if (!is_resource($fp)){
die("Cannot open $csvFile");
}
?>
<select name="city">
<?php //Let's read the csvfile line by line: ?>
<?php while($line = fgetcsv($fp)): ?>
<?php // Assuming that the csvfile's structure is the following: city_id,city_name, we create the dropdown options: ?>
<option value="<?php echo $line[0];?>"><?php echo $line[1]?></option>
<?php endwhile; ?>
</select>
<input type="submit" value="Submit">
</form>
And now here's the JavaScript solution (the code uses the JQUERY framework so you'll have to include it in your html tag:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
You'll also need a hidden form input to contain the matched city id, so here's the extended html markup for your form:
<form action="vendor.com" method="get" target="_blank" id="myForm">
Please enter city name:-
<input type="hidden" id="cityId" name="cityId">
<input type="text" id="cityName" name="cityName">
<input type="submit" value="Submit">
</form>
And your JavaScript to do the job:
<script>
$(function(){
//Ajax call to get csv file contents
$.ajax({
type: "GET",
url: "dummy.csv",
dataType: "text",
success: function(data) {process_csv(data);}
});
//Event handler for form submission
$('#myForm').submit(function(){
//Let's get the value of the text input (city name)
var city_name = $('#cityName').val().toLowerCase();
//If the city name exists in our map, let's set the matched city id to the hidden input field called cityId
if (city_ids[city_name] > 0)
{
$('#cityId').val(city_ids[city_name]);
return true;
}
//Otherwise we can't find the city id in our database, so we can't post the form either...
alert('No such city name in database!');
return false;
});
});
//global variable to contain map of city names and id's
var city_ids = {};
//Function to parse csv file and set city map
function process_csv(text) {
var lines = text.split(/\r\n|\n/);
for (var i=0; i<lines.length; i++) {
var data = lines[i].split(',');
city_ids[data[1].toLowerCase()] = data[0];
}
}
</script>

cakephp view will not display

I have an order form to purchse a voucher but for some reason now when I click phurcase it displays a blank screen. I cant see what has changed and why the view is not being passed the information from the controller.
Vourchers form
<h2>Vouchers</h2>
<?php
foreach($vouchers as $v){
?>
<div id="voucher_box" class="add_shadow column span-8">
<h3><?=$v['Voucher']['title'];?></h3>
<p>
<?=$v['Voucher']['description'];?>
</p>
<?php
echo $this->Form->create('Voucher',array('id'=>'ResVoucherForm','url'=>'/res/voucher'));
echo $this->Form->input('slug',array('type'=>'hidden','value'=>$v['Voucher']['slug']));
?>
<select id="VoucherPrice" name="data[Voucher][price]">
<? $prices = explode(',',$v['Voucher']['prices'])?>
<? foreach($prices as $price){?>
<option value="<?=$price?>">€ <?=$price?></option>
<? } ?>
</select>
<div class="submit"><input type="submit" id="check_rates" value="Purchase this" class="ui-button ui-widget ui-state-default ui-corner-all" /></div>
</form>
</div>
<?
}
?>
Controller
function voucher() {
$this->layout = '360';
$msg[0] = array(); // 0 = bad messages
$msg[1] = array(); // 1 = good messages
$total_price = 0.00;
if(isset($data['Voucher'])) { $this->data['Voucher'] = $data['Voucher']; }
if(isset($this->data['Voucher'])) {
// if we have posted a voucher purchase: add it to session array
if(isset($this->data['Voucher']['slug'])){
$slug = $this->data['Voucher']['slug'];
$voucher = $this->getVoucher($slug);
$voucher['Voucher']['price'] = $this->data['Voucher']['price'];
$vouchers = $this->Session->read('Res.Vouchers'); // read existing voucher orders
if(is_array($vouchers) && isset($voucher['Voucher'])){
$temp['id'] = $voucher['Voucher']['id'];
$temp['title'] = $voucher['Voucher']['title'];
$temp['description'] = $voucher['Voucher']['description'];
$temp['slug'] = $voucher['Voucher']['slug'];
$temp['price'] = $this->data['Voucher']['price'];
$vouchers[] = $temp;
}
$this->Session->write('Res.Vouchers',$vouchers);
} else {
$vouchers = $this->Session->read('Res.Vouchers'); // read existing voucher orders
}
$this->set('voucher_orders', $vouchers);
}
This next view displays blank, I do not know how to test the information in the controller
<?php
/*
if voucher show
*/
if (isset($voucher)) {
?>
<div id="voucher_box" class="add_shadow column span-8">
<h3><?=$voucher['Voucher']['title'];?></h3>
<p>
<?=$voucher['Voucher']['description'];?>
</p>
<?php
echo $this->Form->create('Voucher',array('id'=>'ResVoucherForm','url'=>'/res/voucher'));
echo $this->Form->input('slug',array('type'=>'hidden','value'=>$voucher['Voucher']['slug']));
?>
<select id="VoucherPrice" name="data[Voucher][price]">
<? $prices = explode(',',$voucher['Voucher']['prices'])?>
<? foreach($prices as $price){?>
<option value="<?=$price?>">€ <?=$price?></option>
<? } ?>
</select>
<div class="submit"><input type="submit" id="check_rates" value="Purchase this" class="ui-button ui-widget ui-state-default ui-corner-all" /></div>
</form>
</div>
<?
}
// end if voucher show
?>
Upadate Error Returned #######################################################
Notice (8): Undefined index: id [APP/controllers/res_controller.php, line 739]
Notice (8): Undefined index: title [APP/controllers/res_controller.php, line 740]
Notice (8): Undefined index: description [APP/controllers/res_controller.php, line 741]
Notice (8): Undefined index: slug [APP/controllers/res_controller.php, line 742]
Array
(
[0] => Array
(
[id] =>
[title] =>
[description] =>
[slug] =>
[price] => 100
)
)
In the view, you have this around the whole HTML:
if (isset($voucher)) {
// ...
}
Meaning: display voucher information if there is a voucher, and do not display anything otherwise.
Now, in your controller, you don't seem to be passing a voucher variable to the view (which should be done with $this->set('varname', $var);
So, your view does not get any data, thus it does not display anything.
This could explain your issue. But if the screen is completely blank (not even the layout displays), then you must enable error logging to check what's going on.
You are setting 'voucher_orders' to your view not 'voucher' the name of the variable in the view is always the string passed in the set method. Also I don't quite understand what you are doing in the controller with the $data variable, where does it come from? Also it's redundant doing $this->data['Voucher'] = $data['Voucher'] and the checking $this->data isset if you already checked if $data is set. You might be overwriting your $this->data array, what you are doing is not necessary since the view already gives you a populated $this->data if its a form submission.
You should really try doing some tutorials and reading up a little before jumping in, you seem to not properly understand the CakePHP structure and workflow.
Thanks for all your help. By using the pr() or debug() in the controller I found the problem. It was in the function that was getting called on the line $voucher = $this->getVoucher($slug);. I now have a better understanding of cakephp.

Resources