redirect(
$this
->uri->uri_string());
redirect(
$this
->uri->uri_string());
$cookie
=
array
(
'name'
=>
'loggedin'
,
'value'
=>
'yes'
,
'expire'
=>
'86500'
,
'domain'
=>
'.apol0829.dev'
,
'prefix'
=>
'apollidon_'
);
set_cookie(
$cookie
);
$cookie
=
array
(
'name'
=>
'loggedin'
,
'value'
=>
''
,
'expire'
=>
'0'
,
'domain'
=>
'.apol0829.dev'
,
'prefix'
=>
'apollidon_'
);
delete_cookie(
$cookie
);
The database.php config file
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "123456";
$db['default']['database'] = "database_1";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['second_db']['hostname'] = "localhost";
$db['second_db']['username'] = "root";
$db['second_db']['password'] = "abcdef";
$db['second_db']['database'] = "database_2";
$db['second_db']['dbdriver'] = "mysql";
$db['second_db']['dbprefix'] = "my_";
$db['second_db']['pconnect'] = TRUE;
$db['second_db']['db_debug'] = TRUE;
$db['second_db']['cache_on'] = FALSE;
$db['second_db']['cachedir'] = "";
$db['second_db']['char_set'] = "utf8";
$db['second_db']['dbcollat'] = "utf8_general_ci";
// load second database
$this->legacy_db = $this->load->database(database_2, true);
// fetch result from my_table
$this->legacy_db->select ('*');
$this->legacy_db->from ('my_table');
$query = $this->legacy_db->get();
$result = $query->result ();
// Load authorize_net library
$this->load->library('authorize_net');
// Invoke Authorize.net service
$this->authorize_net->set_params($_POST);
$this->authorize_net->set_login('$login_id', '$tran_key');
$this->authorize_net->process(true);
$response = $this->authorize_net->response();
<?phpclass CI_Xml_Handle{
var $xml='';
function CI_Xml_Handle($xml_content)
{
$this->xml=$xml_content;
}
function XMLtoObject () {
try {
$xml_object = new SimpleXMLElement($this->xml);
if ($xml_object == false) {
return false;
}
}
catch (Exception $e) {
return false;
}
return $xml_object;
}
}
$(
function
() {
$(
'.star-radio'
).rating({
required: true,
callback:
function
(value, link) {
$.ajax({
type:
"post"
,
url: site_url +
"user/rate"
,
dataType:
"json"
,
data:
"&post_url="
+ $(
'#post_url'
).val() +
"&rate_val="
+ value,
success:
function
(e) {
$.jGrowl(e.code +
"<br>"
+ e.msg);
}
});
}
});
<?php
// .. some User controller code up here
// Rate function on User Controller
public
function
rate()
{
// Turn of layout for Ajax request
unset(
$this
->layout);
// Gather ajax post data
$rate
=
$this
->input->post(
"rate_val"
, true);
$post_url
=
$this
->input->post(
"post_url"
, true);
// Load model data
$this
->load->model(
'Post'
);
$post_id
=
$this
->Post->get_post_id(
$post_url
);
// Call function to check if user is login
// return current login user id, null if not login yet
// You need to define this helper function your self
if
(get_user_id()) {
// Call the Post Model is_rated method to check whether the current login user has submit a rate to related post
if
(!
$this
->Post->is_rated(get_user_id(),
$post_id
))
{
$data
=
array
(
"post_id"
=>
$post_id
,
"user_id"
=> get_user_id(),
"posts_rating_value"
=>
$rate
,
"posts_rating_date"
=>
date
(
"Y-m-d H:i:s"
)
);
// Call Post model method to insert rating data
if
(
$this
->Post->insert_rating(
$data
,
$post_id
,
$rate
)) {
echo
json_encode(
array
(
"code"
=>
"Success"
,
"msg"
=>
"Thank you, rate has been submitted"
));
}
else
{
echo
json_encode(
array
(
"code"
=>
"Error"
,
"msg"
=>
"Sorry, something wrong. Please try again."
));
}
}
// If post has been rated by the current login user
else
{
echo
json_encode(
array
(
"code"
=>
"Error"
,
"msg"
=>
"You have already rated this post"
));
}
}
// User is not login yet, ask them to login first
else
{
echo
json_encode(
array
(
"code"
=>
"Error"
,
"msg"
=>
"Please login to submit this rate"
));
}
// Do not proceed to view, just terminate to send Json response
exit
;
}
// .. any other User controller code goes here
?>
<?php
//Check if user logged in
if
(!get_user_id()) {
$radioIsActive
=
"disabled=disabled "
;
}
else
{
$radioIsActive
=
" "
;
}
?>
<?php
for
(
$i
= 1;
$i
<= 5;
$i
++) :
if
(
$i
==
round
(
$row
[
"average"
])) :
?>
<input
class
=
"star-radio"
type=
"radio"
name=
"rating"
value=
"<?php echo $i; ?>"
checked=
"checked"
<?php
echo
"$radioIsActive"
; ?>/>
<?php
else
: ?>
<input
class
=
"star-radio"
type=
"radio"
name=
"rating"
value=
"<?php echo $i; ?>"
<?php
echo
"$radioIsActive"
; ?>/>
<?php
endif
;
endfor
;
?>
CREATE TABLE `db_name`.`blog` (
`blog_id` BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 200 ) NOT NULL ,
`desc` TEXT NOT NULL ,
`created` DATETIME NOT NULL ,
`modified` DATETIME NOT NULL
) ENGINE = MYISAM
<?php
class
blog
extends
Model
{
function
blog()
{
parent::Model();
$this
->load->database();
}
function
count_blogs()
{
// Count total numbers of blog entries
$query
=
$this
->db->query(
'SELECT count(*) as count_blog FROM blogs'
);
$result
=
$query
->results();
return
$result
[0]->count_blog;
}
function
select_blogs(
$num
,
$offset
)
{
// Fetch data from blogs table
$query
=
$this
->db->get(
'blogs'
,
$num
,
$offset
);
$result
=
$query
->results();
return
$result
;
}
}
?>
<?php
class
blog
extends
Controller
{
function
blog() {
parent::Controller();
$this
->load->library(‘pagination’);
$this
->load->model(‘blog’);
$this
->load->helper(‘url’);
}
function
bloglist() {
$config
[
'base_url'
] = ‘http:
//your-site.com/index.php/test/page/’;
$config
[
'per_page'
]=10;
$config
[
'total_rows'
] =
$data
[
'count_blog'
];
$this
->pagination->initialize(
$config
);
$data
[
'title'
]=’CodeIgniter Pagination Example’;
$data
[
'bloglist'
] =
$this
->blog->select_blogs(
$config
[
'per_page'
],
$this
->uri->segment(3));
$data
[
'count_blog'
]=
$this
->blog->count_blogs();
// This will generate your pagination links
$data
[
'page_links'
]=
$this
->pagination->create_links();
$this
->load->view(‘blog/index’,
$data
);
}
}
?>
<table>
<?php
for
(
$i
=0;
$i
<
count
(
$bloglist
);
$i
++) : ?>
<tr>
<td><?php
echo
$bloglist
[
$i
]->title; ?></td>
</tr>
<tr>
<td><?php
echo
$bloglist
[
$i
]->desc; ?></td>
</tr>
<?php
echo
endfor
; ?>
<tr>
<td><?php
echo
$page_links
; ?></td>
</tr>
</table>