Welcome Guest, Not a member yet? Register   Sign In
Fix an anchor issue
#1

Hello all!

I uploaded code from git into my site but having an issue anchoring the controller to view. This is my anchor:
<?= anchor('chat/index','Chat');?>


This is the controller/function that Im trying to connect:

class Chat extends Controller {

    function Chat() {
        parent::Controller();
        $this->load->database('cultured_codeignite');
        $this->load->model('mod_chat');
        $this->load->library(array('session', 'authentication'));

    }

    function index() {
        //outsiders keep out
        $this->authentication->sentry();
        $ctr = 0;
        //get all chat messages from buddy
        $username = $this->session->userdata('username');
        $recipient = $this->session->userdata('recipient');
        $fetchchat = $this->mod_chat->fetchchat($username, $recipient);
        $chatreverse = '';
        //reverse results of chat, bottom message is latest
        foreach ($fetchchat as $chatorig) {
            $chatreverse[$ctr]['username'] = $chatorig->username;
            $chatreverse[$ctr]['message'] = $chatorig->message;
            $time = explode(' ', $chatorig->time);
            $reformat_time = date("g:i a", strtotime($time[1]));
            $chatreverse[$ctr]['time'] = $reformat_time;
            ++$ctr;
        }
        $data['chat'] = '';
        $data['buddy'] = $this->session->userdata('recipient');
        $buddyimage = $this->mod_chat->get_buddy_image($this->session->userdata('recipient'));
        $data['buddyimage'] = $buddyimage[0]->image;
        //throw messages to view
        if (is_array($chatreverse)) {
            $users['username'] = $username;
            $users['recipient'] = $recipient;
            $this->mod_chat->message_read($users);
            $data['chat'] = array_reverse($chatreverse);
        }
        $this->load->view('view_chat', $data);
    }


The viewer is view_chat that Im trying to connect to. How do I get this to work?

Heart Heart ,
Mekaboo
Reply
#2

@Mekaboo,

What errors are you seeing? Also, what does <?= anchor('chat/index','Chat');?> put out?
Reply
#3

Your constructor is using the old style.

PHP Code:
// change this
function Chat()
{
 
   parent::Controller();
 
   
    $this
->load->database('cultured_codeignite');
 
   $this->load->model('mod_chat');
 
   $this->load->library(array('session''authentication'));
}

// to this
function __construct()
{
 
   parent::__construct);
 
   
    $this
->load->database('cultured_codeignite');
 
   $this->load->model('mod_chat');
 
   $this->load->library(array('session''authentication'));


Try that and see if it works.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(06-24-2019, 10:10 PM)php_rocs Wrote: @Mekaboo,

What errors are you seeing? Also, what does <?= anchor('chat/index','Chat');?> put out?

Hey! I get a 404 error saying that the page is not found. Basic error..the page isnt loading at all. Im trying to figure out if its because of the function.
Reply
#5

(06-25-2019, 03:46 AM)InsiteFX Wrote: Your constructor is using the old style.

PHP Code:
// change this
function Chat()
{
 
   parent::Controller();
 
   
    $this
->load->database('cultured_codeignite');
 
   $this->load->model('mod_chat');
 
   $this->load->library(array('session''authentication'));
}

// to this
function __construct()
{
 
   parent::__construct);
 
   
    $this
->load->database('cultured_codeignite');
 
   $this->load->model('mod_chat');
 
   $this->load->library(array('session''authentication'));


Try that and see if it works.
Unfortunately it didnt help, Im still getting a 404 page dont exist code. Trying to figure out how to fix the function.
Reply
#6

@Mekaboo,

I need to see what anchor value is being displayed on the page. Is it something like... https://yoursite.com/index.php/chat/index

If so, then try removing the index and see if that works. Like this <?= anchor('chat','Chat');?>

Also, I noticed that you didn't load the url helper ( https://www.codeigniter.com/user_guide/h...elper.html )
Reply
#7

(This post was last modified: 06-25-2019, 10:49 PM by Wouter60.)

Is your controller Chat.php ? With a capital C ?
If that's the case, what's the url that shows up in your browser after you clicked the "anchor"?
Reply
#8

Thank ya all! I tried various ways to correct things from copy/paste from one controller to another as well as doing the same process for the models. Parts worked but not all. I looked up alternatives and found this one:

https://www.sourcecodester.com/php/6318/...mysql.html

Had the "Undefined Variable error but this time I seem to fix on my own (WooHoo)..now its time to test.

Thank you all for the help,it means alot Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB