How to show a Entity value of type array on list action in Sonata Admin
Bundle?
How Can I display array value on entitty in sonata admin bundle list
action? I've tried to do something like this:
->add('daysOfWeek', null, array('type' => 'array'))
in configureListFields method but then I get error: "An exception has been
thrown during the rendering of a template ("Notice: Array to string
conversion"
Tuesday, 10 September 2013
Rails-4 Devise + CanCan not hiding edit and destroy links
Rails-4 Devise + CanCan not hiding edit and destroy links
I am using CanCan and Devise, but the devise users is managed via custom
UsersController. I want only a logged_in user to see the edit and destroy
links. But right now depend on what is passed to the ability class, it
either hids the edit and destroy links for all users including logged_in
user or it exposes the edit and destroy links of all users to any
signed_in user, hence they can edit any user account event if it wasn't
theirs.
users/index.html.erb
<% @users.each do |user| %>
<div class="col-lg-3 col-sm-4 col-6">
<div><%= user.email %></div>
<% if user_signed_in? %>
<% if can? :update, user %>
<div class=" btn "><%= link_to "Edit", edit_user_path(user) %>
</div>
<% end %>
<% if can? :destroy, user %>
<div class="btn btn-danger"><%= link_to 'Remove', user, method:
:delete, data: {confirmation: 'Are you sure'} %></div>
<% end %>
<div><%= link_to "Sign Out", destroy_user_session_path, method:
:delete %> </div>
<% end %> <!-- closes user_signed_in? -->
</div>
<% end %>
The ability class
class Ability
include CanCan::Ability
def initialize(user)
#to ensure user object is not nil when no user object is passed in
user ||= User.new
can :manage, User do |user|
#this exposes the destroy and edit links for all users including
users not yet signed_in
#user.id == user.id
#this hide the destroy and edit links for all users including
signed_in user
user == :user_id
end
end
end
Please Note that I added the Userscontroller below the 2nd screenshot
screen shot 1 shows that if user.id == user.id in the ability class is
uncommented, exposes the destroy and edit links for all users including
users not yet signed_in and the signed_in user can edit accounts not
belonging to him. In the screenshot, the real signed_in user's email is
a@test.com but you can see that he has access to the edit and destroy
links for the user that is not signed_in which b@test.com
Screen shot 2, is what we get when we uncomment user == :user_id in the
ability class. The edit and destroy links are hidden even from the
signed_in user.
Shortened version of the User controller
class UsersController < ApplicationController
before_action :set_user, only: [:show, :update, :destroy]
before_filter :authenticate_user!, except: [:new, :create]
load_and_authorize_resource , only: [:index, :edit, :destroy]
respond_to :html, :json
def index
@users = User.all
respond_with @users
end
def edit
#@user = User.find(params[:id])
#respond_with @user
end
def destroy
@user.destroy
redirect_to users_path, {notice: 'A user was removed'}
end
private
def set_user
@user = User.find(params[:id])
end
def user_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
end
The sessions controller
class UsersSessionsController < Devise::SessionsController
respond_to :html, :json
def create
super
if signed_in?(resource)
#call the code to transfer guest cart to signed_in user
load_current_cart
end
end
end
I am using CanCan and Devise, but the devise users is managed via custom
UsersController. I want only a logged_in user to see the edit and destroy
links. But right now depend on what is passed to the ability class, it
either hids the edit and destroy links for all users including logged_in
user or it exposes the edit and destroy links of all users to any
signed_in user, hence they can edit any user account event if it wasn't
theirs.
users/index.html.erb
<% @users.each do |user| %>
<div class="col-lg-3 col-sm-4 col-6">
<div><%= user.email %></div>
<% if user_signed_in? %>
<% if can? :update, user %>
<div class=" btn "><%= link_to "Edit", edit_user_path(user) %>
</div>
<% end %>
<% if can? :destroy, user %>
<div class="btn btn-danger"><%= link_to 'Remove', user, method:
:delete, data: {confirmation: 'Are you sure'} %></div>
<% end %>
<div><%= link_to "Sign Out", destroy_user_session_path, method:
:delete %> </div>
<% end %> <!-- closes user_signed_in? -->
</div>
<% end %>
The ability class
class Ability
include CanCan::Ability
def initialize(user)
#to ensure user object is not nil when no user object is passed in
user ||= User.new
can :manage, User do |user|
#this exposes the destroy and edit links for all users including
users not yet signed_in
#user.id == user.id
#this hide the destroy and edit links for all users including
signed_in user
user == :user_id
end
end
end
Please Note that I added the Userscontroller below the 2nd screenshot
screen shot 1 shows that if user.id == user.id in the ability class is
uncommented, exposes the destroy and edit links for all users including
users not yet signed_in and the signed_in user can edit accounts not
belonging to him. In the screenshot, the real signed_in user's email is
a@test.com but you can see that he has access to the edit and destroy
links for the user that is not signed_in which b@test.com
Screen shot 2, is what we get when we uncomment user == :user_id in the
ability class. The edit and destroy links are hidden even from the
signed_in user.
Shortened version of the User controller
class UsersController < ApplicationController
before_action :set_user, only: [:show, :update, :destroy]
before_filter :authenticate_user!, except: [:new, :create]
load_and_authorize_resource , only: [:index, :edit, :destroy]
respond_to :html, :json
def index
@users = User.all
respond_with @users
end
def edit
#@user = User.find(params[:id])
#respond_with @user
end
def destroy
@user.destroy
redirect_to users_path, {notice: 'A user was removed'}
end
private
def set_user
@user = User.find(params[:id])
end
def user_params
params.require(:user).permit(:email, :password, :password_confirmation)
end
end
The sessions controller
class UsersSessionsController < Devise::SessionsController
respond_to :html, :json
def create
super
if signed_in?(resource)
#call the code to transfer guest cart to signed_in user
load_current_cart
end
end
end
Backbone.js- I got this error message ReferenceError {}
Backbone.js- I got this error message ReferenceError {}
hello i am newbie in require.js and backbone.js i need u help for my
development programming..
i have code in :
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,
maximum-scale=1, user-scaleable=no">
<link rel="stylesheet" href="css/jquery.mobile.structure-1.3.1.min.css" />
<link rel="stylesheet" href="css/themes/red.min.css" />
<link rel="stylesheet" href="css/menu.css" />
<link rel="stylesheet" href="css/table.css" />
<script>
curl = {
apiName: 'require'
};
</script>
<script src="js/libs/amd/require.js"></script>
<script src="js/bootstrap.js"></script>
</head>
<body>
<!--<div id="menu">
<h3>Menu</h3>
<ul>
<li><a href="" class="contentLink">Home </a></li>
<li><a href="" class="contentLink">About </a></li>
<li><a href="" class="contentLink">Portfolio </a></li>
<li><a href="" class="contentLink">Contact </a></li>
</ul>
</div>-->
<div data-role="page" id="login" data-url="/login"> </div><!-- /page
login -->
<div data-role="page" id="main" data-url="/main"> </div><!-- /page main -->
<div data-add-back-btn="true" data-role="page" id="accountenquiry"
data-url="/accountenquiry"> </div><!-- /page account enquiry -->
<div data-add-back-btn="true" data-role="page" id="accountdisplay"
data-url="/accountdisplay" > </div><!-- /page account display -->
<div data-add-back-btn="true" data-role="page" id="fundtransferlist"
data-url="/fundtransferlist" > </div><!-- /page fundtransferlist -->
<div data-add-back-btn="true" data-role="page" id="ownfundtransfer"
data-url="/ownfundtransfer" > </div><!-- /page ownfundtransfer -->
<div data-add-back-btn="true" data-role="page" id="newthirdpartydetail"
data-url="/newthirdpartydetail" > </div><!-- /page newthirdpartydetail
-->
<div data-role="page" id="two" data-url="/two" > </div>
</body>
</html>
views/account-enquiry/AccountEnquiryView.js
define([
'underscore',
'backbone',
'text!templates/account-enquiry/accountenquiry.html'
], function(_, Backbone, tmpl){
var serverUrl =
'http://localhost/agro-rib-mobile/restful/crud/get_all_accounts.php';
Account = Backbone.Model.extend({
urlRoot: serverUrl,
parse: function(response) {
console.log(response);
return response;
},
defaults: {
ACCOUNT_ID: null,
ACCOUNT_TYPE: '',
FULL_NAME: '',
ACCOUNT_NUMBER : '',
CURRENT_BALANCE: 0
}
});
var AccountCollection = Backbone.Collection.extend({
model:Account,
urlRoot: serverUrl,
parse: function(response) {
console.log(response);
return response;
}
});
var AccountEnquiryView = Backbone.View.extend({
el: '#accountenquiry',
template: _.template(tmpl),
initialize:function () {
console.log('Initializing Account Enquiry');
},
render: function() {
var AccountsCollection = Backbone.Collection.extend({
model : Account,
url: serverUrl,
parse: function(response) {
console.log(response);
return response;
}
});
var accounts = new AccountsCollection;
accounts.fetch();
//console.log(accounts.toJSON());
$(this.el).html(this.template(accounts.toJSON()));
return this;
}
});
return AccountEnquiryView;
});
templates/account-enquiry/accountenquiry.html
<!-- Start of second page: two -->
<div data-role="header">
<h1>Account Enquiry</h1>
</div><!-- /header -->
<div data-role="content" data-theme="a">
<p>All Account</p>
<table border="1" cellpadding="5" cellspacing="0" width="100%"
class="ui-responsive" id="my-table" data-role="table"
data-mode="columntoggle" >
<thead>
<tr>
<th width="50%">Account</th>
<th width="50%">Current Balance</th>
</tr>
</thead>
<tbody>
<% _.each(accounts, function(account) { %>
<tr>
<td>
<span><strong>Current Account(s)</strong></span><br>
<a class="detail" href="#/accountdisplay">
<%= account.FULL_NAME %> </a><br>
<span>19710257104</span>
</td>
<td>RM1,411,421,532</td>
</tr>
<% }); %>
</tbody>
</table>
</div>
Why i got this error? ReferenceError {}
hello i am newbie in require.js and backbone.js i need u help for my
development programming..
i have code in :
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1,
maximum-scale=1, user-scaleable=no">
<link rel="stylesheet" href="css/jquery.mobile.structure-1.3.1.min.css" />
<link rel="stylesheet" href="css/themes/red.min.css" />
<link rel="stylesheet" href="css/menu.css" />
<link rel="stylesheet" href="css/table.css" />
<script>
curl = {
apiName: 'require'
};
</script>
<script src="js/libs/amd/require.js"></script>
<script src="js/bootstrap.js"></script>
</head>
<body>
<!--<div id="menu">
<h3>Menu</h3>
<ul>
<li><a href="" class="contentLink">Home </a></li>
<li><a href="" class="contentLink">About </a></li>
<li><a href="" class="contentLink">Portfolio </a></li>
<li><a href="" class="contentLink">Contact </a></li>
</ul>
</div>-->
<div data-role="page" id="login" data-url="/login"> </div><!-- /page
login -->
<div data-role="page" id="main" data-url="/main"> </div><!-- /page main -->
<div data-add-back-btn="true" data-role="page" id="accountenquiry"
data-url="/accountenquiry"> </div><!-- /page account enquiry -->
<div data-add-back-btn="true" data-role="page" id="accountdisplay"
data-url="/accountdisplay" > </div><!-- /page account display -->
<div data-add-back-btn="true" data-role="page" id="fundtransferlist"
data-url="/fundtransferlist" > </div><!-- /page fundtransferlist -->
<div data-add-back-btn="true" data-role="page" id="ownfundtransfer"
data-url="/ownfundtransfer" > </div><!-- /page ownfundtransfer -->
<div data-add-back-btn="true" data-role="page" id="newthirdpartydetail"
data-url="/newthirdpartydetail" > </div><!-- /page newthirdpartydetail
-->
<div data-role="page" id="two" data-url="/two" > </div>
</body>
</html>
views/account-enquiry/AccountEnquiryView.js
define([
'underscore',
'backbone',
'text!templates/account-enquiry/accountenquiry.html'
], function(_, Backbone, tmpl){
var serverUrl =
'http://localhost/agro-rib-mobile/restful/crud/get_all_accounts.php';
Account = Backbone.Model.extend({
urlRoot: serverUrl,
parse: function(response) {
console.log(response);
return response;
},
defaults: {
ACCOUNT_ID: null,
ACCOUNT_TYPE: '',
FULL_NAME: '',
ACCOUNT_NUMBER : '',
CURRENT_BALANCE: 0
}
});
var AccountCollection = Backbone.Collection.extend({
model:Account,
urlRoot: serverUrl,
parse: function(response) {
console.log(response);
return response;
}
});
var AccountEnquiryView = Backbone.View.extend({
el: '#accountenquiry',
template: _.template(tmpl),
initialize:function () {
console.log('Initializing Account Enquiry');
},
render: function() {
var AccountsCollection = Backbone.Collection.extend({
model : Account,
url: serverUrl,
parse: function(response) {
console.log(response);
return response;
}
});
var accounts = new AccountsCollection;
accounts.fetch();
//console.log(accounts.toJSON());
$(this.el).html(this.template(accounts.toJSON()));
return this;
}
});
return AccountEnquiryView;
});
templates/account-enquiry/accountenquiry.html
<!-- Start of second page: two -->
<div data-role="header">
<h1>Account Enquiry</h1>
</div><!-- /header -->
<div data-role="content" data-theme="a">
<p>All Account</p>
<table border="1" cellpadding="5" cellspacing="0" width="100%"
class="ui-responsive" id="my-table" data-role="table"
data-mode="columntoggle" >
<thead>
<tr>
<th width="50%">Account</th>
<th width="50%">Current Balance</th>
</tr>
</thead>
<tbody>
<% _.each(accounts, function(account) { %>
<tr>
<td>
<span><strong>Current Account(s)</strong></span><br>
<a class="detail" href="#/accountdisplay">
<%= account.FULL_NAME %> </a><br>
<span>19710257104</span>
</td>
<td>RM1,411,421,532</td>
</tr>
<% }); %>
</tbody>
</table>
</div>
Why i got this error? ReferenceError {}
Monday, 9 September 2013
Giving Print Job Using PHP
Giving Print Job Using PHP
I am using Jzebra for giving print job from browser to printer.
I could list the printers name from local machine using jzebra but i want
to know any other identification like printer ip address or anything else
to detect the printer and also i want to give print using that.
I tried php_printer.dll but it doesn't work for me and also i spoke to my
server support. They also didnt give positive result.
I want to get the printer identification and using that i want to give
print job to printer using php or jzebra.
I am using Jzebra for giving print job from browser to printer.
I could list the printers name from local machine using jzebra but i want
to know any other identification like printer ip address or anything else
to detect the printer and also i want to give print using that.
I tried php_printer.dll but it doesn't work for me and also i spoke to my
server support. They also didnt give positive result.
I want to get the printer identification and using that i want to give
print job to printer using php or jzebra.
contact form php issue
contact form php issue
Okay so here's the contactform.htm file:
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> <a
href="http://www.freecontactform.com/email_form.php">Email Form</a>
</td>
</tr>
</table>
</form>
And the send_form_email.php file:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "trevasco@gmail.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form
you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form
you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be
valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be
valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be
valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be
valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
When you fill out the info then hit submit, I don't get the sent message,
instead it opens the .php file and you can see all the code. I'm a
beginner with PHP, so is there some sort of linking the files together I
have to do?
Okay so here's the contactform.htm file:
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">First Name *</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="last_name">Last Name *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email Address *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Comments *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="25" rows="6"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit"> <a
href="http://www.freecontactform.com/email_form.php">Email Form</a>
</td>
</tr>
</table>
</form>
And the send_form_email.php file:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "trevasco@gmail.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form
you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form
you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be
valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be
valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be
valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be
valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
When you fill out the info then hit submit, I don't get the sent message,
instead it opens the .php file and you can see all the code. I'm a
beginner with PHP, so is there some sort of linking the files together I
have to do?
Display Joomla plugin fields data in template | first K2 extension
Display Joomla plugin fields data in template | first K2 extension
I have a problem and I'm really new to Joomla, so any help will be highly
appreciated.
I'm developing a simple joomla plugin based on Example K2 Plugin
(http://getk2.org/extend/extensions/90-example-k2-plugin-for-developers).
What i'm trying to create is a K2 extension for Categories, so i'll be
able to add extra content to categories. I already did a search and there
is not plugin or extension to cover my needs for this project with Joomal
3.x.
For each category I set information in the backend as currency, language,
country , etc. I added this fields to the backend via the xml file.
I have tried several ways, but I haven't been able to access this
information on my k2 template. When i dump parameters I get the default
value from the xml, but not the one already saved for the category.
So i'm being able to easily display the content with a plugin template but
by defect the only function available for categories will be
onK2CategoryDisplay, but what i'm trying to achieve here is to call the
fields values from the K2 template, next to the title for example, or
below a gallery.
I found this lines, but it only displays the default text saved on the xml
file, and not the new content. If i'm not being clear, please let me know
and i'll update this post. Thanks in advance.
$plugin = JPluginHelper::getPlugin('k2', 'categories');
$pluginParams = new JRegistry();
$pluginParams->loadString($plugin->params);
$param = $pluginParams->get('localCountry_cat');
var_dump($param);
Here is the categories.xml:
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="k2" method="upgrade">
<name>Categories K2 Plugin</name>
<files>
<filename plugin="categories">categories.php</filename>
<folder>categories</folder>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field name="localCountry_cat" type="text" size="80"
default="test" label="Country local name" description="" />
<field name="capital_cat" type="text" size="80" default="test"
label="Capital" description="" />
<field name="languages_cat" type="text" size="80"
default="test" label="Official Languages" description="" />
</fieldset>
</fields>
</config>
<!-- K2 backend field parameters -->
<fields group="category">
<field name="localCountry_cat" type="text" size="80"
default="" label="Country local name" description="" />
<field name="capital_cat" type="text" size="80" default=""
label="Capital" description="" />
<field name="languages_cat" type="text" size="80" default=""
label="Official Languages" description="" />
</fields>
Here is the categories.php
// no direct access
defined('_JEXEC') or die('Restricted access');
// Load the K2 plugin API
JLoader::register('K2Plugin',
JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'k2plugin.php');
class plgK2categories extends K2Plugin {
// Required global reference parameters
var $pluginName = 'categories';
var $pluginNameHumanReadable = 'Categories K2 Plugin';
var $plgCopyrightsStart = " "
var $plgCopyrightsEnd = " ";
function plgK2categories( & $subject, $params) {
parent::__construct($subject, $params);
}
function onK2CategoryDisplay( & $category, & $params, $limitstart) {
// API
$mainframe = JFactory::getApplication();
$document = JFactory::getDocument();
// ---------- Get plugin parameters ---------------
// Global plugin params
$plugin = JPluginHelper::getPlugin('k2', $this->pluginName);
$pluginGlobalParams = new JRegistry( $plugin->params );
// K2 Category plugin specific params
$pluginParams = new K2Parameter($category->plugins, '',
$this->pluginName);
$local = $pluginParams->get('localCountry_cat');
$capital = $pluginParams->get('capital_cat');
$languages = $pluginParams->get('languages_cat');
$currency = $pluginParams->get('currency_cat');
// --------- Requirements -------
require_once(dirname(__FILE__).DS.$this->pluginName.DS.'includes'.DS.'helper.php');
// ---------- Fetch the template -------
ob_start();
$getTemplatePath =
categoriesHelper::getTemplatePath($this->pluginName,'default.php');
$getTemplatePath = $getTemplatePath->file;
include($getTemplatePath);
$getTemplate =
$this->plgCopyrightsStart.ob_get_contents().$this->plgCopyrightsEnd;
ob_end_clean();
// ----- Output -----
return $getTemplate;
}
} // END CLASS
I have a problem and I'm really new to Joomla, so any help will be highly
appreciated.
I'm developing a simple joomla plugin based on Example K2 Plugin
(http://getk2.org/extend/extensions/90-example-k2-plugin-for-developers).
What i'm trying to create is a K2 extension for Categories, so i'll be
able to add extra content to categories. I already did a search and there
is not plugin or extension to cover my needs for this project with Joomal
3.x.
For each category I set information in the backend as currency, language,
country , etc. I added this fields to the backend via the xml file.
I have tried several ways, but I haven't been able to access this
information on my k2 template. When i dump parameters I get the default
value from the xml, but not the one already saved for the category.
So i'm being able to easily display the content with a plugin template but
by defect the only function available for categories will be
onK2CategoryDisplay, but what i'm trying to achieve here is to call the
fields values from the K2 template, next to the title for example, or
below a gallery.
I found this lines, but it only displays the default text saved on the xml
file, and not the new content. If i'm not being clear, please let me know
and i'll update this post. Thanks in advance.
$plugin = JPluginHelper::getPlugin('k2', 'categories');
$pluginParams = new JRegistry();
$pluginParams->loadString($plugin->params);
$param = $pluginParams->get('localCountry_cat');
var_dump($param);
Here is the categories.xml:
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="k2" method="upgrade">
<name>Categories K2 Plugin</name>
<files>
<filename plugin="categories">categories.php</filename>
<folder>categories</folder>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field name="localCountry_cat" type="text" size="80"
default="test" label="Country local name" description="" />
<field name="capital_cat" type="text" size="80" default="test"
label="Capital" description="" />
<field name="languages_cat" type="text" size="80"
default="test" label="Official Languages" description="" />
</fieldset>
</fields>
</config>
<!-- K2 backend field parameters -->
<fields group="category">
<field name="localCountry_cat" type="text" size="80"
default="" label="Country local name" description="" />
<field name="capital_cat" type="text" size="80" default=""
label="Capital" description="" />
<field name="languages_cat" type="text" size="80" default=""
label="Official Languages" description="" />
</fields>
Here is the categories.php
// no direct access
defined('_JEXEC') or die('Restricted access');
// Load the K2 plugin API
JLoader::register('K2Plugin',
JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'k2plugin.php');
class plgK2categories extends K2Plugin {
// Required global reference parameters
var $pluginName = 'categories';
var $pluginNameHumanReadable = 'Categories K2 Plugin';
var $plgCopyrightsStart = " "
var $plgCopyrightsEnd = " ";
function plgK2categories( & $subject, $params) {
parent::__construct($subject, $params);
}
function onK2CategoryDisplay( & $category, & $params, $limitstart) {
// API
$mainframe = JFactory::getApplication();
$document = JFactory::getDocument();
// ---------- Get plugin parameters ---------------
// Global plugin params
$plugin = JPluginHelper::getPlugin('k2', $this->pluginName);
$pluginGlobalParams = new JRegistry( $plugin->params );
// K2 Category plugin specific params
$pluginParams = new K2Parameter($category->plugins, '',
$this->pluginName);
$local = $pluginParams->get('localCountry_cat');
$capital = $pluginParams->get('capital_cat');
$languages = $pluginParams->get('languages_cat');
$currency = $pluginParams->get('currency_cat');
// --------- Requirements -------
require_once(dirname(__FILE__).DS.$this->pluginName.DS.'includes'.DS.'helper.php');
// ---------- Fetch the template -------
ob_start();
$getTemplatePath =
categoriesHelper::getTemplatePath($this->pluginName,'default.php');
$getTemplatePath = $getTemplatePath->file;
include($getTemplatePath);
$getTemplate =
$this->plgCopyrightsStart.ob_get_contents().$this->plgCopyrightsEnd;
ob_end_clean();
// ----- Output -----
return $getTemplate;
}
} // END CLASS
Assembly cmp fails for correct values when comparing (ax register)/(value) and variable
Assembly cmp fails for correct values when comparing (ax register)/(value)
and variable
When I compare two values like
cmp numSmallerEqual, 57
JLE nextStep1
or
move ax, 57
cmp numSmallerEqual, ax
JLE nextStep1
it fails to jump even if num1 is smaller than 57. However when I do it
like this it works
mov ax,9
add ax, 48
mov dx,ax
mov ah,02
cmp numSmallerEqual, ax
JLE nextStep1
It miraculously works. The strangest thing is if I remove even one line ex
instead of:
mov ax,9
add ax, 48
I only add:
mov ax, 57
It fails.
numSmallerEqual is declared and assigned a character value that was read
from the keyboard as follows:
numSmallerEqual dw 0
mov ah,01
int 21h
mov numSmallerEqual, ax
First I don't understand why the fist compare fails, and second I can't
figure out why the second compare works (other than assuming it flushes
memory that I am not aware of). What is the reason for this behaviour?
and variable
When I compare two values like
cmp numSmallerEqual, 57
JLE nextStep1
or
move ax, 57
cmp numSmallerEqual, ax
JLE nextStep1
it fails to jump even if num1 is smaller than 57. However when I do it
like this it works
mov ax,9
add ax, 48
mov dx,ax
mov ah,02
cmp numSmallerEqual, ax
JLE nextStep1
It miraculously works. The strangest thing is if I remove even one line ex
instead of:
mov ax,9
add ax, 48
I only add:
mov ax, 57
It fails.
numSmallerEqual is declared and assigned a character value that was read
from the keyboard as follows:
numSmallerEqual dw 0
mov ah,01
int 21h
mov numSmallerEqual, ax
First I don't understand why the fist compare fails, and second I can't
figure out why the second compare works (other than assuming it flushes
memory that I am not aware of). What is the reason for this behaviour?
Subscribe to:
Posts (Atom)