Can anybody help me figuring out this cause I don't know where's the problem.
I've tried many times and even search for lots of tutorials still couldn't work at all. Please help me to solve my problems thanks alot.
This is my controllers saved as Home.php
<?php
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('HomeModel');
// Your own constructor code
}
}
function index(){
$query = $this->HomeModel->getEmployees();
$data['EMPLOYEES'] = null;
if($query){
$data['EMPLOYEES'] = $query;
}
$this->load->view('index.php', $data);
}
?>
This is model saved as HomeModel.php
<?php
class HomeModel extends Model {
function HomeModel(){
parent::Model();
}
function getEmployees(){
$this->db->select("jantina,bangsa,agama");
$this->db->from('pesakit');
$query = $this->db->get();
return $query->result();
}
}
?>
This is views saved as index.php
<?php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Display Records From Database Using Codeigniter</title>
<link href="<?= base_url();?>css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div class="row">
<div style="width:500px;margin:50px;">
<h4>Display Records From Database Using Codeigniter</h4>
<table class="table table-striped table-bordered">
<tr><td><strong>Jantina</strong></td><td><strong>Bangsa</strong></td><td><strong>Agama</strong></td></tr>
<?php foreach($EMPLOYEES as $employee){?>
<tr><td><?=$employee->jantina;?></td><td><?=$employee->bangsa;?></td><td><?=$employee->agam;?></td></tr>
<?php }?>
</table>
</div>
</div>
</body>
</html>
config.php
$config['base_url'] = 'http://localhost/project/';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
routes.php
$route['default_controller'] = 'home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
database.php
$active_group = 'main';
$active_record = TRUE;
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => '',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
$db['main']['hostname']='xx.x.xxx.xx';
$db['main']['username']='this server's username';
$db['main']['password'] ='this server's password';
$db['main']['database'] = 'database name';
$db['main']['dbdriver'] = 'mysql';
$db['main']['dbprefix'] = '';
$db['main']['pconnect'] = TRUE;
$db['main']['db_debug'] = TRUE;
$db['main']['cache_on'] = FALSE;
$db['main']['cachedir'] = '';
$db['main']['char_set'] = 'utf8';
$db['main']['dbcollat'] = 'utf8_general_ci';
$db['main']['swap_pre'] = '';
$db['main']['autoinit'] = TRUE;
$db['main']['stricton'] = FALSE;
);
Help me please, I'm totally a newbie for CI. Thanks alot.
Unless this is a typo in the controller, you have an extra closing brace above the index() function.
<?php
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('HomeModel');
// Your own constructor code
}
} <--- THIS IS CLOSING YOUR CONTROLLER CLASS.
function index(){
$query = $this->HomeModel->getEmployees();
$data['EMPLOYEES'] = null;
if($query){
$data['EMPLOYEES'] = $query;
}
$this->load->view('index.php', $data);
}
} <--- IT NEEDS TO BE DOWN HERE.
?>
There's a lot wrong here. Let's start with your Home controller.
Don't put a ?> at the end of your files.
Move your index function into the Home controller class as a method.
I simplified the code a little, if the getEmployees() method returns null anyway on failure.
I'd use the compact($employees) function here. It's the same as writing ['employees' => $employees].
Be consistent with naming, don't use all caps. Save all caps for global constants.
You don't need the .php in the $this->load->view() first parameter.
...
<?php
class Home extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('HomeModel');
}
public function index()
{
$employees = $this->HomeModel->getEmployees();
$this->load->view('index', compact('employees'));
}
}
A lot of the same for the Home Model.
<?php
class HomeModel extends CI_Model
{
public function getEmployees()
{
$this->db->select('jantina, bangsa, agama');
$this->db->from('pesakit');
return $this->db->get()->result();
}
}
For the index.php page.
Remove the <?php opening tag from the first line of your file.
I wouldn't recommend using short tags like <?=.
In view files, its better to be explicit with your foreach, if, while, etc blocks by using foreach (...) : endforeach;
...
<!DOCTYPE html>
<html lang="en">
<head>
<title>Display Records From Database Using Codeigniter</title>
<link href="<?php echo base_url();?>css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div class="row">
<div style="width:500px;margin:50px;">
<h4>Display Records From Database Using Codeigniter</h4>
<table class="table table-striped table-bordered">
<tr><td><strong>Jantina</strong></td><td><strong>Bangsa</strong></td><td><strong>Agama</strong></td></tr>
<?php foreach ($employees as $employee) : ?>
<tr><td><?php echo $employee->jantina; ?></td><td><?php echo $employee->bangsa; ?></td><td><?php echo $employee->agam; ?></td></tr>
<?php endforeach; ?>
</table>
</div>
</div>
</body>
</html>
I think config.php and routes.php look fine.
You've got a syntax error in your database.php array formatting. I'd just keep it in the same format as it was originally.
<?php
$active_group = 'main';
$active_record = true;
$query_builder = true;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = false;
$db['default']['db_debug'] = ENVIRONMENT !== 'production';
$db['default']['cache_on'] = false;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = true;
$db['default']['stricton'] = false;
$db['main']['hostname'] = 'xx.x.xxx.xx';
$db['main']['username'] = 'this server\'s username';
$db['main']['password'] = 'this server\'s password';
$db['main']['database'] = 'database name';
$db['main']['dbdriver'] = 'mysqli';
$db['main']['dbprefix'] = '';
$db['main']['pconnect'] = true;
$db['main']['db_debug'] = true;
$db['main']['cache_on'] = false;
$db['main']['cachedir'] = '';
$db['main']['char_set'] = 'utf8';
$db['main']['dbcollat'] = 'utf8_general_ci';
$db['main']['swap_pre'] = '';
$db['main']['autoinit'] = true;
$db['main']['stricton'] = false;
As a side note, read up on PSR-1 and PSR-2 coding standards. Also, please take a look at PHP The Right Way.
REplace(If index is your view page name)
$this->load->view('index.php', $data);
To
$this->load->view('index', $data);
Related
I am working on a basic blog application with Codeigniter 3.1.8 and Bootstrap 4.
The single post URL is made from the post's title with url_title($this->input->post('title'), 'dash', TRUE). The entire post crearing function is this:
public function create() {
// Only logged in users can create posts
if (!$this->session->userdata('is_logged_in')) {
redirect('login');
}
$data = $this->get_data();
$data['tagline'] = "Add New Post";
if ($data['categories']) {
foreach ($data['categories'] as &$category) {
$category->posts_count = $this->Posts_model->count_posts_in_category($category->id);
}
}
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('desc', 'Short description', 'required');
$this->form_validation->set_rules('body', 'Body', 'required');
$this->form_validation->set_error_delimiters('<p class="error-message">', '</p>');
if($this->form_validation->run() === FALSE){
$this->load->view('partials/header', $data);
$this->load->view('dashboard/create-post');
$this->load->view('partials/footer');
} else {
// Create slug (from title)
$slug = url_title($this->input->post('title'), 'dash', TRUE);
$slugcount = $this->Posts_model->slug_count($slug, null);
if ($slugcount > 0) {
$slug = $slug."-".$slugcount;
}
// Upload image
$config['upload_path'] = './assets/img/posts';
$config['allowed_types'] = 'jpg|jpeg|png';
$config['max_size'] = '2048';
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
$errors = array('error' => $this->upload->display_errors());
$post_image = 'default.jpg';
} else {
$data = array('upload_data' => $this->upload->data());
$post_image = $_FILES['userfile']['name'];
}
$this->Posts_model->create_post($post_image, $slug);
$this->session->set_flashdata('post_created', 'Your post has been created');
redirect('/');
}
}
I was convinced it worked fine, until I added a post that had diacritics in its title. "La mulți ani România!" results in the slug la-mul??i-ani-rom??nia instead of la-multi-ani-romania.
I tried to fix thos issues with Codeigniter's convert_accented_characters():
$slug = convert_accented_characters(url_title($this->input->post('title'), 'dash', TRUE));
It does not work even thou I did load the test helper:
$autoload['helper'] = array('url', 'form', 'date', 'text');
What other options do I have? How can I fix this problem?
The order in which I used the url_title() and convert_accented_characters() was wrong.
This is the correct one:
$slug = url_title(convert_accented_characters($this->input->post('title')), 'dash', TRUE);
It works fine now.
I have worked on a hook for validate my translated fields, based on this thread : https://stackoverflow.com/a/33070156/4617689. That i've done do the trick, but i'm looking for you guys to help me to improve my code, so feel free to comment and modify
class ContentbuildersTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Tree');
$this->addBehavior('Timestamp');
$this->addBehavior('Translate', [
'fields' => [
'slug'
]
]);
}
public function validationDefault(Validator $validator)
{
$data = null; // Contain our first $context validator
$validator
->requirePresence('label')
->notEmpty('label', null, function($context) use (&$data) {
$data = $context; // Update the $data with current $context
return true;
})
->requirePresence('type_id')
->notEmpty('type_id')
->requirePresence('is_activated')
->notEmpty('is_activated');
$translationValidator = new Validator();
$translationValidator
->requirePresence('slug')
->notEmpty('slug', null, function($context) use (&$data) {
if (isset($data['data']['type_id']) && !empty($data['data']['type_id'])) {
if ($data['data']['type_id'] != Type::TYPE_HOMEPAGE) {
return true;
}
return false;
}
return true;
});
$validator
->addNestedMany('translations', $translationValidator);
return $validator;
}
}
I'm not proud of my trick with the $data, but i've not found a method to get the data of the validator into my nestedValidator...
Important part here is to note that i only rule of my nestedValidator on 'translations', this is very important !
class Contentbuilder extends Entity
{
use TranslateTrait;
}
Here basic for I18ns to work
class BetterFormHelper extends Helper\FormHelper
{
public function input($fieldName, array $options = [])
{
$context = $this->_getContext();
$explodedFieldName = explode('.', $fieldName);
$errors = $context->entity()->errors($explodedFieldName[0]);
if (is_array($errors) && !empty($errors) && empty($this->error($fieldName))) {
if (isset($errors[$explodedFieldName[1]][$explodedFieldName[2]])) {
$error = array_values($errors[$explodedFieldName[1]][$explodedFieldName[2]])[0];
$options['templates']['inputContainer'] = '<div class="input {{type}} required error">{{content}} <div class="error-message">' . $error . '</div></div>';
}
}
return parent::input($fieldName, $options);
}
}
With that formHelper we gonna get the errors of nestedValidation and inject them into the input, i'm not confortable with the templates, so that's why it's very ugly.
<?= $this->Form->create($entity, ['novalidate', 'data-load-in' => '#right-container']) ?>
<div class="tabs">
<?= $this->Form->input('label') ?>
<?= $this->Form->input('type_id', ['empty' => '---']) ?>
<?= $this->Form->input('is_activated', ['required' => true]) ?>
<?= $this->Form->input('translations.fr_FR.slug') ?>
<?= $this->Form->input('_translations.en_US.slug') ?>
</div>
<?php
echo $this->Form->submit(__("Save"));
echo $this->Form->end();
?>
Here my fr_FR.slug is required when type_id is not set to Type::TYPE_HOMEPAGE, yeah my homepage has not slug, note that the en_US.slug is not required at all, because i only required 'translations.xx_XX.xxxx' and not '_translations.xx_XX.xxxx'.
And the last part of the code, the controller
$entity = $this->Contentbuilders->patchEntity($entity, $this->request->data);
// We get the locales
$I18ns = TableRegistry::get('I18ns');
$langs = $I18ns->find('list', [
'keyField' => 'id',
'valueField' => 'locale'
])->toArray();
// Merging translations
if (isset($entity->translations)) {
$entity->_translations = array_merge($entity->_translations, $entity->translations);
unset($entity->translations);
}
foreach ($entity->_translations as $lang => $data) {
if (in_array($lang, $langs)) {
$entity->translation($lang)->set($data, ['guard' => false]);
}
}
Here a .gif of the final result om my side : http://i.giphy.com/3o85xyrLOTd7q0YVck.gif
On my Welcome controller I have a function called content_top which loads function $this->$part[0]($setting_info); in this case $this->slideshow($setting_info); Then it should display that slideshow functions view in that data array.
When I have refreshed my page I get a error
A PHP Error was encountered
Severity: 4096
Message: Object of class CI_Loader could not be converted to string
Filename: common/content_top.php
Line Number: 7
Backtrace:
File: C:\wamp\www\cms\application\views\common\content_top.php
Line: 7
Function: _error_handler
File: C:\wamp\www\cms\application\controllers\Welcome.php
Line: 51
Function: view
File: C:\wamp\www\cms\application\controllers\Welcome.php
Line: 19
Function: content_top
File: C:\wamp\www\cms\index.php
Line: 292
Function: require_once
And
A PHP Error was encountered
Severity: 4096
Message: Object of class CI_Loader could not be converted to string
Filename: common/welcome_message.php
Line Number: 3
Backtrace:
File: C:\wamp\www\cms\application\views\common\welcome_message.php
Line: 3
Function: _error_handler
File: C:\wamp\www\cms\application\controllers\Welcome.php
Line: 20
Function: view
File: C:\wamp\www\cms\index.php
Line: 292
Function: require_once
Question Is there any way to when I have a function in array to be able to make it display the view with out throwing error.
<?php
class Welcome extends CI_Controller {
public $data = array();
public function __construct() {
parent::__construct();
$this->load->model('design/model_layout');
$this->load->model('extension/model_module');
$this->load->model('design/model_banner');
$this->load->model('tool/model_image');
$this->load->library('image_lib');
}
public function index() {
$this->load->view('common/header');
$data['content_top'] = $this->content_top();
$this->load->view('common/welcome_message', $data);
$this->load->view('common/footer');
}
public function content_top() {
if ($this->uri->segment(1)) {
$route = $this->uri->segment(1) .'/'. $this->uri->segment(2);
} else {
$route = 'common/home';
}
$layout_id = $this->model_layout->get_layout($route);
$data['modules'] = array();
$modules = $this->model_layout->get_layout_modules($layout_id, 'content_top');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
if (isset($part[1])) {
$setting_info = $this->model_module->get_module($part[1]);
if ($setting_info) {
$data['modules'][] = $this->$part[0]($setting_info);
}
}
}
return $this->load->view('common/content_top', $data);
}
public function slideshow($setting_info) {
static $module = 0;
$data['banners'] = array();
$results = $this->model_banner->get_banner($setting_info['banner_id']);
foreach ($results as $result) {
$data['banners'][] = array(
'banner_image' => $this->model_image->resize($result['banner_image'], $setting_info['width'], $setting_info['height'])
);
}
$data['module'] = $module++;
$data['resize_errors'] = $this->image_lib->display_errors();
return $this->load->view('module/slideshow', $data);
}
}
In the CI when you loading the view and printing as a string then need to pass the third parameter as 'TRUE'.
<?php echo $this->load->view('headers/menu', '', TRUE);?>
Solved
On the controller I had to change a couple things around
I also have had to use a template layout to minimize the views
But on content_top and sideshow function I had to use return and true
return $this->load->view('folder/name', $this->data, TRUE);
Controller
<?php
class Home extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('design/model_layout');
$this->load->model('extension/model_module');
$this->load->model('design/model_banner');
$this->load->model('tool/model_image');
$this->load->library('image_lib');
}
public function index() {
$this->data['title'] = 'Home';
$this->data = array(
'column_left' => $this->column_left(),
'column_right' => $this->column_right(),
'content_bottom' => $this->content_bottom(),
'content_top' => $this->content_top(),
'page' => 'common/home'
);
$this->load->view('common/template', $this->data);
}
public function column_left() {
$route = 'common/home';
$layout_id = $this->model_layout->get_layout($route);
$this->data['modules'] = array();
$modules = $this->model_layout->get_layout_modules($layout_id, 'column_left');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
$setting_info = $this->model_module->get_module($part[1]);
$this->data['modules'][] = array (
'module_name' => $this->$part[0]($setting_info)
);
}
return $this->load->view('common/column_left', $this->data, TRUE);
}
public function column_right() {
$route = 'common/home';
$layout_id = $this->model_layout->get_layout($route);
$this->data['modules'] = array();
$modules = $this->model_layout->get_layout_modules($layout_id, 'column_right');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
$setting_info = $this->model_module->get_module($part[1]);
$this->data['modules'][] = array (
'module_name' => $this->$part[0]($setting_info)
);
}
return $this->load->view('common/column_right', $this->data, TRUE);
}
public function content_bottom() {
$route = 'common/home';
$layout_id = $this->model_layout->get_layout($route);
$this->data['modules'] = array();
$modules = $this->model_layout->get_layout_modules($layout_id, 'content_bottom');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
$setting_info = $this->model_module->get_module($part[1]);
$this->data['modules'][] = array (
'module_name' => $this->$part[0]($setting_info)
);
}
return $this->load->view('common/content_bottom', $this->data, TRUE);
}
public function content_top() {
$route = 'common/home';
$layout_id = $this->model_layout->get_layout($route);
$this->data['modules'] = array();
$modules = $this->model_layout->get_layout_modules($layout_id, 'content_top');
foreach ($modules as $module) {
$part = explode('.', $module['code']);
$setting_info = $this->model_module->get_module($part[1]);
$this->data['modules'][] = array (
'module_name' => $this->$part[0]($setting_info)
);
}
return $this->load->view('common/content_top', $this->data, TRUE);
}
/*
Add function for modules that are enabled for this page
*/
public function slideshow($setting_info) {
static $module = 0;
$this->data['banners'] = array();
$results = $this->model_banner->get_banner($setting_info['banner_id']);
foreach ($results as $result) {
$this->data['banners'][] = array(
'banner_image' => $this->model_image->resize($result['banner_image'], $setting_info['width'], $setting_info['height'])
);
}
$this->data['module'] = $module++;
return $this->load->view('module/slideshow', $this->data, TRUE);
}
}
Template View
<?php $this->load->view('common/header');?>
<?php $this->load->view($page);?>
<?php $this->load->view('common/footer');?>
Content Top View
<?php foreach ($modules as $module) {?>
<?php echo $module['module_name'];?>
<?php }?>
Home View
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?php echo $content_top;?>
</div>
</div>
</div>
Proof Working
This happened to me when I did this:
$model = $this->load->model('user_model);
$data = [
'model' => $model
];
instead of this:
$this->load->model('user_model);
$model = $this->user_model->edit();
$data = [
'model' => $model
];
then when I echoed out the $model, it gave me the error. So I tried to print_r then it gave me a very long array until I realize my mistake. Hope it helps.
Just remove the echo on view page when you are using CI new versions.
<?php $this->load->view('headers/menu');?>
https://stackoverflow.com/a/40675633/2790502
I am using Facebook PHP SDK with Codeigniter to do login and registration using Facebook. For this I am using This tutorial
my controller 'facebooktest.php' code is:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Facebooktest extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('input');
$this->load->library('session');
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('security');
}
function Facebooktest() {
parent::Controller();
$cookies = $this->load->model('facebook_model');
}
function index() {
$this->load->view('facebooktest/test2');
}
function test1() {
$data = array();
$data['user'] = $this->facebook_model->get_facebook_cookie();
$this->load->view('facebooktest/test1', $data);
}
function test2() {
$data['friends'] = $this->facebook_model->get_facebook_cookie();
$this->load->view('facebooktest/test2', $data);
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
?>
view 'test2.php' has code as:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Kent is Learning CodeIgniter - Test 2</title>
</head>
<body>
<fb:login-button autologoutlink="true"
onlogin="window.location.reload(true);"></fb:login-button>
<div style="width:600px;">
<?
if(isset($friends)){
foreach($friends as $friend){
?>
<img src="http://graph.facebook.com/<?=$friend['id'];?>/picture" title="<?=$friend['name'];?>" />
<?
}
}
?>
</div>
<p><?=anchor('facebook_connect/page4','Go back to page 4 of the tutorial');?></p>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '457228377680583', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
// A user has logged in, and a new cookie has been saved
window.location.reload(true);
} else {
// The user has logged out, and the cookie has been cleared
}
});
</script>
</body>
</html>
And model 'facebook_model.php' has code:
<?php
class Facebook_model extends CI_Model {
function __construct() {
parent::__construct();
}
function get_facebook_cookie() {
$app_id = '457228377680583';
$application_secret = '01f660b73bc085f0b78cd22322556495';
if (isset($_COOKIE['fbs_' . $app_id])) {
echo "dfgdsf";exit;
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
} else {
return null;
}
}
function getUser() {
$cookie = $this->get_facebook_cookie();
$user = #json_decode(file_get_contents(
'https://graph.facebook.com/me?access_token=' .
$cookie['access_token']), true);
return $user;
}
function getFriendIds($include_self = TRUE) {
$cookie = $this->get_facebook_cookie();
$friends = #json_decode(file_get_contents(
'https://graph.facebook.com/me/friends?access_token=' .
$cookie['access_token']), true);
$friend_ids = array();
foreach ($friends['data'] as $friend) {
$friend_ids[] = $friend['id'];
}
if ($include_self == TRUE) {
$friend_ids[] = $cookie['uid'];
}
return $friend_ids;
}
function getFriends($include_self = TRUE) {
$cookie = $this->get_facebook_cookie();
print_r($cookie);
$friends = #json_decode(file_get_contents(
'https://graph.facebook.com/me/friends?access_token=' .
$cookie['access_token']), true);
if ($include_self == TRUE) {
$friends['data'][] = array(
'name' => 'You',
'id' => $cookie['uid']
);
}
return $friends['data'];
}
function getFriendArray($include_self = TRUE) {
$cookie = $this->get_facebook_cookie();
$friendlist = #json_decode(file_get_contents(
'https://graph.facebook.com/me/friends?access_token=' .
$cookie['access_token']), true);
$friends = array();
foreach ($friendlist['data'] as $friend) {
$friends[$friend['id']] = array(
'name' => $friend['name'],
'picture' => 'http://graph.facebook.com/'.$friend['id'].'/picture'
);
}
if ($include_self == TRUE) {
$friends[$cookie['uid']] = 'You';
}
return $friends;
}
}
?>
The problem is that, in model, it is coming inside 'getFriends()'. From there it is going inside 'get_facebook_cookie()'. But it is not going inside if(isset($_COOKIE['fbs_' . $app_id])))
and hence, it is nor displaying data that I want.
So, if possible, please let me know whats wrong with my code.
Thanks in advance....
using This Template Library
When I try and use the add_js() function it errors out. I add the regions $_scripts to the template header file but when I load the page it says undefined variable _scripts.
any thoughts?
changed <?= $_scripts ?> to <?= (isset($_scripts)) ? $_scripts : “”; ?>
and obviously I lose the error but the js file still isn't loading.
I did an echo at each step though the add_js() method and the output is correct. I also did an output of $this->js and they both had the correct output. So it gets through the get_js method fine and sets the class variable fine but I don't get anything added to the actual page.
sorry different computer now.
here is the controller method:
function registrationForm(){
$this->template->set_template('single');
$this->template->write_view('header', 'templates/header_template');
$this->template->write_view('footer', 'templates/footer_template');
$this->template->write_view('center', 'user/registration_form');
$this->template->add_js('js/jquery.min.js');
$this->template->add_js('js/validate.jquery.js');
$this->template->render();
}
here is the head section:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<?= base_url() ?>css/style.css" type="text/css" rel="stylesheet" />
<?= (isset($_scripts)) ? $_scripts : ""; ?>
<?= (isset($_styles)) ? $_styles : ""; ?>
</head>
and the add_js() method:
function add_js($script, $type = 'import', $defer = FALSE)
{
$success = TRUE;
$js = NULL;
$this->CI->load->helper('url');
switch ($type)
{
case 'import':
$filepath = base_url() . $script;
$js = '<script type="text/javascript" src="'. $filepath .'"';
if ($defer)
{
$js .= ' defer="defer"';
}
$js .= "></script>";
break;
case 'embed':
$js = '<script type="text/javascript"';
if ($defer)
{
$js .= ' defer="defer"';
}
$js .= ">";
$js .= $script;
$js .= '</script>';
break;
default:
$success = FALSE;
break;
}
// Add to js array if it doesn't already exist
if ($js != NULL && !in_array($js, $this->js))
{
$this->js[] = $js;
$this->write('_scripts', $js);
}
return $success;
}
template.php config file
/*
|--------------------------------------------------------------------------
| Default Template Configuration (adjust this or create your own)
|--------------------------------------------------------------------------
*/
$template['default']['template'] = 'templates/default_template';
$template['default']['regions'] = array(
'header',
'left',
'right',
'footer',
);
$template['default']['parser'] = 'parser';
$template['default']['parser_method'] = 'parse';
$template['default']['parse_template'] = FALSE;
/*
|--------------------------------------------------------------------------
| Default Template Configuration (adjust this or create your own)
|--------------------------------------------------------------------------
*/
$template['single']['template'] = 'templates/single_template';
$template['single']['regions'] = array(
'header',
'center',
'footer',
);
$template['single']['parser'] = 'parser';
$template['single']['parser_method'] = 'parse';
$template['single']['parse_template'] = FALSE;
/* End of file template.php */
/* Location: ./system/application/config/template.php */